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 -- `tests/test_fast_mlsirm_grm_recovery.py` (new) simulates polytomous GRM responses from known true item parameters and person thetas (`fast_mlsirm` ships no polytomous-specific simulator, so the Samejima (1969) graded-response formula is implemented directly in the test), fits them with `fast_mlsirm.fit_polytomous` -- the same function `period_report.py`'s production code calls -- and asserts the recovered EAP thetas are close to true by RMSE (measured ~0.38, asserted `< 0.6`) and correlation (measured ~0.92, asserted `> 0.75`). This is real GRM theta-recovery accuracy testing against synthetic data with known ground truth, not item-parameter calibration or an infra-only smoke test. Still open: item-parameter calibration, GPCM recovery (only GRM covered so far), Fixed-Item Parameter Calibration (Kim, 2006 FIPC -- `period_report.py` uses this for later periods, untested), and CAT (`fast_mlsirm.cat`/`administer_adaptive_test` -- not exercised anywhere in this repo's tests) remain unverified.
- **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
3 changes: 3 additions & 0 deletions frontend/src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ describe("App, unauthenticated", () => {
state: expect.objectContaining({ returnUrl: expect.stringMatching(/^\//) }),
}),
);
// 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")).toMatch(/^\//);
});
});

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
67 changes: 67 additions & 0 deletions tests/test_fast_mlsirm_grm_recovery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""Real theta-recovery test for the GRM model period_report.py actually
fits: simulate polytomous responses from known true item parameters and
person abilities, fit them with fast_mlsirm.fit_polytomous (the same
function period_report.py calls, per its own module docstring), and assert
the recovered EAP thetas are close to the true thetas by RMSE and
correlation -- not a placeholder or an infra-only smoke test.

fast_mlsirm ships no polytomous-specific simulator (only MLS2PLMConfig's
multi-level simulate()), so the GRM response-generation formula is
implemented directly here: cumulative-logistic category boundaries
(Samejima, 1969), sampled per person/item from the resulting category
probabilities.
"""

from __future__ import annotations

import numpy as np
from fast_mlsirm import fit_polytomous, score_polytomous, validate_irt_response_matrix

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

# Reasonable bounds for a 12-item, 4-category GRM test at this sample size:
# a real run with these exact parameters/seed measures RMSE ~0.38 and
# correlation ~0.92, comfortably inside literature-typical recovery for a
# test this length. The margins below are loose enough to tolerate a minor
# fast-mlsirm version bump while still catching an actual estimation
# regression (e.g. RMSE blowing up past ~1 std or correlation collapsing).
MAX_THETA_RMSE = 0.6
MIN_THETA_CORRELATION = 0.75


def _grm_category_probs(theta: float, discrimination: float, thresholds: np.ndarray) -> np.ndarray:
"""Samejima (1969) graded-response category probabilities for one
person/item pair, given known true parameters."""
cumulative = np.concatenate(([1.0], 1.0 / (1.0 + np.exp(-(discrimination * theta - thresholds))), [0.0]))
return -np.diff(cumulative)
Comment thread
seonghobae marked this conversation as resolved.


def test_grm_recovers_true_theta_within_expected_rmse() -> 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)
Comment thread
seonghobae marked this conversation as resolved.

responses = validate_irt_response_matrix(responses, item_type="polytomous", n_categories=N_CAT)
Comment thread
seonghobae marked this conversation as resolved.
fit = fit_polytomous(responses, n_cat=N_CAT, model="grm", max_iter=80)
assert fit.converged

scored = score_polytomous(responses, fit)
theta_eap = scored["theta_eap"]

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

assert rmse < MAX_THETA_RMSE, f"theta recovery RMSE {rmse:.3f} exceeded {MAX_THETA_RMSE}"
assert correlation > MIN_THETA_CORRELATION, f"theta recovery correlation {correlation:.3f} below {MIN_THETA_CORRELATION}"
Loading