Skip to content

Batch phase 2: online Nomikos-MacGregor monitoring - #460

Open
kgdunn wants to merge 1 commit into
claude/process-improve-library-review-9h1fn2from
claude/batch-phase2-online-monitoring
Open

Batch phase 2: online Nomikos-MacGregor monitoring#460
kgdunn wants to merge 1 commit into
claude/process-improve-library-review-9h1fn2from
claude/batch-phase2-online-monitoring

Conversation

@kgdunn

@kgdunn kgdunn commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds BatchPCA.predict_online: projection to the model plane (PMP) for a partially-observed batch. At each time sample the future trajectory columns are treated as missing and the score is the least-squares fit of the observed columns onto the loadings (t = pinv(P_obs) @ x_obs); initial conditions, known from the batch start, are always observed. At full observation it matches BatchPCA.diagnose exactly.
  • Adds BatchMonitor: builds time-varying Hotelling's T2 and SPE control limits by running every good batch through predict_online at each sample and summarising the good-batch spread (spe_calculation per sample; the analytical F-based T2 limit). monitor() tracks a new batch sample-by-sample and flags the samples where each statistic exceeds its limit.
  • Adds online_monitoring_plot: the online SPE/T2 chart, drawing the batch trace over the time-varying limit and the mean good-batch trace, with alarm samples marked.

This is Phase 2 of the batch modernization plan (online monitoring). It builds on the offline BatchPCA from Phase 1.

Note on base branch: this PR is stacked on claude/process-improve-library-review-9h1fn2 (Phase 1, #459), since predict_online is a method on BatchPCA which isn't merged yet. GitHub will retarget the base to main automatically once #459 merges. Review #459 first.

Test plan

  • tests/batch/test_batch_monitor.py: PMP matches diagnose at full observation; upto_k bounds; limit shapes; a good training batch stays mostly in-limit; a large injected fault in a real nylon batch trips SPE in the fault window; upto_k truncation; initial-conditions threaded end-to-end
  • tests/batch/test_batch_plots.py: online monitoring plot builds for SPE and T2; bad-statistic guard
  • Full batch suite: 111 passed; ruff check . and mypy src/process_improve clean (142 files)

Checklist

  • Version bumped in pyproject.toml (MINOR: 1.55.0 -> 1.56.0) and CITATION.cff synced
  • Tests added or updated where relevant
  • ruff check . passes
  • CHANGELOG.md updated

🤖 Generated with Claude Code

https://claude.ai/code/session_01SyEpexCyqHn1rwTMYQSiP6


Generated by Claude Code

BatchPCA.predict_online projects a partially-observed batch onto the
model by projection to the model plane (PMP): future trajectory columns
are treated as missing and the score is the least-squares fit of the
observed columns onto the loadings, with initial conditions always
observed. At full observation it matches BatchPCA.diagnose.

BatchMonitor builds time-varying T2 and SPE control limits by running
every good batch through predict_online at each time sample and
summarising the good-batch spread (spe_calculation per sample; the
analytical F-based T2 limit). monitor() tracks a new batch sample by
sample and flags where each statistic exceeds its limit.
online_monitoring_plot draws the trace over the limit band with alarm
markers.

Bumps to 1.56.0 with CITATION, CHANGELOG, and docs updates.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyEpexCyqHn1rwTMYQSiP6
@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.17857% with 11 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/process_improve/batch/_batch_pca.py 83.33% 3 Missing and 3 partials ⚠️
src/process_improve/batch/_batch_monitor.py 94.11% 2 Missing and 1 partial ⚠️
src/process_improve/batch/_batch_plots.py 91.66% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

kgdunn pushed a commit that referenced this pull request Aug 21, 2026
…plots, loaders

Consolidates the stale #459 / #460 / #462 stack onto current main, as
one commit series inside the mid-course-correction PR:

- BatchPCA: batchwise-unfolded (Nomikos-MacGregor) PCA with an optional
  initial-conditions (Z) join, composed over multivariate.PCA and
  MCUVScaler; batch-level scores, SPE, T2, contributions and the plot
  and limit conveniences.
- BatchPCA.predict_online: projection to the model plane for a
  partially-observed batch (upgraded to the shared missing-data
  projection API in a later commit series).
- BatchMonitor: time-varying online SPE and T2 limits learned from good
  batches, with per-sample alarms, plus online_monitoring_plot.
- BatchPLS: batchwise-unfolded [Z | X] -> Y regression to final
  quality. Refreshed beyond the original: the class now owns both
  scalers publicly (center_/scale_ for the unfolded block,
  y_center_/y_scale_ for the quality block; the inner PLS runs with
  scale=False), reports beta and RMSE in engineering units, and adds a
  prediction_interval wrapper. The mid-course corrector reads these
  public attributes instead of any PLS internals.
- time_varying_loading_plot and contribution_at_time_plot for the
  unfolded structure; dataset loaders load_nylon, load_dryer and
  load_batch_fake_data for the bundled batch CSVs.
- Integration test: BatchPLS on a simulator historical campaign (80
  batches, 4 components) reaches fit R2 0.83 and out-of-sample
  correlation 0.80 against fresh batches; thresholds pinned below with
  margin.

The #461 transformer facades are deliberately not re-landed; they can
be revived separately if wanted.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZAyiPT8xURSdi24yFKCra
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.

2 participants