You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit d5d7758
Browse filesBrowse the repository at this point in the historyBrowse files
reconcile(observations): fold #266 into main's newer observation handling
Keep main's #272/#302 observation-error and forecast files (which superseded
the branch's older right-alignment), keep the branch's new feature file
requirements.jl, and consolidate the observation tests.
Also fixes two pre-existing main defects exposed by the rebase's test run:
- observations.jl had a missing 'end' between two @testItems, so the second
never ran as its own testitem (main's own CI was failing on this).
- the stale #272 NamedTuple test asserted gaps were sampled as latents; they
are marginalised out, matching the implementation and the newer gap tests.
@assertlength(N) == n "The number-of-trials vector `N` (length $(length(N))) must match the expected-observation series length ($n)"
60
-
return N
69
+
_binomial_trials(N::AbstractVector{<:Integer}, n) = N
70
+
71
+
# Build the per-time-point trials distribution, right-aligning the trials
72
+
# against the expected series exactly as the observations are aligned. `n_diff`
73
+
# shifts the trials so their last entry pairs with the last expected step, which
74
+
# makes the two natural shapes — one entry per observation, or one per expected
75
+
# value — put the same trials on the same time points, and leaves the head of
76
+
# whichever runs longer unused. Trials that do not reach back to the first
77
+
# scored step are rejected rather than quietly shifted.
78
+
function_trial_dist(obs_model, p_t, N, diff_t)
79
+
n =length(p_t)
80
+
N_t =_binomial_trials(N, n)
81
+
first_step =first(_scored_steps(diff_t, p_t))
82
+
n_diff =length(N_t) - n
83
+
@assert first_step + n_diff >=1"The number of trials `N` (length $(length(N_t))) must cover every scored time point: $(n - first_step +1) are needed to score $(n + diff_t) observations against $n expected values"
@assert y_t isa NamedTuple&&haskey(y_t, :N) "BinomialError needs `y_t` to be a NamedTuple carrying the number of trials, e.g. `(y = successes, N = trials)` (use `y = missing` to simulate)"
65
89
66
-
# Read the number of trials from the data.
67
-
N_t =_binomial_trials(y_t.N, length(Y_t))
90
+
# Read the number of trials from the data before `y_t` is rebound to the
91
+
# observed successes below.
92
+
N = y_t.N
68
93
69
94
# `Y_t` is the success probability; clamp away from 0/1 to avoid a degenerate
70
95
# likelihood, mirroring the count families' `Y_t .+ 1e-6` nudge.
71
96
p_t =clamp.(Y_t, 1.0e-6, 1-1.0e-6)
72
-
dist =_TrialDist(obs_model, p_t, N_t)
73
97
74
-
y = y_t.y
98
+
# The successes always arrive in a `NamedTuple` field, so they are never a
99
+
# model argument DynamicPPL copies: `_scored_series` detaches them from the
100
+
# caller's data before anything is scored.
101
+
y =_scored_series(obs_model, y_t, Y_t)
75
102
if y isa MissingObservations
76
103
diff_t =length(y.value) -length(Y_t)
104
+
dist =_trial_dist(obs_model, p_t, N, diff_t)
77
105
y_t, __varinfo__ =_score_missing_observations!!(
78
106
__model__.context, __varinfo__, y, diff_t, Y_t, dist
79
107
)
80
108
else
81
109
# Rebind `y_t` to the observed successes (the same name, so DynamicPPL
0 commit comments