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]
Return the encoder for birth-death samples.
- 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]
Accumulate weighted event counts and exposure for one trajectory.
- initialize(x, weight, rng)[source]
Initialize the sufficient statistics with one weighted trajectory.
- Parameters:
x (Any)
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
Accumulate weighted event counts and exposure from encoded trajectories.
- seq_initialize(x, weights, rng)[source]
Initialize the sufficient statistics from encoded trajectories.
- Parameters:
x (ndarray)
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- combine(suff_stat)[source]
Merge serialized birth-death-sampling statistics into this accumulator.
- value()[source]
Return event counts, exposure, trajectory count, and horizon total.
- from_value(x)[source]
Restore the accumulator from serialized birth-death-sampling statistics.
- scale(c)[source]
Scale accumulated sufficient statistics by a constant.
- Parameters:
c (float)
- Return type:
BirthDeathSamplingAccumulator
- key_merge(stats_dict)[source]
Merge this accumulator into a keyed statistics dictionary.
- key_replace(stats_dict)[source]
Replace this accumulator from a keyed statistics dictionary.
- acc_to_encoder()[source]
Return an encoder for trajectory sufficient statistics.
- Return type:
BirthDeathSamplingDataEncoder
- class BirthDeathSamplingAccumulatorFactory(name=None, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for BirthDeathSamplingAccumulator.
- make()[source]
Create an empty birth-death-sampling accumulator.
- Return type:
BirthDeathSamplingAccumulator
- class BirthDeathSamplingEstimator(name=None, keys=None)[source]
Bases:
ParameterEstimatorClosed-form rate MLE:
rate = (total events of that type) / integral_n.- accumulator_factory()[source]
Return a factory for birth-death-sampling sufficient-statistic accumulators.
- Return type:
BirthDeathSamplingAccumulatorFactory