Repository navigation
RNN/PCNN: normalize constant inputs with variance 1; PCNN losses scaled by a flow - #94
Merged
PatrickHenkel1 merged 2 commits intoNov 10, 2026
Merged
Conversation
The normalization of the recurrent models used the variance floor 1e-12, so a constant input column (e.g. a fixed air flow in the training data) was scaled by 1e6. Any later deviation from the training value, such as a rounded value in an MPC (0.07222 instead of 0.072222), reached the network as a huge normalized input; in a PCNN it shifted the hidden states by up to 3. Constant columns are now normalized with variance 1, as in the single step models (expr.blocks, ann_models.output_scale). New helper input_variance, used by build_step_model and build_pcnn_step_model, with a regression test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A loss of the energy accumulator can be scaled by a flow input,
b * V * (T_x - T), e.g. a ventilation with the air flow V and the supply
temperature T_x. Before, every loss had a constant conductance, so a varying
air flow had to be learned by the recurrent network.
- PCNNModel(flows={loss input: flow input}); PCNNTerm.flow
- the step model multiplies the gradient by the flow (keras Multiply, translated
by AgentLib-MPC); the flow is no input of f, like the controls
- the initial rates given as None are estimated with the scaled term
- the consistency check 1 - sum b > 0 uses the largest flow of the training data
- flows is only written to the config when used
Tests: estimated rate equals the true dt*cp/C of the one room data, closed loop
rollout, config round trip, invalid configurations, CasADi contract.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two changes to the recurrent models. Both came up while using them as room temperature models in an MPC (AgentLib-MPC branch 143).
Fix: constant inputs (RNNModel, PCNNModel). The variance floor 1e-12 scaled a constant input column by 1e6. A tiny deviation at runtime, such as a value rounded by the MPC, then shifted the hidden states by up to 3. Constant columns are now normalized with variance 1, as in the single step models (new helper input_variance).
Feature: PCNN losses scaled by a flow. A loss can now be scaled by a flow input, b * V * (T_x - T), for example ventilation with the air flow V:
PCNNModel(heating={"load": None}, losses={"T_sup": None, "T_amb": None}, flows={"T_sup": "V_flow"})
The flow is not an input of f. Initial rates and the consistency check (1 - sum b > 0, using the largest flow in the training data) take the flow into account. Existing configs are unchanged.
Tests:
280 passed locally. test_deterministic_operations fails only in my environment and is unrelated to this PR. CHANGELOG updated.