Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/product-technical-gap-baseline.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
## 3. General Architecture Gaps
- **DB Architecture**: Ensure PostgreSQL is strictly used (no file DBs), 3rd normal form is maintained, and Hot Partitions are handled. DB locks must be managed (or use read/write replicas).
- **Zotero Integration**: Papers and standards referenced by TEPP must be synced via Local Zotero API (http://localhost:23119/api/) and cited using APA 7th edition in docstrings.
- **Testing**: We need actual testing of Psychometrics (Fast-MLSIRM parameter calibration, RMSE of estimates, Fixed-Item Parameter Calibration, CAT) against synthetic/demo data.
- **Testing**: Partially resolved -- CAT recovery is now real and tested via `tests/test_fast_mlsirm_cat_recovery.py`, which simulates responses from known true item parameters and person thetas and verifies the actual adaptive-testing value proposition via `fast_mlsirm.cat_simulate_polytomous` (Dodd, De Ayala & Koch, 1995): a mean of ~8.7 of 40 items reaches accuracy (RMSE ~0.40, correlation ~0.91) -- not just "it runs," but "it recovers theta using substantially fewer items than the full bank," the property that actually distinguishes CAT from full-bank testing. GRM (Samejima 1969) and GPCM (Muraki 1993) parameter-recovery tests -- `fast_mlsirm` ships no polytomous simulator, so both formulas need to be implemented directly, matching `PolytomousFit`'s documented parameterization -- are in flight in still-open PRs #451 (`tests/test_fast_mlsirm_grm_recovery.py`) and #452 (`tests/test_fast_mlsirm_gpcm_recovery.py`) and not yet merged. Still open: Fixed-Item Parameter Calibration (Kim, 2006 FIPC -- `period_report.py` uses this for later periods, untested; check `link_fixed_item_parameters`/`fixed_item_calibration_diagnostics` for the real two-stage simulation this needs).
- **Security & Compliance**: PII masking cannot break the system. Need SOC 2 and CSAP compliance alternatives to blind PII masking.
- **LLM Orchestration**: Ensure ALL LLM calls route through `contextual-orchestrator` utilizing API keys (BYTEZ, NVIDIA, OPENROUTER, OPENAI) with auto model discovery and optimal reasoning effort allocation (Fugu/Conductor/TRINITY research).

Expand Down
8 changes: 7 additions & 1 deletion frontend/src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,25 @@ beforeEach(() => {

afterEach(() => {
vi.unstubAllGlobals();
window.sessionStorage.clear();
window.localStorage.clear();
});

describe("App, unauthenticated", () => {
it("shows a login button that starts the real OIDC redirect", async () => {
window.history.replaceState({}, "", "/?post=abc#details");
render(<App showLabPanels />);
const button = screen.getByRole("button", { name: /log in/i });
await userEvent.click(button);
expect(signinRedirect).toHaveBeenCalledTimes(1);
expect(signinRedirect).toHaveBeenCalledWith(
expect.objectContaining({
state: expect.objectContaining({ returnUrl: expect.stringMatching(/^\//) }),
state: expect.objectContaining({ returnUrl: "/?post=abc#details" }),
}),
);
// Persisted as a fallback in case the OIDC state round-trip is dropped
// (see oidcReturnUrl.ts's restoreOidcReturnUrl, consumed in main.tsx).
expect(window.sessionStorage.getItem("lineageweave.oidc.returnUrl")).toBe("/?post=abc#details");
});
});

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4610,7 +4610,8 @@ export default function App({ showLabPanels = false }: { showLabPanels?: boolean
</div>
<div className="login-controls">
<button className="btn-primary" onClick={() => {
const returnUrl = window.location.pathname + window.location.search;
const returnUrl = returnUrlFromLocation();
rememberOidcReturnUrl(returnUrl);
void auth.signinRedirect({ state: { returnUrl } });
}}>
{t("Log in")}
Expand All @@ -4620,7 +4621,6 @@ export default function App({ showLabPanels = false }: { showLabPanels?: boolean
<small>Enterprise SSO Authentication</small>
</div>
</div>
{destination === "admin" ? <AdminPanel currentBrandName={brandName} onBrandNameChange={setBrandName} accessToken={accessToken} /> : null}
</main>
<footer className="app-footer" role="contentinfo">
<div className="app-footer-title">
Expand Down
87 changes: 87 additions & 0 deletions tests/test_fast_mlsirm_cat_recovery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"""Real computerized-adaptive-test (CAT) accuracy AND efficiency test for
fast_mlsirm's cat_simulate_polytomous (Dodd, De Ayala & Koch, 1995):
fits a GRM item bank from known true item parameters and person thetas
(same simulation approach as test_fast_mlsirm_grm_recovery.py), then runs
the adaptive simulator against known true thetas and asserts BOTH that
theta recovery stays close to full-bank accuracy AND that CAT actually
uses substantially fewer items than the full bank -- the property that
distinguishes a real CAT test from just another full-bank recovery test.
"""

from __future__ import annotations

import numpy as np
from fast_mlsirm import cat_simulate_polytomous, fit_polytomous

N_PERSONS = 400
N_ITEMS = 40
N_CAT = 4
SEED = 20260101

CAT_MIN_ITEMS = 5
CAT_MAX_ITEMS = N_ITEMS
CAT_SE_THRESHOLD = 0.4

# A real run with these exact parameters/seed measures theta RMSE ~0.40 and
# correlation ~0.91 using a mean of ~8.7 of 40 items -- comparable accuracy
# to the full-bank GRM recovery test (~0.38/~0.92) at roughly a fifth of
# the items. Margins are loose enough to tolerate a minor fast-mlsirm
# version bump while still catching a real regression in either accuracy
# or the adaptive-selection efficiency CAT exists to provide.
#
# MAX_MEAN_ITEMS_USED is deliberately close to the measured ~8.7 (not a
# loose N_ITEMS * 0.5): the same fixture/seed with adaptive=False (random
# item order) measures mean_items_used ~14.97, which still clears rmse/
# correlation bounds -- so a bound of 12 is what actually catches a silent
# fallback to non-adaptive selection (e.g. an `adaptive` flag dropped on
# its way through the Rust binding).
MAX_THETA_RMSE = 0.65
MIN_THETA_CORRELATION = 0.7
MAX_MEAN_ITEMS_USED = 12


def _grm_category_probs(theta: float, discrimination: float, thresholds: np.ndarray) -> np.ndarray:
"""Samejima (1969) graded-response category probabilities."""
cumulative = np.concatenate(([1.0], 1.0 / (1.0 + np.exp(-discrimination * (theta - thresholds))), [0.0]))
return -np.diff(cumulative)


def test_cat_recovers_theta_using_substantially_fewer_items_than_the_full_bank() -> None:
rng = np.random.default_rng(SEED)
true_theta = rng.normal(0.0, 1.0, N_PERSONS)
true_discrimination = rng.uniform(0.8, 2.0, N_ITEMS)
true_thresholds = np.sort(rng.normal(0.0, 1.0, (N_ITEMS, N_CAT - 1)), axis=1)

responses = np.zeros((N_PERSONS, N_ITEMS))
for item in range(N_ITEMS):
for person in range(N_PERSONS):
probs = _grm_category_probs(true_theta[person], true_discrimination[item], true_thresholds[item])
probs = np.clip(probs, 0.0, None)
probs = probs / probs.sum()
responses[person, item] = rng.choice(N_CAT, p=probs)

bank = fit_polytomous(responses, n_cat=N_CAT, model="grm")
assert bank.converged

cat_result = cat_simulate_polytomous(
true_theta,
bank,
min_items=CAT_MIN_ITEMS,
max_items=CAT_MAX_ITEMS,
se_threshold=CAT_SE_THRESHOLD,
adaptive=True,
seed=SEED,
)
theta_eap = cat_result["theta_eap"]
n_used = cat_result["n_used"]
Comment thread
seonghobae marked this conversation as resolved.

rmse = float(np.sqrt(np.mean((theta_eap - true_theta) ** 2)))
correlation = float(np.corrcoef(theta_eap, true_theta)[0, 1])
mean_items_used = float(n_used.mean())

assert rmse < MAX_THETA_RMSE, f"CAT theta RMSE {rmse:.3f} exceeded {MAX_THETA_RMSE}"
assert correlation > MIN_THETA_CORRELATION, f"CAT theta correlation {correlation:.3f} below {MIN_THETA_CORRELATION}"
assert mean_items_used < MAX_MEAN_ITEMS_USED, (
f"CAT used a mean of {mean_items_used:.2f} of {N_ITEMS} items, "
f"not meaningfully fewer than the full bank -- adaptive item selection isn't providing efficiency"
)
Loading