mixle.stats.processes.birth_death module¶
Evaluate, estimate, and sample from a general birth-death-sampling process.
Defines BirthDeathSamplingDistribution, BirthDeathSamplingSampler, BirthDeathSamplingAccumulatorFactory, BirthDeathSamplingAccumulator, BirthDeathSamplingEstimator, and BirthDeathSamplingDataEncoder.
A continuous-time linear birth-death process on a population n(t): each individual independently
gives birth at rate birth_rate, dies at rate death_rate, and is sampled (observed through
time, without removal) at rate sampling_rate. This is a general population/epidemic model; the
fossilized birth-death model is the special case where sampling_rate is the fossilization
rate. Pure birth-death is sampling_rate = 0.
Data type: one fully-observed trajectory (n0, T, events) – initial count n0, observation
window length T, and a time-ordered list of (time, type) events with type in
{0: birth, 1: death, 2: sampling}. The log-likelihood is
sum_events log n_i + n_b log(birth) + n_d log(death) + n_s log(sampling) - (birth+death+sampling) * I,
where n_i is the population just before event i and I = integral_0^T n(t) dt (n is
piecewise constant between events). The MLE is closed-form: each rate is its event count divided by
I (summed over trajectories).
Reference: Feller, An Introduction to Probability Theory and Its Applications, Vol. 1 (Wiley).
- class BirthDeathSamplingDistribution(birth_rate, death_rate, sampling_rate=0.0, initial_population=1, horizon=10.0, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionGeneral linear birth-death-sampling process (fossilized birth-death is the
sampling_rate>0case).- Parameters:
- density(x)[source]
Probability density of one trajectory (see
log_density).
- log_density(x)[source]
Log-likelihood of one fully-observed trajectory
(n0, T, events).
- seq_log_density(x)[source]
Vectorized log-likelihood for an
(N, 5)array of per-trajectory sufficient statistics.
- sampler(seed=None)[source]
Return a BirthDeathSamplingSampler for this distribution.
- Parameters:
seed (int | None)
- Return type:
BirthDeathSamplingSampler
- estimator(pseudo_count=None)[source]
Return a BirthDeathSamplingEstimator (closed-form rate MLE).
- Parameters:
pseudo_count (float | None)
- Return type:
BirthDeathSamplingEstimator
- dist_to_encoder()[source]
Returns a BirthDeathSamplingDataEncoder object.
- Return type:
BirthDeathSamplingDataEncoder
- class BirthDeathSamplingSampler(dist, seed=None)[source]
Bases:
DistributionSamplerExact Gillespie simulation of birth-death-sampling trajectories on
[0, horizon].- Parameters:
dist (BirthDeathSamplingDistribution)
seed (int | None)
- class BirthDeathSamplingAccumulator(name=None, keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulate weighted event counts, the time-integral of the population, and trajectory count.
- update(x, weight, estimate)[source]
- initialize(x, weight, rng)[source]
- Parameters:
x (Any)
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
- seq_initialize(x, weights, rng)[source]
- Parameters:
x (ndarray)
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- combine(suff_stat)[source]
- from_value(x)[source]
- scale(c)[source]
Scale linear sufficient statistics in-place by
c.The structural default is correct for ordinary weighted sums, nested tuples/lists/dicts, and numeric arrays. Families whose
value()payload includes non-linear metadata such as support bounds must override this method and leave that metadata unscaled.- Parameters:
c (float)
- Return type:
BirthDeathSamplingAccumulator
- key_merge(stats_dict)[source]
Pool this accumulator’s statistics into
stats_dictunder its merge key.The structural default implements the common single-key pattern: store the accumulator under
self.keysthe first time the key is seen, elsecombineinto the one already there. Accumulators with several named keys (e.g. an HMM’s init/trans/state keys) or a non-accumulator stats payload override this. AkeysofNone(the default) is a no-op.
- key_replace(stats_dict)[source]
Replace this accumulator’s statistics from the pooled
stats_dictentry (see key_merge).
- acc_to_encoder()[source]
- Return type:
BirthDeathSamplingDataEncoder
- class BirthDeathSamplingAccumulatorFactory(name=None, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for BirthDeathSamplingAccumulator.
- make()[source]
- Return type:
BirthDeathSamplingAccumulator