Skip to content

Temporal straightening - #493

Draft
edyoshikun wants to merge 13 commits into
rescale-lot-correctionfrom
temporal-straightening
Draft

Temporal straightening#493
edyoshikun wants to merge 13 commits into
rescale-lot-correctionfrom
temporal-straightening

Conversation

@edyoshikun

Copy link
Copy Markdown
Member

No description provided.

edyoshikun and others added 9 commits July 24, 2026 12:04
Add an optional MMD-vs-HPI kinetics plot showing when and how much each
condition's cell cloud diverges from control over infection time.

- config: mmd_hpi_bin_hours (None = off) sets the HPI bin width in hours
- _compute_hpi_mmd: per-bin MMD is TIME-MATCHED — control@bin vs condition@bin,
  not condition@bin vs the time-pooled control reference. The DynaCLR embedding
  carries a strong time/culture axis (uninfected cells drift substantially over a
  36h timelapse), so a time-pooled reference conflates infection with that axis
  and produces a spurious early-high/dip artifact. Matching within the bin cancels
  the shared time component and isolates infection.
- emits a control-vs-control null (half-split per bin) as the no-difference floor
- plot_mmd_vs_hpi: condition curves + grey null band; hollow markers = per-bin
  MMD not significant (raw p > mmd_pvalue_threshold)

Validated: pAL17 becomes a clean sigmoid (~0 until ~14h, rise to 0.25); TOMM20
shows a real monotonic rise (~0.004->0.018) above null, vindicating a genuine but
weak infection signal that the time confound had previously distorted.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Weak channels (TOMM20/Phase3D) have a real but graded control-vs-perturbed shift,
not a distinct bimodal split — the perturbed-only GMM gate abstains on them. Add a
control-anchored alternative that produces labels with a controlled false-positive
rate.

- fit_control_anchored_labels (witness_gmm.py): model perturbed scores as
  pi*N(control) + (1-pi)*N(remodel) with the baseline Gaussian FROZEN to the
  (time-matched) control distribution; fit only the remodel component + mixing
  weight via constrained EM. "Remodel" = excess over baseline, so a subtle
  proportion shift still yields labels. Posterior threshold calibrated so the
  control false-positive rate equals control_fp_target.
- config: gate (gmm | control_anchored) + control_fp_target (default 0.05)
- label_marker branches on gate; sidecar records gate/remodel_fraction/control_fp/
  posterior_threshold for control_anchored, GMM summary otherwise
- control-FP diagnostic line uses the calibrated threshold; plot_witness_gmm is
  GMM-only

Validated: TOMM20 (time-matched witness + control_anchored, 5% target) yields
6617 remodel / 9123 noremodel with realized control FP 0.050 (vs ~22% under the
pooled GMM gate). Tests 6/6.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Curvature loss (1 - cos of consecutive latent velocities) and a shared
next-state predictor MLP for temporal-dynamics learning, both acting on
the encoder embedding z. Stop-grad predictor target; DDP-safe zero for
all-invalid sequence batches. Includes unit tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add emit_sequence to the datamodule/dataset: sample K consecutive
same-track same-marker frames (fixed frame stride) via the lineage
lookup, emit a (B*K,C,Z,Y,X) 'sequence' batch key with a valid mask.
Engine encodes it in one forward and adds lambda_curv*L_curv +
lambda_pred*L_pred on z, with cosine-annealed weights. All defaults
disabled so existing configs are unaffected. Includes a fast-dev smoke
config.

Also fix a pre-existing z_focus NaN guard in _slice_patch that only
caught Python float NaN, not numpy float, crashing int(NaN) on parquets
with unpopulated z_focus rows.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@edyoshikun
edyoshikun changed the base branch from main to rescale-lot-correction July 27, 2026 17:57
@edyoshikun
edyoshikun marked this pull request as draft July 27, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant