Skip to content

physXAI 1.0.0 – Phase 3: recursive multi step evaluation and training - #73

Merged
PatrickHenkel1 merged 2 commits into
v1/phase-2-exprfrom
v1/phase-3-recursive
Nov 6, 2026
Merged

PatrickHenkel1 merged 2 commits into
v1/phase-2-exprfrom
v1/phase-3-recursive

Conversation

@PatrickHenkel1

Copy link
Copy Markdown
Collaborator

Phase 3 of the physXAI 1.0.0 refactoring, the core feature: single step models are evaluated and trained over a horizon, as in an MPC. Stacked on #72 (base v1/phase-2-expr).

Summary

  • Recursive evaluation (physXAI.evaluation.rollout):
    • PreprocessingSingleStep(..., eval_horizon='24h') applies every single step model recursively on windows of the val/test/train data.
    • The model must predict one of its own inputs: Change(T) or T with input T and its lags.
    • RMSE, MAE and bias per step are stored in td.horizon_metrics and {name}_training_data.json, and plotted over the horizon in hours.
  • Derived inputs are recomputed in every step: expressions inside the model anyway; data columns such as vT from their expressions. This was impossible with constructed features.
  • Implementation: RecursiveCell is a keras RNN cell around the step model and is differentiable. scikit-learn linear regressions are wrapped as a frozen dense layer.
  • Training on the multi step error: recursive_training=RecursiveTraining(horizon='24h', first_step_weight=0.25, mode='single_then_multi').
    • Available for all keras models; ModularANN(solver='ols') can serve as the initialization.
    • Only the step model weights are trained, so AgentLib-MPC still receives a single step model.
  • Example: executables/bestest_hydronic_heat_pump/TAir_recursive.py (physics terms plus a residual MLP).

Results on the BOPTEST data (test split, 12 h horizon)

RMSE 1 h RMSE 6 h RMSE 12 h bias 12 h
single step training 0.109 K 0.619 K 0.617 K 0.34 K
+ recursive fine-tuning (6 h) 0.095 K 0.468 K 0.405 K 0.19 K

The single step RMSE is nearly identical for both (0.038 / 0.037). Only 14 days of data, i.e. 4 test windows, so the numbers are indicative.

Fixes

  • The legacy multi step evaluation wrote its predictions into the training data.
  • BuildContext cached tensors by id() of temporary expressions, which Python reuses (wrong tensors).
  • Early stopping on val_loss without validation data; seeds were set at object creation.

Test plan

  • pytest: 102 passed. New tests cover exact rollouts (error < 1e-3 over the horizon), comparison with a hand-written recursion including the recomputed vT, an offset showing up as an accumulating bias, lags and absolute outputs, step weights and both training modes.
  • All executables run.

🤖 Generated with Claude Code

…models

- physXAI.evaluation.rollout: recursion derived from the names (Change(X) /
  X and lags), RecursiveCell (keras RNN cell around the step model) with
  recomputation of derived columns depending on the recursive feature,
  RMSE / MAE / bias per step of the horizon for every split
- Single step models evaluate the horizon automatically with
  PreprocessingSingleStep(eval_horizon='24h'); horizon plot
- physXAI.training.RecursiveTraining: training on the multi step error with
  weighted first step, modes single_then_multi / multi_step, also as fine
  tuning of OLS solutions; the saved model stays a single step model
- Fixes: in-place writes of the legacy multi step evaluation, BuildContext
  id reuse, early stopping without validation data, seeding at creation
- Example TAir_recursive.py, tests for exact rollouts, recomputed columns,
  bias, lags, absolute outputs and the recursive training

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 6, 2026 00:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@PatrickHenkel1
PatrickHenkel1 merged commit d7983a4 into v1/phase-2-expr Nov 6, 2026
@PatrickHenkel1
PatrickHenkel1 deleted the v1/phase-3-recursive branch November 6, 2026 06:27
@PatrickHenkel1 PatrickHenkel1 mentioned this pull request Nov 8, 2026
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