CaMa: survival and recurrence models, the live scenario figures, and their training from governance #7

Merged
angel merged 33 commits from feature/cama-roundtrip into dev 2026-11-21 15:03:34 -06:00

33 Commits

Author SHA1 Message Date
rockdrigo 1b9afb22ea CaMa: the SEER stages see the molecular subtype; the subtype derivation is shared; the live menu reads the scenarios that can be drawn 2026-11-21 14:43:46 -06:00
rockdrigo 3fdc59df6d CaMa recurrence: the CLI entry imports its data folder; test of the entry a governance job runs 2026-11-21 13:43:19 -06:00
rockdrigo 9fe1f86c8b CaMa recurrence: a version trains, registers and publishes its figures (test) 2026-11-21 13:41:15 -06:00
rockdrigo 0804937578 CaMa recurrence: the METABRIC and SCAN-B analysis as a trainable scenario, with its scenario figures and a patient-to-scenario match 2026-11-21 13:34:56 -06:00
rockdrigo e99eb499d6 CaMa survival: the live figure is the clinical scenario's, over the production model and the live cohort 2026-11-21 13:14:06 -06:00
rockdrigo b1006a97d7 CaMa survival: the clinical scenarios are a shared module and stage 6 lists each scenario's risk factors; the live figure drops the unused options 2026-11-21 13:03:19 -06:00
rockdrigo 997aebd068 CaMa survival: a saved model is rehydrated with the current class before scoring 2026-11-21 12:15:22 -06:00
rockdrigo b8936522be CaMa survival: the figure for a selection of members, scored with the production model over the live cohort; the pipeline's chart wording 2026-11-21 12:07:21 -06:00
rockdrigo ec430c3ee3 CaMa survival: the published figure runs the SEER pipeline's stage-5 functions, and the production model keeps its structure settings 2026-11-21 10:33:48 -06:00
rockdrigo 0cf3e60341 CaMa survival: the published figure carries no test-data note 2026-11-21 10:13:47 -06:00
rockdrigo 4c8b559557 CaMa development record: tables carry their column order 2026-11-21 05:03:52 -06:00
rockdrigo f3be09467f CaMa survival: the SEER pipeline is imported only when a run develops the model 2026-11-21 03:33:44 -06:00
rockdrigo 9cccec5274 CaMa survival: lesion-size feature and the SEER development stages published with each version 2026-11-21 03:28:13 -06:00
rockdrigo 67787adfd4 Merge the SEER survival pipeline
# Conflicts:
#	README.md
#	models/cama/seer_survival/survival_models.py
#	pyproject.toml
2026-11-21 02:07:49 -06:00
rockdrigo edda0fd7b7 Merge CaMa survival scenario and its population results 2026-11-21 02:07:45 -06:00
rockdrigo acc8c371bc CaMa survival: the SEER interval-survival pipeline as a scenario with population results
models/cama/seer_survival is the SEER survival pipeline as Hamilton dataflows, with the interval LR and network keeping
their per-interval fits and surviving an interval without deaths. models/cama/survival is the scenario: it indexes the
total cohort at the first invasive biopsy report (steps/indexing.py), derives the covariates and the outcome from the
cohort's events, fits the interval survival, writes the five routines and publishes the population curves
(analisis/curvas.json) with the version. An estimate may carry the model's own index date.
2026-11-21 02:07:34 -06:00
edgar 941ae15a3e A risk carries the model's index date for its member
Risk and risk_rows give (pac_id, fecha_indice, horizonte_anios, probabilidad, ic_bajo, ic_alto), the shape a batch now
stores: the horizons count from the model's index date, taken from the estimate's rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HmQxVJVNR5FYkPAregGEQ7
2026-11-20 23:02:46 -06:00
edgar 410de1d3b7 Each scenario's index and rules in its pipeline, matching dbt's cohorts
models/steps/indexing.py: a scenario that lists it gets its source cohort as `source_cohort`, and the node `cohort`
re-indexes it by `[config.index]` of its model.toml: the surveillance kind (first cytology) and the post-colposcopy
kind (visit k), with dbt's rules in dbt's order and names, the recruitment window taken from the source cohort's
parameters. Every kind ends with `observacion_previa_insuficiente`, a threshold on the days observed before the index
(0 for now: the data are left-truncated, so rules on earlier events read only what was recorded). On the synthetic
copy the pipeline gives dbt's patients, index dates and attrition for cin2_pim and cin2_logistic (surveillance) and
cin2_pim_post_colposcopy (visit 1, now on cacu/cohorte_total). cin2_logistic's MUESTREO records the index attrition and
the prior history; a stored build's lineage carries its parameters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HmQxVJVNR5FYkPAregGEQ7
2026-11-20 21:54:47 -06:00
edgar 0880181219 Merge dev into feature/cohorts-dbt-canonical: TEA EEG analysis and baselines
Conflicts: the README keeps this branch's rows and adds TEA's; `__main__` keeps the Scenario-based commands and adds
`_own_steps`; pyproject keeps the reports/ paths and adds the `eeg-reference` extra. `GIT_COMMIT_TAG` comes back in
`models.io.lineage` as the name of MLflow's own tag, which `models.tea.eeg.bundle` reads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HmQxVJVNR5FYkPAregGEQ7
2026-11-20 20:05:13 -06:00
edgar ea6db36b23 dbt is the only definition of a cohort: the stored build runs dbt's queries
The WebApi cycle's build (models.cohorts.build.build_of) runs the cohort's queries from dbt's manifest with the same
chain as the export, instead of a Python frame per cohort; the TOML definitions, their frames and definition.py are
removed. A cohort may have no exclusions (cacu/cohorte_total, for models whose rules don't fit SQL) and an optional
`variables` query; the population meta carries the cohort's version. cohort_urls lists a domain's cohorts in the
manifest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HmQxVJVNR5FYkPAregGEQ7
2026-11-20 19:52:05 -06:00
edgar 06829a4498 Post-colposcopy scenario reads the cohort of the first surveillance visit
cin2_pim_post_colposcopy now reads cacu/cohorte_post_colposcopia_visita_1 (dbt): Cheung et al. 2020 index the risk at
the first surveillance visit with a cotest, not at the first cytology. Its description states the provisional
assumption that a colposcopy without a biopsy order is below CIN2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HmQxVJVNR5FYkPAregGEQ7
2026-11-20 19:52:02 -06:00
luis c42f544173 Tests for the SEER survival pipeline's stages and runner 2026-11-20 13:40:06 -06:00
luis 305e855a15 CaMa SEER survival pipeline: the six scripts as Hamilton DAGs, one module of nodes per stage and the heavy routines apart
Stages 01-06 (depuration, MCA balancing and categorization, bootstrap indices, stepwise LR and hybrid Bayesian network, survival curves, risk factors), settings in model.toml, run.py writing each stage's files and pipeline.py as the runner that replaces ejecutar_pipeline.py. New extras seer-survival and seer-survival-dca; experiments/ excluded from the wheel.
2026-11-20 13:40:06 -06:00
luis 76d6b96409 Keep the original SEER survival scripts as experiments (not packaged) 2026-11-20 13:40:06 -06:00
edgar 7d50786ac2 cin2_pim post-colposcopy and post-treatment scenarios, and their kit cohorts
Two TOML-only scenarios on cin2_pim's dataflow (KPNC's scenarios 4 and 5): CIN2+, KPNC's three post cytology groups,
the referral grade as history after colposcopy, and the strata that reproduce KPNC's tables 17 and 24 (one mixture per
referral grade; one mixture). The kit definitions of both cohorts mirror the dbt rules, so the WebApi cycle can build
them and KitBuild read them. A notebook describes the scenarios, their encoders and the shared DAG.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HmQxVJVNR5FYkPAregGEQ7
2026-11-20 12:09:40 -06:00
edgar bde02109ab Surveillance cohort: a glandular-only index result counts as an index result
Mirror of the dbt rule no_index_result, which now reads the timeline's glandular rows (AGC, ADENOCARCINOMA) next to
the Bethesda and HPV ones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HmQxVJVNR5FYkPAregGEQ7
2026-11-20 12:09:28 -06:00
edgar 3e72063e3f cin2_pim with PIMixture's I-spline baseline, frequency weights, HPV strata and KPNC's cytology categories
The incidence baseline is chosen in model.toml (Weibull or I-splines of order 4 with knots at quantiles, equal to
PIMixture's Ispline); identical rows are fitted once with their count as weight; one mixture per stratum, a member of
an unseen stratum or level gets NaN. The index cytology goes into KPNC's six categories, glandular results included and
the most severe winning; an optional history feature is read from the config.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HmQxVJVNR5FYkPAregGEQ7
2026-11-20 12:06:05 -06:00
edgar 01e4406838 The notebook runner moves to reports/: experiment, notebook_jobs and notebook_import next to rendering and eda
They run a notebook on a build's file and keep it as an MLflow run, as eda does; io/ keeps the storage and MLflow
boundary and pipelines/ the cohort pipelines. Moved whole with git mv, imports repointed; models.notebook, the API
notebooks import, stays where it is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HmQxVJVNR5FYkPAregGEQ7
2026-11-19 20:50:46 -06:00
edgar dce29670a4 The classifier's routines join the fitting steps: analytic_method, class_balance, output_confidence and routines
They depend only on the fitted pipeline and the split, so every scenario that lists models.steps.model_fitting
records them; sampling and missing_data stay in cin2_logistic, which owns windowed_outcomes and index_sample_results.
Moved as written in the merge (git blame -C follows them to 1b45bc6).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HmQxVJVNR5FYkPAregGEQ7
2026-11-19 20:46:50 -06:00
edgar 6fbf573999 Merge dev into the Hamilton dataflow: the governance routines and the notebook runner on scenarios declared in model.toml
dev's 1b45bc6 (governance requirements, sandboxed notebooks) was written on the per-scenario driver that this branch
replaced with models.dags; it is carried over in that shape:

- cin2_logistic: the five ML-01a routines (sampling, missing_data, analytic_method, class_balance, output_confidence)
  and `routines` are nodes of the scenario's dataflow, on its node names (windowed_outcomes, train_set, test_set,
  fitted_pipeline, test_probabilities); `calibration_bins` is a config input with a default.
