Score the full model against the base model; compile the search step
Validation: the walk-forward evaluator now replays all zones together with the full model (electrical heat, neighbour exchange, ventilation and recovery) using the parameters frozen at the forecast start and the electrical heat and window openings that actually happened, and scores the base 3-parameter model on the same spans. Forecast Error sensors add base_model_mae and improvement_vs_base (share of the base model's error the new features remove; 0 = no gain, negative = worse). Saved 0.3 statistics load with their own error as the base column. On synthetic apartments, 60-minute error full vs base: gaming office 0.031 vs 0.182 °C (83 % better), bedroom with ventilation 0.026 vs 0.218 °C (88 %), two coupled rooms 0.024 vs 0.037 °C (34 %; gone by 120 min, where the constant-outdoor assumption dominates). The same ventilation week without window sensors shows no improvement, as it should. These check the method, not real-world accuracy. Performance: every term of a zone's 5-minute change is affine in the zone temperatures and the radiator lag, and which layer applies depends only on which inputs exist. compile_step_model reads the coefficients off the real model per zone and step, so the plan search does a few multiply-adds per step. It matches the direct model to 1e-12 and makes a 180-minute, 5-zone search 4.5x faster (0.73 s here, close to the old base-only search). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8d197fabcd
commit
b1577a0c78
7 files changed
+266
-31
No files matched your search
@@ -76,6 +76,25 @@ class EvaluationTests(unittest.TestCase):
|
||||
self.assertEqual(evaluator.summary(['sensor.room'])[15]['samples'], 7)
|
||||
self.assertEqual(before, 7)
|
||||
|
||||
def test_full_model_replays_actual_inputs_and_is_compared_with_base(self):
|
||||
base = (0.004, 0.12, 0.0005)
|
||||
full = {'base': base, 'uses_extended': True,
|
||||
'extended': (['loss', 'heat', 'bias', 'internal'], base + (0.15,)),
|
||||
'ventilation': (['vent_natural'], (0.01,))}
|
||||
evaluator, temp = ev.ForecastEvaluator(0.1), 20.0
|
||||
for k in range(40):
|
||||
internal = 0.4 if (k // 8) % 2 else 0.0 # gaming on and off
|
||||
opening = 1.0 if k % 10 in (3, 4) else 0.0 # short ventilation
|
||||
if k:
|
||||
temp += 0.004 * (5 - temp) + 0.12 * 0.5 + 0.0005 + 0.15 * internal + 0.01 * opening * (5 - temp)
|
||||
evaluator.observe(START + timedelta(seconds=300 * k), {'r': temp}, 5.0, 0.5, 0.0, {'r': base},
|
||||
models={'r': full},
|
||||
inputs={'r': {'internal': internal, 'ventilation': {'opening': opening}}})
|
||||
stats = evaluator.summary(['r'])[60]
|
||||
self.assertAlmostEqual(stats['mae'], 0, places=6)
|
||||
self.assertGreater(stats['base_model_mae'], 0.05)
|
||||
self.assertEqual(stats['improvement_vs_base'], 1.0)
|
||||
|
||||
def test_saved_statistics_round_trip_and_reject_garbage(self):
|
||||
evaluator = plant(10)
|
||||
restored = ev.ForecastEvaluator(0.1)
|
||||
@@ -86,8 +105,11 @@ class EvaluationTests(unittest.TestCase):
|
||||
'not-a-day': {'15': {'sensor.room': [1, 0.0, 0.1, 0.1]}},
|
||||
day: {'45': {'sensor.room': [1, 0.0, 0.1, 0.1]},
|
||||
'15': {'sensor.a': [1, 0.0, -0.1, 0.1], 'sensor.b': [True, 0, 0, 0],
|
||||
'sensor.c': [1, float('nan'), 0, 0], 'sensor.d': [2, 0.1, 0.2, 0.4]}}}})
|
||||
self.assertEqual(restored.as_dict(), {'days': {day: {'15': {'sensor.d': [2, 0.1, 0.2, 0.4]}}}})
|
||||
'sensor.c': [1, float('nan'), 0, 0], 'sensor.d': [2, 0.1, 0.2, 0.4],
|
||||
'sensor.e': [2, 0.1, 0.2, 0.4, 0.3], 'sensor.f': [2, 0.1, 0.2, 0.4, -1]}}}})
|
||||
# A 0.3 bucket has no base-model column; its model was the base model then.
|
||||
self.assertEqual(restored.as_dict(), {'days': {day: {'15': {
|
||||
'sensor.d': [2, 0.1, 0.2, 0.4, 0.2], 'sensor.e': [2, 0.1, 0.2, 0.4, 0.3]}}}})
|
||||
for garbage in (None, [], {'days': []}):
|
||||
restored.load(garbage)
|
||||
self.assertEqual(restored.as_dict(), {'days': {}})
|
||||
|
||||
Reference in new issue
Block a user