Skip to content

fix(pvmodel): gate Predict at clearSky<50 to suppress night-time phantom output - #135

Merged
frahlg merged 1 commit into
masterfrom
133-pvmodel-night-gate
Apr 19, 2026
Merged

frahlg merged 1 commit into
masterfrom
133-pvmodel-night-gate

Conversation

@frahlg

@frahlg frahlg commented Apr 19, 2026

Copy link
Copy Markdown
Member

Closes #133.

Summary

  • Add a hard gate at the top of `Model.Predict`: when `clearSkyW < 50` return 0. Mirrors the Update-side gate (same threshold, same physical justification).
  • Two regression tests: night-time prediction is 0 regardless of `Beta[0]` drift, and the gate boundary behaves as expected (49 → 0, 50 → nonzero).

Why

Operator report (2026-04-19): planner UI showed −1.1 kW of PV at Mon 02:00 local. The feature vector's intercept term (`x[0]=1`) collapses the learned prediction to `Beta[0]` at night; RLS is free to pick a non-zero `Beta[0]` when that minimises daytime residual, and nothing stops the intercept from leaking into night slots.

Followed by the planner's `selectPlannerPVW` (`mpc/service.go:832`) — at night `forecastPVW=0 < 200 W` so it falls back unreserved to the twin's prediction — the twin's phantom 1.1 kW became the MPC's sole PV input.

Hard gate at the model layer is the right place: physics lives there, the planner trusts the model.

Follow-up

#134 addresses the underlying intercept drift. This PR suppresses the night symptom; #134 will clean up the daytime bias.

Test plan

  • `go test ./internal/pvmodel` — 8 tests green, including 2 new
  • `make test` + `make e2e` — green
  • Smoke on Pi: refresh planner at night, confirm PV row reads 0 W for all post-midnight slots

🤖 Generated with Claude Code

…tom output

Closes #133.

Model.Predict evaluates the learned RLS regression with a feature vector
that includes an intercept term (x[0]=1.0). At night every other feature
is zero (they all multiply clearSkyW=0), so the prediction collapses to
trust*Beta[0]. RLS has no physical constraint forcing Beta[0] to zero —
whenever the daytime training residual is minimized with a non-zero
intercept, the model projects that intercept into every night slot.

Operator report (2026-04-19): planner showed −1.1 kW of PV at Mon 02:00
local, feeding that into the MPC as the night-time generation input.

The Update path already gates at clearSkyW<50 (same "no sun, no signal"
threshold); mirror it on the Predict side. Pure physics — PV production
is bounded below by zero and requires sun above the horizon.

This masks the night-time symptom. The intercept still drifts during
daytime training and biases daytime predictions by a constant Beta[0]
offset; that's tracked separately in #134.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@frahlg
frahlg merged commit 5baa38c into master Apr 19, 2026
1 check passed
@frahlg
frahlg deleted the 133-pvmodel-night-gate branch April 19, 2026 18:09
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.

PV twin predicts non-zero PV at night (Model.Predict returns Beta[0])

1 participant