- io/adapters, dags/training: the saver writes each routine with TrainingRun.log_routine before logging the model;
  the driver hands it `routines` when the dataflow has that node. Without it a scenario still trains, but the registry
  won't promote it (ROUTINE_KINDS).
- io/tracking: dev's log_routine, run_files and run_file next to this branch's log_model (scikit-learn or pyfunc,
  pinned requirements).
- reports/rendering: dev's Quarto and Jupyter renderers (io/rendering.py, followed as a rename) with this branch's
  notebook hash; notebook_jobs and experiment import it from there, and cohort_reference and file_sha256 from
  io/storage.
- cin2_logistic/train.py: a delegate to models.dags.training for callers of the old driver.
- Persistance's English names from dev: persistance.edges.gold, cohort_repository.

Tests: 219 passed against the monorepo's dev Persistance, Extraction and Core (OCR with tesseract deselected).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HmQxVJVNR5FYkPAregGEQ7
2026-11-19 20:44:34 -06:00
edgar fe7f881ade CIN2+ PIM coding as KPNC's: a visit is free of CIN2+ with HPV-negative and NILM or ASC-US, a positive without histology leaves it unknown
known_negative takes lists per key; the last negative carries every earlier one, and follow-up without a test isn't
counted. docs/codificacion_pim.md gives the six example patients, each with its unit test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HmQxVJVNR5FYkPAregGEQ7
2026-11-19 20:23:36 -06:00
edgar 0be622c12d Models as a dataflow with Hamilton adapters: scenarios declared in model.toml, cohort read from the database or a file, a scikit-learn model registered with its requirements, estimates per horizon, and the CIN2+ prevalence-incidence scenario 2026-11-11 23:27:38 -06:00
edgar c9eb68ee42 Fitting steps every scenario shares: a temporal split, the classifier chosen by config, the fit and its metrics 2026-11-11 23:27:38 -06:00