Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
628dcce
Select strata of a state, a coupling per batch and a kernel shared by…
claude Dec 1, 2026
fa57c33
State the chunked-run contract, test it over the scenario registry an…
claude Dec 1, 2026
93c9625
Load a resumed history a stratum at a time and test the stepwise piec…
claude Dec 1, 2026
c61d2d9
Keep the new docs within the wording, sentence and code length standards
claude Dec 1, 2026
e13229c
Round the tutorial's summary
claude Dec 1, 2026
349f96e
Word the history-load comment in the present
claude Dec 1, 2026
adcd789
Merge main into the stepwise branch
claude Dec 1, 2026
b12de6e
Rewrite the particle filter page from generic functions and share sel…
claude Dec 1, 2026
e1809cc
Merge main into the stepwise branch
claude Dec 2, 2026
95ec588
Run reversed scenarios unchunked in the chunked-run test
claude Dec 2, 2026
2b32b51
Zero only the buffer rows a history leaves unloaded, and load a histo…
claude Dec 2, 2026
8550755
Keep a state's outputs in the buffer of the run that wrote them
claude Dec 2, 2026
7a91254
A state as one vector: vec(state), State(like, x; t) and length(state)
claude Dec 2, 2026
d78b0fa
history = PerStratum(x): one value before the start for each stratum
claude Dec 2, 2026
9eaa7b5
Benchmark a run a step at a time: the resumed_steps case and stepwise…
claude Dec 2, 2026
73365af
Proposal: advance!(r, state, gain) steps a state in its own buffer
claude Dec 2, 2026
7ceba22
Read and return a state on a buffer held strata × time without a gene…
claude Dec 2, 2026
ac39cbd
Particle filtering page: LowLevelParticleFilters.jl does the filterin…
claude Dec 2, 2026
22ec9a7
Test the bootstrap filter with particles as strata on the host and on…
claude Dec 2, 2026
5813fe6
Merge main into the cheap resumed step branch
claude Dec 2, 2026
b2424e1
Batch axis before time, a shared kernel's cotangent on the device, sh…
claude Dec 2, 2026
4cc23ea
advance!: the run it returns as a formula
claude Dec 2, 2026
920359d
vec(state) and State(like, x) behind their own functions
claude Dec 2, 2026
37fc903
Merge main into the cheap resumed step branch
claude Dec 3, 2026
80dc12e
Name the owned field in the State docstring
claude Dec 3, 2026
c739061
The rule returns the state the plain run returns, and takes its buffe…
claude Dec 3, 2026
618e5b7
Fold the particle filtering page of #1016 into this branch
claude Dec 3, 2026
f5a14f9
Merge main into the cheap resumed step branch
seabbs-bot Dec 3, 2026
465efd8
Say what reusing a state after advance! does, and test the strata × t…
seabbs-bot Dec 3, 2026
2d28edb
A cached run's state on floats has the plain run's type
seabbs-bot Dec 4, 2026
11e9b2f
Restore the Gordon1993 and Andrieu2010 entries the page fold dropped
seabbs-bot Dec 4, 2026
aa69aca
Leave the PerStratum history scenarios out where a release lacks them
seabbs-bot Dec 4, 2026
dcd406b
Traced buffer and zeros methods on a state's buffer rows
seabbs-bot Dec 4, 2026
1c6f490
Merge main into the cheap resumed step branch
seabbs-bot Dec 4, 2026
e2de184
One traced zeros method per host type, so neither is ambiguous
seabbs-bot Dec 4, 2026
52fbf9a
Name vec in the particle filtering page without a cross-reference
seabbs-bot Dec 4, 2026
3db88e7
Pass every run keyword through the Reactant extension's traced run
seabbs-bot Dec 4, 2026
b7b8701
Reactant rows for the PerStratum history scenarios
seabbs-bot Dec 4, 2026
2ef35b4
The PerStratum history scenarios' rows in the Reactant results page
seabbs-bot Dec 4, 2026
f482c6d
Merge main into the cheap resumed step branch
seabbs-bot Dec 4, 2026
5f7742a
State(like, x) keeps the strata of a history with no outputs
seabbs-bot Dec 4, 2026
76ef073
Merge main into the cheap resumed step branch
seabbs-bot Dec 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
LogExpFunctions = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
LowLevelParticleFilters = "d9d29d28-c116-5dba-9239-57a5fe23875b"
Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[sources]
Expand Down Expand Up @@ -56,7 +58,9 @@ JSON = "0.21, 1"
KernelAbstractions = "0.9.34, 0.10"
Literate = "2"
LogExpFunctions = "0.3, 1"
LowLevelParticleFilters = "3.40"
Mooncake = "0.5.70"
Plots = "1"
SpecialFunctions = "2"
StaticArrays = "1"
Statistics = "1"
5 changes: 5 additions & 0 deletions docs/docs_config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const HEAVY_TUTORIALS = [
"delays-and-reporting/clinical-outcomes.jl",
"forecasting-and-fitting/forecasting.jl",
"forecasting-and-fitting/conjugate-reproduction-number.jl",
"forecasting-and-fitting/particle-filter.jl",
"transmission/reproduction-number.jl",
"transmission/latent-processes.jl",
"populations-and-places/spatial-strata.jl",
Expand Down Expand Up @@ -54,6 +55,8 @@ const TUTORIAL_STUBS = [
"# [Forecasting by continuing a run from its state](@id tutorial-forecasting)",
"forecasting-and-fitting/conjugate-reproduction-number.md" =>
"# [Conjugate gamma–Poisson estimation of the instantaneous reproduction number](@id tutorial-conjugate-rt)",
"forecasting-and-fitting/particle-filter.md" =>
"# [Particle filtering of a renewal model with LowLevelParticleFilters.jl](@id tutorial-particle-filter)",
"transmission/reproduction-number.md" =>
"# [The instantaneous and effective reproduction numbers from a run](@id tutorial-reproduction-number)",
"transmission/latent-processes.md" =>
Expand Down Expand Up @@ -284,6 +287,8 @@ const TUTORIALS = Pair{String, Any}[
"Forecasting" => "forecasting-and-fitting/forecasting.md",
"Conjugate estimation of the reproduction number" =>
"forecasting-and-fitting/conjugate-reproduction-number.md",
"Particle filtering" =>
"forecasting-and-fitting/particle-filter.md",
],
]

Expand Down
1 change: 1 addition & 0 deletions docs/pages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pages = [
"Forecasting and fitting" => [
"Forecasting" => "tutorials/forecasting-and-fitting/forecasting.md",
"Conjugate estimation of the reproduction number" => "tutorials/forecasting-and-fitting/conjugate-reproduction-number.md",
"Particle filtering" => "tutorials/forecasting-and-fitting/particle-filter.md",
],
],
"How-to guides" => [
Expand Down
37 changes: 37 additions & 0 deletions docs/src/explanation/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ A recurrence `renewal` takes its gain first, and a convolution `delay` takes its
| [`renewal(gain; history, add, start, stop)`](@ref Recurrence) | the run, a vector or strata × time |
| [`delay(x; gain, add, history, start, stop)`](@ref Convolution) | an array shaped like `x` |
| [`renewal(gain; history, record = (Resume(), Pressure(), Trace()))`](@ref Recurrence) | `(; y, state, pressure, trace)`, with the `State` to [resume from](@ref explanation-history-state) |
| [`ComposableRecurrences.advance!(renewal, state, gain; add, stop, record)`](@ref ComposableRecurrences.advance!) | `(; y, state)` as `renewal(gain; state, record = Resume())` returns, run in the buffer of `state`, which it uses up |
| [`ComposableRecurrences.contributions(delay, x; ...)`](@ref ComposableRecurrences.contributions) | each lag's term before the sum, with a column per output time |
| [`ComposableRecurrences.contributions(delay, x; indexing = Primary(), ...)`](@ref ComposableRecurrences.contributions) | the same terms with a column per input time, zero where they arrive after `stop` |
| [`ComposableRecurrences.contributions(K; start, stop)`](@ref ComposableRecurrences.contributions) | the entries of a table `K` held by input time, cut at `stop` as those terms are |
Expand Down Expand Up @@ -164,6 +165,7 @@ Without a history the run starts from zeros.
Their strata are those of a strata × time input, or else those of one group of the first modifier whose groups hold more than one value.
A `Depletion` whose flows move between named pools is such a modifier.
For a single stratum a number is one value before `start`, so `history = 1.0` is `history = [1.0]`.
A vector is the values of one series, so one value before `start` for each of ``S`` strata is `history = PerStratum(x)`, which is `history = reshape(x, S, 1)`.
A modifier's `Init` reads the whole history, so a modifier can set its starting state from more than ``L`` values.

A [`State`](@ref ComposableRecurrences.State) holds everything the next step reads: the last ``L`` outputs, the state of each modifier and the next time.
Expand Down Expand Up @@ -218,6 +220,41 @@ rest = r_kept(R[kept, :]; state = select(first_part.state, kept))
rest ≈ r(R; state = first_part.state)[kept, :]
```

A method that keeps its own state vector, such as a filter from another package, reads a `State` as one vector and builds one back.
The vector [`vec(state)`](@ref Base.vec(::ComposableRecurrences.State)) holds each stratum's outputs, oldest first, then each modifier's state.
The call [`State(like, x; t)`](@ref ComposableRecurrences.State(::ComposableRecurrences.State, ::AbstractVector)) returns the state of that shape whose next step is at time `t`.
Time is absolute in every call and the vector holds none, so the method passes it.

```@example operators
state = first_part.state
x = vec(state)
again = ComposableRecurrences.State(state, x; t = state.t)
length(state), vec(again) == x
```

A resumed call leaves the state it is given as it was: it copies the state's outputs into a new buffer, runs there and returns a new state.
The call [`advance!(r, state, gain)`](@ref ComposableRecurrences.advance!) runs the same steps in the buffer the state already has and returns the same outputs and state.
A loop of single steps then copies no history.
The state passed is used up, and the loop carries on from the one returned.

```@example operators
using ComposableRecurrences: advance!
function stepwise(r, R, state, n)
y = zeros(size(R, 1), n)
for t in 1:n
out = advance!(r, state, R)
y[:, t] = out.y
state = out.state
end
return y, state
end
start = r(R; history = ones(3, 3), stop = 0, record = Resume()).state
y, last_state = stepwise(r, R, start, 20)
y ≈ r(R; history = ones(3, 3))
```

[Particle filtering of a renewal model with LowLevelParticleFilters.jl](@ref tutorial-particle-filter) runs a particle filter on a recurrence, a particle at a time and with the particles as strata.

## [Seeding](@id explanation-seeding)

A recurrence needs values before its first step, in one of two places.
Expand Down
6 changes: 3 additions & 3 deletions docs/src/explanation/shapes-and-couplings.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ A coupling and a shared parameter make the copies one model.
It is one matrix product on the strata reshaped to ``S \times B``.
- A `Gather` stores a parameter once whether it differs by stratum, by batch or by neither.

A call whose `history` is ``S \times h \times B`` runs the batches as strata and returns ``S \times T \times B``:
A call whose `history` is ``S \times B \times h`` runs the batches as strata and returns ``S \times B \times T``, with time last as in every time-indexed input:

```@example shapes
using ComposableRecurrences: Batched
Expand All @@ -189,11 +189,11 @@ population = Gather(PerStratum([500.0, 200.0]), repeat(1:2, 3))
batched = Recurrence(
[0.5, 0.3]; coupling = Batched(K), modifiers = (Depletion(population),)
)
h = ones(2, 2, 3) .* reshape([1.0, 2.0, 4.0], 1, 1, 3)
h = ones(2, 3, 2) .* [1.0 2.0 4.0]
size(batched(1.4; history = h, stop = 5))
```

A [resumed call](@ref explanation-history-state) works on the ``B S`` strata, and `select` with `each = S` selects whole batches.
A [resumed call](@ref explanation-history-state) takes inputs in either layout and returns its state on the ``B S`` strata, and `select` with `each = S` selects whole batches.

## [Nesting](@id explanation-nesting)

Expand Down
44 changes: 44 additions & 0 deletions docs/src/refs.bib
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,47 @@ @article{LloydSmith2005
pages = {355--359},
doi = {10.1038/nature04153}
}

@article{Liu1998,
author = {Liu, Jun S. and Chen, Rong},
title = {Sequential {Monte Carlo} methods for dynamic systems},
journal = {Journal of the American Statistical Association},
year = {1998},
volume = {93},
number = {443},
pages = {1032--1044},
doi = {10.1080/01621459.1998.10473765}
}

@article{Carpenter1999,
author = {Carpenter, J. and Clifford, P. and Fearnhead, P.},
title = {Improved particle filter for nonlinear problems},
journal = {IEE Proceedings - Radar, Sonar and Navigation},
year = {1999},
volume = {146},
number = {1},
pages = {2--7},
doi = {10.1049/ip-rsn:19990255}
}

@article{Gordon1993,
author = {Gordon, N. J. and Salmond, D. J. and Smith, A. F. M.},
title = {Novel approach to nonlinear/non-{Gaussian} {Bayesian} state estimation},
journal = {IEE Proceedings F (Radar and Signal Processing)},
year = {1993},
volume = {140},
number = {2},
pages = {107--113},
doi = {10.1049/ip-f-2.1993.0015}
}

@article{Andrieu2010,
author = {Andrieu, Christophe and Doucet, Arnaud and Holenstein, Roman},
title = {Particle {Markov} chain {Monte Carlo} methods},
journal = {Journal of the Royal Statistical Society: Series B (Statistical Methodology)},
year = {2010},
volume = {72},
number = {3},
pages = {269--342},
doi = {10.1111/j.1467-9868.2009.00736.x}
}
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ round(maximum(abs, std(case_draws; dims = 2) .- case_sd); digits = 4)
# - A prior that links the ``R_w`` of different windows, such as a random walk on ``\log R_t``: the joint prior is not a product of gamma densities.
# - An unknown generation interval.
#
# The page *A particle filter and SMC² for a renewal model* estimates a model with the first, third and fourth of these.
# [Particle filtering of a renewal model with LowLevelParticleFilters.jl](@ref tutorial-particle-filter) estimates a model with the first and third of these.
#
# ## [Count distributions other than the Poisson](@id conjugate-beyond-poisson)
#
Expand Down
Loading
Loading