poisson module#
Classes for defining Poisson point processes on bdms.Tree 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.Tree.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:
ABCAbstract base class for Poisson point processes on
bdms.Treeattributes.- abstractmethod λ(x, t)#
The Poisson intensity \(\lambda(x, t)\) for state \(x\) at time \(t\).
- abstractmethod Λ(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.
- abstractmethod Λ_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 intensity. If zero, the waiting time is infinite.seed (
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:
ProcessAbstract base class for homogenous Poisson processes.
- abstractmethod λ_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\).
- Λ(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, attr='state')#
Bases:
HomogeneousProcessA process with a specified constant rate (independent of state).
- Parameters:
- class bdms.poisson.DiscreteProcess(rates, attr='state')#
Bases:
HomogeneousProcessA homogeneous process at each of \(d\) states.
- Parameters:
- class bdms.poisson.InhomogeneousProcess(attr='state', quad_kwargs={}, root_kwargs={})#
Bases:
ProcessAbstract 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:
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().
- abstractmethod λ_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\).
- Λ(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\).