Skip to content

Serial interval from trajectory draws for shared-trajectory models - #1256

Merged
sbfnk merged 4 commits into
mainfrom
issue-1254-serial-interval-of-a-shared-trajectory-m
Nov 25, 2026
Merged

sbfnk merged 4 commits into
mainfrom
issue-1254-serial-interval-of-a-shared-trajectory-m

Conversation

@sbfnk-bot

Copy link
Copy Markdown
Collaborator

serial_interval(model, infector, infectee) now works for a model whose attributes record onset without an onset_law (a builder drawing a within-host trajectory), including a kernel that depends on the individual, such as a HazardKernel on the load. It returns a mixture over n_trajectories draws of the attributes (keywords n_trajectories = 200 and rng). Each draw contributes its kernel conditioned on a contact, shifted by minus its own onset, and weighted by the chance of a contact, so high-load draws count for more. The infectee's incubation period comes from an independent draw. Draws with no onset are left out, as in realised_serial_intervals. Models with clinical_presentation and a fixed generation time keep the existing convolution path.

An onset drawn in the builder alongside the trajectory is sampled jointly with it, one per draw. Interventions are not applied, and the offspring law must be a fixed distribution.

The new test compares the mixture's CDF with realised_serial_intervals from 4000 simulated outbreaks, for a HazardKernel on the load and for an exponential generation time with trajectory-driven onset, at five points (tolerance 0.025). Only test/test_serial_interval.jl was run.

Closes #1254. Builds on #1223.

This PR closes #1254.

sbfnk-bot and others added 3 commits November 25, 2026 11:49
…ory draws

Co-authored-by: sbfnk <sebastian.funk@lshtm.ac.uk>
Co-authored-by: sbfnk <sebastian.funk@lshtm.ac.uk>
Co-authored-by: sbfnk <sebastian.funk@lshtm.ac.uk>
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark comparison vs base

Minimum time per call. Buckets are PR time as a % of base, so lower is faster (🟢 faster, ⚪ within 5%, 🔴 slower). Counts of benchmarks per bucket:

Group 🟢 <50% 🟢 50–75% 🟢 75–95% ⚪ 95–105% 🔴 105–125% 🔴 125–150% 🔴 >150%
Evaluation · · · 16 3 · ·
Evaluation — 19 benchmarks (by time change)
Benchmark base PR time memory
simulation: homogeneous SI, max_time 20.23 ms 23.05 ms 🔴 1.14× ⚪ 1.0×
simulation: homogeneous 29.94 ms 32.39 ms 🔴 1.08× ⚪ 1.0×
simulation: homogeneous, susceptibility trait 37.19 ms 40.22 ms 🔴 1.08× ⚪ 1.0×
simulation: branching process 1.45 ms 1.5 ms ⚪ 1.04× ⚪ 1.0×
simulation: households 1.03 ms 1.06 ms ⚪ 1.03× ⚪ 1.0×
simulation: network, live kernel with policy 4.43 ms 4.52 ms ⚪ 1.02× ⚪ 1.0×
simulation: network, live kernel 4.04 ms 4.12 ms ⚪ 1.02× ⚪ 1.0×
evaluation: compile_contact_pairs 27.35 μs 27.83 μs ⚪ 1.02× ⚪ 1.0×
simulation: branching process, HeldCapacity with DeferRefused 1.35 s 1.37 s ⚪ 1.01× ⚪ 1.0×
simulation: branching process, interventions 16.6 μs 16.82 μs ⚪ 1.01× ⚪ 1.0×
evaluation: chain size loglikelihood 1.97 μs 1.96 μs ⚪ 0.99× —
evaluation: PoissonLognormal pdf, large count 37.97 μs 38.05 μs ⚪ 1.0× ⚪ 1.0×
evaluation: PoissonWeibull pdf 51.64 μs 51.73 μs ⚪ 1.0× ⚪ 1.0×
evaluation: pairwise_surv_loglik 24.26 μs 24.29 μs ⚪ 1.0× ⚪ 1.0×
simulation: network, shared kernel 172.41 μs 172.59 μs ⚪ 1.0× ⚪ 1.0×
evaluation: PoissonWeibull pdf, large count 50.72 μs 50.72 μs ⚪ 1.0× ⚪ 1.0×
evaluation: ChainSizes loglikelihood 460.0 ns 460.0 ns ⚪ 1.0× —
evaluation: PoissonLognormal pdf 36.79 μs 36.79 μs ⚪ 1.0× ⚪ 1.0×
evaluation: extinction_probability 891.0 ns 891.0 ns ⚪ 1.0× ⚪ 1.0×
AD gradients — 0 benchmarks (by time change)

none

@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.81%. Comparing base (9c65f39) to head (83e4dfb).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1256   +/-   ##
=======================================
  Coverage   97.81%   97.81%           
=======================================
  Files         104      104           
  Lines       11806    11833   +27     
=======================================
+ Hits        11548    11575   +27     
  Misses        258      258           
Flag Coverage Δ
epibranch-ad 29.41% <0.00%> (-0.08%) ⬇️
epibranch-analytical 40.51% <0.00%> (-0.11%) ⬇️
epibranch-engine 52.47% <0.00%> (-0.14%) ⬇️
epibranch-inference 44.29% <100.00%> (+0.64%) ⬆️
epibranch-interventions 53.99% <0.00%> (-0.14%) ⬇️
epibranch-population 53.84% <0.00%> (-0.14%) ⬇️
epihouseholds 96.94% <ø> (ø)
epinetwork 95.40% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Co-authored-by: sbfnk <sebastian.funk@lshtm.ac.uk>
@sbfnk-bot

Copy link
Copy Markdown
Collaborator Author

Merged origin/main. Main had added a note and error text saying serial_interval does not handle a shared-trajectory model, plus a test and changelog entry. This PR handles that case, so I kept its side and removed that text, the _SIMULATED_ROUTE suffix on the error, the test and the changelog entry. test/test_serial_interval.jl passes after the merge.

@sbfnk-bot
sbfnk-bot marked this pull request as ready for review November 25, 2026 13:09
@sbfnk-bot
sbfnk-bot requested a review from sbfnk as a code owner November 25, 2026 13:09
@sbfnk
sbfnk merged commit e2f2749 into main Nov 25, 2026
29 checks passed
@sbfnk
sbfnk deleted the issue-1254-serial-interval-of-a-shared-trajectory-m branch November 25, 2026 13:24
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.

Serial interval of a shared-trajectory model from trajectory draws

2 participants