Metrics & formulas¶
Derived from the ai_cdss source (metrics.py builders, recommender.py
MVT criterion). Notation: patient \(p\), protocol \(q\), clinical subscale \(k\),
session index \(t\) (within a \((p,q)\) pair). \(P_p\) is the set of all
protocols available to patient \(p\) (their PPF protocol set,
state.all_protocols); \(\mathrm{prescribed}_p \subseteq P_p\) is the set
prescribed in the prior week.
Recent adherence¶
Per-session adherence \(A_t \in [0,1]\) is an input (session data); a day
where every session was NOT_PERFORMED sets \(A_t = \mathrm{NaN}\) so a
fully-skipped day does not anchor the average. RECENT_ADHERENCE is the
exponentially-weighted moving average of \(A_t\) per \((p,q)\)
(ewm(alpha, adjust=True)):
Delta DM¶
A robust local trend of the difficulty-modulation value \(\mathrm{DM}\) per
\((p,q)\), in two steps (build_delta_dm).
1 · Smoothing — Savitzky–Golay filter (window \(L=7\), polynomial order \(2\)):
2 · Slope — rolling Theil–Sen regression of \(\widetilde{\mathrm{DM}}\) against the session index over a window \(W=7\) (median of pairwise slopes, outlier-robust):
Missing values are filled with \(0\).
Patient–protocol fit (PPF)¶
Cosine similarity between the patient's clinical deficit vector and the
protocol's attribute vector, both indexed by subscale \(k\) (compute_ppf).
Patient deficit (normalize clinical scores by their max, take the complement):
Protocol attributes (mean of the protocol features mapped to subscale \(k\)):
PPF (cosine):
The per-subscale contribution \(\mathrm{CONTRIB}_{p,q,k} = \hat d_{p,k}\,\hat a_{q,k}\) sums over \(k\) to \(\mathrm{PPF}(p,q)\).
Score¶
Weighted linear combination of the three metrics (default weights
\(w=[1,1,1]\)); missing components are treated as \(0\) (Scorer):
MVT swap criterion¶
The threshold is the mean score over all of patient \(p\)'s protocols
(per-patient, protocol-wide) (_below_mean_protocols):
Swap targets are the prescribed protocols scoring strictly below that patient's own protocol-set mean:
Fallback (aisn_min_one_swap): if \(\mathrm{swap}_p = \varnothing\),
force-swap the single lowest-scoring prescribed protocol,
\(\arg\min_{q \in \mathrm{prescribed}_p} \mathrm{SCORE}(p,q)\).
Constants¶
| Symbol | Value | Source (constants.py) |
|---|---|---|
| \(\alpha\) (EWMA) | \(0.5\) | EWMA_ALPHA |
| \(L\) (Savitzky–Golay window) | \(7\) | SAVGOL_WINDOW_SIZE |
| poly (Savitzky–Golay order) | \(2\) | SAVGOL_POLY_ORDER |
| \(W\) (Theil–Sen window) | \(7\) | THEILSON_REGRESSION_WINDOW_SIZE |
| \(w\) (score weights) | \([1,1,1]\) | Scorer default |