poisson
module#
Classes for defining Poisson point processes on bdms.TreeNode
state
spaces. Several abstract base classes concrete child classes are included.
These classes are used to define rate-driven processes—such as birth, death, and
mutation—for simulations with bdms.TreeNode.evolve
.
Example
>>> import bdms
Define a two-state process.
>>> poisson_process = bdms.poisson.DiscreteProcess({"a": 1.0, "b": 2.0})
Sample waiting times for each state.
>>> for state in poisson_process.rates:
... print(state, poisson_process.waiting_time_rv(state, 0.0, seed=0))
a 0.6799...
b 0.3399...
- class bdms.poisson.Process(attr='state')#
Bases:
ABC
Abstract base class for Poisson point processes on
bdms.TreeNode
attributes.- Parameters:
attr (
str
) – The name of thebdms.TreeNode
attribute to access.
- abstract λ(x, t)#
The Poisson intensity \(\lambda(x, t)\) for state \(x\) at time \(t\).
- Parameters:
- Return type:
- Returns:
The Poisson intensity \(\lambda(x, t)\).
- abstract Λ(x, t, Δt)#
Evaluate the Poisson intensity measure of state \(x\) and time interval \([t, t+Δt)\), defined as.
\[\Lambda(x, t, Δt) = \int_{t}^{t+Δt} \lambda(x, s)ds,\]This is needed for sampling waiting times and evaluating the log probability density function of waiting times.
- abstract Λ_inv(x, t, τ)#
Evaluate the inverse function wrt \(\Delta t\) of
Process.Λ()
, \(\Lambda_t^{-1}(x, t, \tau)\), such that \(\Lambda_t^{-1}(x, t, \Lambda(x, t, t+\Delta t)) = \Delta t\). This is needed for sampling waiting times. Note that \(\Lambda_t^{-1}\) is well-defined iff \(\lambda(x, t) > 0\).
- waiting_time_rv(x, t, rate_multiplier=1.0, seed=None)#
Sample the waiting time \(\Delta t\) until the first event, given the process on state \(x\) starting at time \(t\).
- Parameters:
x (
Hashable
) – State.t (
float
) – Time at which to start waiting.rate_multiplier (
float
) – A constant by which to multiply the Poisson intensityseed (
int
|Generator
|None
) – A seed to initialize the random number generation. IfNone
, then fresh, unpredictable entropy will be pulled from the OS. If anint
, then it will be used to derive the initial state. If anumpy.random.Generator
, then it will be used directly.
- Return type:
- Returns:
Waiting time \(\Delta t\).
- class bdms.poisson.HomogeneousProcess(attr='state')#
Bases:
Process
Abstract base class for homogenous Poisson processes.
- abstract λ_homogeneous(x)#
Evaluate homogeneous Poisson intensity \(\lambda(x)\) for state \(x\).
- λ(x, t)#
The Poisson intensity \(\lambda(x, t)\) for state \(x\) at time \(t\).
- Parameters:
- Return type:
- Returns:
The Poisson intensity \(\lambda(x, t)\).
- Λ(x, t, Δt)#
Evaluate the Poisson intensity measure of state \(x\) and time interval \([t, t+Δt)\), defined as.
\[\Lambda(x, t, Δt) = \int_{t}^{t+Δt} \lambda(x, s)ds,\]This is needed for sampling waiting times and evaluating the log probability density function of waiting times.
- Λ_inv(x, t, τ)#
Evaluate the inverse function wrt \(\Delta t\) of
Process.Λ()
, \(\Lambda_t^{-1}(x, t, \tau)\), such that \(\Lambda_t^{-1}(x, t, \Lambda(x, t, t+\Delta t)) = \Delta t\). This is needed for sampling waiting times. Note that \(\Lambda_t^{-1}\) is well-defined iff \(\lambda(x, t) > 0\).
- class bdms.poisson.ConstantProcess(value=1.0)#
Bases:
HomogeneousProcess
A process with a specified constant rate (independent of state).
- Parameters:
value (
float
) – Constant rate.
- λ_homogeneous(x)#
Evaluate homogeneous Poisson intensity \(\lambda(x)\) for state \(x\).
- class bdms.poisson.DiscreteProcess(rates, attr='state')#
Bases:
HomogeneousProcess
A homogeneous process at each of \(d\) states.
- Parameters:
- λ_homogeneous(x)#
Evaluate homogeneous Poisson intensity \(\lambda(x)\) for state \(x\).
- class bdms.poisson.InhomogeneousProcess(attr='state', quad_kwargs={}, root_kwargs={})#
Bases:
Process
Abstract base class for homogenous Poisson processes.
Default implementations of
Λ()
andΛ_inv()
use quadrature and root-finding, respectively. You may wish to override these methods in a child clasee for better performance, if analytical forms are available.- Parameters:
attr (
str
) – The name of thebdms.TreeNode
attribute to access.quad_kwargs (
dict
[str
,Any
]) – Quadrature convergence arguments passed toscipy.integrate.quad()
.root_kwargs (
dict
[str
,Any
]) – Root-finding convergence arguments passed toscipy.optimize.root_scalar()
.
- abstract λ_inhomogeneous(x, t)#
Evaluate inhomogeneous Poisson intensity \(\lambda(x, t)\) given state \(x\).
- λ(x, t)#
The Poisson intensity \(\lambda(x, t)\) for state \(x\) at time \(t\).
- Parameters:
- Return type:
- Returns:
The Poisson intensity \(\lambda(x, t)\).
- Λ(x, t, Δt)#
Evaluate the Poisson intensity measure of state \(x\) and time interval \([t, t+Δt)\), defined as.
\[\Lambda(x, t, Δt) = \int_{t}^{t+Δt} \lambda(x, s)ds,\]This is needed for sampling waiting times and evaluating the log probability density function of waiting times.
- Λ_inv(x, t, τ)#
Evaluate the inverse function wrt \(\Delta t\) of
Process.Λ()
, \(\Lambda_t^{-1}(x, t, \tau)\), such that \(\Lambda_t^{-1}(x, t, \Lambda(x, t, t+\Delta t)) = \Delta t\). This is needed for sampling waiting times. Note that \(\Lambda_t^{-1}\) is well-defined iff \(\lambda(x, t) > 0\).