C1a: code only, no comments, no Markdown
Remove 212 Python docstrings and 118 comments, and trim prose from three noqa pragmas. The submodule had zero tracked Markdown files. Preserve the existing executable statements and lint pragmas. Use pass for class bodies that previously consisted of only a docstring.
This commit is contained in:
@@ -1,22 +1,3 @@
|
||||
"""Age baselines: each metric's value (and per electrode and zone) against children of the same
|
||||
age in a reference cohort.
|
||||
|
||||
Seven scenarios (`SCENARIOS`), each trained on its feature table (one row per valid reference
|
||||
study: the scenario's features from `Analysis.features` plus `age_months`). Every feature gets
|
||||
its own baseline, plain JSON-able data (`train`), scored by `score`:
|
||||
|
||||
* Centile curves: on 120 ages log-spaced from 1 to 216 months, the p5, p25, median, p75 and p95
|
||||
of the reference weighted by a Gaussian on log age (width 0.2), where the effective number of
|
||||
studies is at least 30 and the age lies within the reference's. A value scores z = (value -
|
||||
median) / ((median - p5 or p95 - median) / 1.645), outside -1 / +1 below p5 / above p95; the
|
||||
centiles are interpolated on log age; ages outside the curve get none.
|
||||
* Count rate (spikes, which most reference children never have): the reference's rate per
|
||||
minute (16 to 37 months) and its dispersion between children (negative binomial by moments,
|
||||
Poisson without excess). A value is a count in the child's own minutes (`exposure`): z from
|
||||
the mid-p tail of that many or more, clipped to ±8; outside +1 when P(N >= n) < 0.05; p5,
|
||||
median and p95 are the rates at those quantiles of the count in those minutes.
|
||||
"""
|
||||
|
||||
import math
|
||||
from dataclasses import dataclass
|
||||
|
||||
@@ -35,10 +16,10 @@ EXPOSURE = "minutes"
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Scenario:
|
||||
metric: str # the metric code it scores
|
||||
parts: tuple[str, ...] # of the metric: "value", "electrodes", "zones"
|
||||
metric: str
|
||||
parts: tuple[str, ...]
|
||||
stage: str | None = None
|
||||
counts: bool = False # a count against the `minutes` feature, not centile curves
|
||||
counts: bool = False
|
||||
|
||||
|
||||
SCENARIOS = {
|
||||
@@ -54,7 +35,6 @@ PREFIX = {"electrodes": "electrode_", "zones": "zone_"}
|
||||
|
||||
|
||||
def _weighted_quantile(x: np.ndarray, w: np.ndarray, q: float) -> float:
|
||||
"""Interpolated between the midpoints of each weight's cumulative share."""
|
||||
order = np.argsort(x)
|
||||
x, w = x[order], w[order]
|
||||
return float(np.interp(q, (np.cumsum(w) - 0.5 * w) / w.sum(), x))
|
||||
@@ -89,7 +69,7 @@ def _count_rate(values: np.ndarray, ages: np.ndarray, exposure: np.ndarray) -> d
|
||||
rate = float(n.sum() / x.sum()) if x.sum() > 0 else float("nan")
|
||||
mu = rate * x
|
||||
excess = float(((n - mu) ** 2 - n).sum())
|
||||
k = float((mu**2).sum() / excess) if excess > 0 else None # None: Poisson
|
||||
k = float((mu**2).sum() / excess) if excess > 0 else None
|
||||
return {
|
||||
"kind": "count_rate",
|
||||
"ages": list(COUNT_AGES),
|
||||
@@ -101,8 +81,6 @@ def _count_rate(values: np.ndarray, ages: np.ndarray, exposure: np.ndarray) -> d
|
||||
|
||||
|
||||
def train(features: pd.DataFrame, scenario: str) -> dict:
|
||||
"""Feature -> baseline, for every feature of the scenario's table (`age_months` and the
|
||||
count's `minutes` excepted)."""
|
||||
counts = SCENARIOS[scenario].counts
|
||||
ages = features["age_months"].to_numpy(float)
|
||||
out = {}
|
||||
@@ -164,8 +142,6 @@ def _score_count(baseline: dict, value: float, age: float, exposure: float | Non
|
||||
def score(
|
||||
baseline: dict, value: float | None, age_months: float | None, exposure: float | None = None
|
||||
) -> dict:
|
||||
"""z, outside (-1/0/+1), p5, median, p95 of a value at an age; None where the value, the
|
||||
age or the baseline's coverage is missing."""
|
||||
value, age_months = _number(value), _number(age_months)
|
||||
if value is None or age_months is None:
|
||||
return dict.fromkeys(("z", "outside", "p5", "median", "p95"))
|
||||
@@ -175,9 +151,6 @@ def score(
|
||||
|
||||
|
||||
def deviations(models: dict[str, dict], analysis) -> dict[str, dict]:
|
||||
"""Metric code -> {"value": score, "electrodes": {e: score}, "zones": {z: score}} from the
|
||||
trained scenarios in `models` (scenario -> `train`'s output); a scenario without a model
|
||||
leaves its parts out."""
|
||||
out = {m.code: {} for m in analysis.metrics}
|
||||
metrics = {m.code: m for m in analysis.metrics}
|
||||
for name, scenario in SCENARIOS.items():
|
||||
|
||||
Reference in New Issue
Block a user