mixle.stats.processes.ctmc module¶
Continuous-time Markov chain (CTMC) over fully observed trajectories.
A CTMC on K states is governed by a generator matrix Q: off-diagonal q_ij >= 0 is the rate
of jumping i -> j, and q_ii = -sum_{j!=i} q_ij. A fully-observed trajectory is the initial state
plus the sequence of (dwell_time, next_state) jumps; its log-likelihood is
log L = sum_{i!=j} n_ij * log q_ij - sum_i q_i * T_i, q_i = -q_ii = sum_{j!=i} q_ij,
where n_ij is the number of observed i->j transitions and T_i the total time spent in i.
This is a collection of independent Poisson-rate likelihoods, so the MLE is closed form and
unique: q_ij = n_ij / T_i. The estimator therefore certifies GLOBAL_UNIQUE (see
mixle.inference.certify(), which classifies this family). Data type: (s0, [(dt, s1), (dt, s2),
...]) – the initial state and the observed jumps.
The family follows the standard Mixle distribution contract (Distribution / Sampler / Accumulator / Factory /
Estimator / DataEncoder) so it composes with optimize / seq_log_density / the PPL surface like
every other family.
- class ContinuousTimeMarkovChainDistribution(rates, initial_state=0, horizon=10.0, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionCTMC on
Kstates with generatorQ(off-diagonal rates); MLE is closed form (GLOBAL_UNIQUE).- Parameters:
- property generator: ndarray
The generator matrix
Q(off-diagonal rates, diagonal = -exit rate).
- density(x)[source]
Return the probability density of one fully observed trajectory.
- log_density(x)[source]
Return the log-likelihood of one fully observed CTMC trajectory.
- seq_log_density(x)[source]
Return vectorized log-likelihoods for encoded trajectory statistics.
- sampler(seed=None)[source]
Return a Gillespie sampler for trajectories from this CTMC.
- Parameters:
seed (int | None)
- Return type:
ContinuousTimeMarkovChainSampler
- estimator(pseudo_count=None)[source]
Return the closed-form rate estimator for this state space.
- Parameters:
pseudo_count (float | None)
- Return type:
ContinuousTimeMarkovChainEstimator
- dist_to_encoder()[source]
Return the trajectory-statistics encoder used by vectorized methods.
- Return type:
ContinuousTimeMarkovChainDataEncoder
- class ContinuousTimeMarkovChainSampler(dist, seed=None)[source]
Bases:
DistributionSamplerExact Gillespie simulation of CTMC trajectories on
[0, horizon].- Parameters:
dist (ContinuousTimeMarkovChainDistribution)
seed (int | None)
- class ContinuousTimeMarkovChainAccumulator(num_states, name=None, keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulate the CTMC sufficient statistics: transition counts
n_ijand dwell timesT_i.- update(x, weight, estimate)[source]
Update transition-count and dwell-time statistics from one trajectory.
- initialize(x, weight, rng)[source]
Initialize sufficient statistics from one trajectory.
- Parameters:
x (Any)
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
Update sufficient statistics from encoded trajectory statistics.
- seq_initialize(x, weights, rng)[source]
Initialize sufficient statistics from encoded trajectory statistics.
- Parameters:
x (Any)
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- combine(suff_stat)[source]
Merge transition-count and dwell-time sufficient statistics.
- value()[source]
Return copies of transition counts and dwell times.
- from_value(x)[source]
Restore transition-count and dwell-time sufficient statistics.
- scale(c)[source]
Scale accumulated sufficient statistics by a constant.
- Parameters:
c (float)
- Return type:
ContinuousTimeMarkovChainAccumulator
- key_merge(stats_dict)[source]
Merge keyed transition and dwell statistics into this accumulator.
- key_replace(stats_dict)[source]
Replace this accumulator’s state from keyed statistics when present.
- acc_to_encoder()[source]
Return the encoder compatible with CTMC sufficient statistics.
- Return type:
ContinuousTimeMarkovChainDataEncoder
- class ContinuousTimeMarkovChainAccumulatorFactory(num_states, name=None, keys=None)[source]
Bases:
StatisticAccumulatorFactoryCreate accumulators for CTMC transition-count and dwell-time statistics.
- make()[source]
Create an empty CTMC accumulator.
- Return type:
ContinuousTimeMarkovChainAccumulator
- class ContinuousTimeMarkovChainEstimator(num_states, pseudo_count=None, name=None, keys=None)[source]
Bases:
ParameterEstimatorClosed-form rate MLE:
q_ij = n_ij / T_i(independent Poisson rates, unique global optimum).- accumulator_factory()[source]
Return a factory for CTMC sufficient-statistic accumulators.
- Return type:
ContinuousTimeMarkovChainAccumulatorFactory