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: SequenceEncodableProbabilityDistribution

General linear birth-death-sampling process (fossilized birth-death is the sampling_rate>0 case).

Parameters:
density(x)[source]

Probability density of one trajectory (see log_density).

Parameters:

x (Any)

Return type:

float

log_density(x)[source]

Log-likelihood of one fully-observed trajectory (n0, T, events).

Parameters:

x (Any)

Return type:

float

seq_log_density(x)[source]

Vectorized log-likelihood for an (N, 5) array of per-trajectory sufficient statistics.

Parameters:

x (ndarray)

Return type:

ndarray

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: DistributionSampler

Exact Gillespie simulation of birth-death-sampling trajectories on [0, horizon].

Parameters:
  • dist (BirthDeathSamplingDistribution)

  • seed (int | None)

sample(size=None)[source]

Draw one trajectory (n0, T, events) or a list of size trajectories.

Parameters:

size (int | None)

Return type:

Any

class BirthDeathSamplingAccumulator(name=None, keys=None)[source]

Bases: SequenceEncodableStatisticAccumulator

Accumulate weighted event counts, the time-integral of the population, and trajectory count.

Parameters:
  • name (str | None)

  • keys (str | None)

update(x, weight, estimate)[source]
Parameters:
  • x (Any)

  • weight (float)

  • estimate (BirthDeathSamplingDistribution | None)

Return type:

None

initialize(x, weight, rng)[source]
Parameters:
Return type:

None

seq_update(x, weights, estimate)[source]
Parameters:
Return type:

None

seq_initialize(x, weights, rng)[source]
Parameters:
Return type:

None

combine(suff_stat)[source]
Parameters:

suff_stat (tuple[float, float, float, float, float, float])

Return type:

BirthDeathSamplingAccumulator

value()[source]
Return type:

tuple[float, float, float, float, float, float]

from_value(x)[source]
Parameters:

x (tuple[float, float, float, float, float, float])

Return type:

BirthDeathSamplingAccumulator

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_dict under its merge key.

The structural default implements the common single-key pattern: store the accumulator under self.keys the first time the key is seen, else combine into 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. A keys of None (the default) is a no-op.

Parameters:

stats_dict (dict[str, Any])

Return type:

None

key_replace(stats_dict)[source]

Replace this accumulator’s statistics from the pooled stats_dict entry (see key_merge).

Parameters:

stats_dict (dict[str, Any])

Return type:

None

acc_to_encoder()[source]
Return type:

BirthDeathSamplingDataEncoder

class BirthDeathSamplingAccumulatorFactory(name=None, keys=None)[source]

Bases: StatisticAccumulatorFactory

Factory for BirthDeathSamplingAccumulator.

Parameters:
  • name (str | None)

  • keys (str | None)

make()[source]
Return type:

BirthDeathSamplingAccumulator

class BirthDeathSamplingEstimator(name=None, keys=None)[source]

Bases: ParameterEstimator

Closed-form rate MLE: rate = (total events of that type) / integral_n.

Parameters:
  • name (str | None)

  • keys (str | None)

accumulator_factory()[source]
Return type:

BirthDeathSamplingAccumulatorFactory

estimate(nobs, suff_stat)[source]

Estimate per-capita rates from accumulated event counts and population time-integral.

Parameters:
Return type:

BirthDeathSamplingDistribution

class BirthDeathSamplingDataEncoder[source]

Bases: DataSequenceEncoder

Encode trajectories (n0, T, events) into an (N, 6) array of sufficient statistics + T.

seq_encode(x)[source]

Encode the iid observation sequence x for vectorized evaluation.

Parameters:

x (Sequence[Any])

Return type:

ndarray