bdms.poisson
#
Abstract base classes for defining general Poisson point processes on
bdms.TreeNode
state spaces. Several 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...
Module Contents#
Classes#
Abstract base class for Poisson point processes on |
|
Abstract base class for homogenous Poisson processes. |
|
A process with a specified constant rate (independent of state). |
|
A homogeneous process at each of \(d\) states. |
|
Abstract base class for homogenous Poisson processes. |
- class bdms.poisson.Process(attr='state')#
Bases:
abc.ABC
Abstract base class for Poisson point processes on
bdms.TreeNode
attributes.- Parameters:
attr (str) – The name of the
bdms.TreeNode
attribute to access.
- abstract λ(x, t)#
The Poisson intensity \(\lambda(x, t)\) for state \(x\) at time \(t\).
- Parameters:
x (Hashable) – State to evaluate Poisson intensity at.
t (float) – Time to evaluate Poisson intensity at (
0.0
corresponds to the root). This only has an effect if the process is time-inhomogeneous.
- Returns:
The Poisson intensity \(\lambda(x, t)\).
- Return type:
numpy.typing.NDArray[numpy.float64]
- 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 intensity
seed (int | Generator | None) – A seed to initialize the random number generation. If
None
, 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.
- Returns:
Waiting time \(\Delta t\).
- Return type:
numpy.typing.NDArray[numpy.float64]
- class bdms.poisson.HomogeneousProcess(attr='state')#
Bases:
Process
Abstract base class for homogenous Poisson processes.
- Parameters:
attr (str) –
- abstract λ_homogeneous(x)#
Evaluate homogeneous Poisson intensity \(\lambda(x)\) for state \(x\).
- Parameters:
x (Hashable | Sequence[Hashable] | numpy.typing.NDArray[Any]) – State to evaluate Poisson intensity at.
- Returns:
The Poisson intensity \(\lambda(x)\).
- Return type:
numpy.typing.NDArray[numpy.float64]
- λ(x, t)#
The Poisson intensity \(\lambda(x, t)\) for state \(x\) at time \(t\).
- Parameters:
x (Hashable) – State to evaluate Poisson intensity at.
t (float) – Time to evaluate Poisson intensity at (
0.0
corresponds to the root). This only has an effect if the process is time-inhomogeneous.
- Returns:
The Poisson intensity \(\lambda(x, t)\).
- Return type:
numpy.typing.NDArray[numpy.float64]
- Λ(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\).
- 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
seed (int | Generator | None) – A seed to initialize the random number generation. If
None
, 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.
- Returns:
Waiting time \(\Delta t\).
- Return type:
numpy.typing.NDArray[numpy.float64]
- 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\).
- Parameters:
x (Hashable | Sequence[Hashable] | numpy.typing.NDArray[Any]) – State to evaluate Poisson intensity at.
- Returns:
The Poisson intensity \(\lambda(x)\).
- Return type:
numpy.typing.NDArray[numpy.float64]
- λ(x, t)#
The Poisson intensity \(\lambda(x, t)\) for state \(x\) at time \(t\).
- Parameters:
x (Hashable) – State to evaluate Poisson intensity at.
t (float) – Time to evaluate Poisson intensity at (
0.0
corresponds to the root). This only has an effect if the process is time-inhomogeneous.
- Returns:
The Poisson intensity \(\lambda(x, t)\).
- Return type:
numpy.typing.NDArray[numpy.float64]
- Λ(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\).
- 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
seed (int | Generator | None) – A seed to initialize the random number generation. If
None
, 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.
- Returns:
Waiting time \(\Delta t\).
- Return type:
numpy.typing.NDArray[numpy.float64]
- 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\).
- Parameters:
x (Hashable | Sequence[Hashable] | numpy.typing.NDArray[Any]) – State to evaluate Poisson intensity at.
- Returns:
The Poisson intensity \(\lambda(x)\).
- Return type:
numpy.typing.NDArray[numpy.float64]
- λ(x, t)#
The Poisson intensity \(\lambda(x, t)\) for state \(x\) at time \(t\).
- Parameters:
x (Hashable) – State to evaluate Poisson intensity at.
t (float) – Time to evaluate Poisson intensity at (
0.0
corresponds to the root). This only has an effect if the process is time-inhomogeneous.
- Returns:
The Poisson intensity \(\lambda(x, t)\).
- Return type:
numpy.typing.NDArray[numpy.float64]
- Λ(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\).
- 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
seed (int | Generator | None) – A seed to initialize the random number generation. If
None
, 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.
- Returns:
Waiting time \(\Delta t\).
- Return type:
numpy.typing.NDArray[numpy.float64]
- 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 the
bdms.TreeNode
attribute to access.quad_kwargs (dict[str, Any]) – Quadrature convergence arguments passed to
scipy.integrate.quad()
.root_kwargs (dict[str, Any]) – Root-finding convergence arguments passed to
scipy.optimize.root_scalar()
.
- abstract λ_inhomogeneous(x, t)#
Evaluate inhomogeneous Poisson intensity \(\lambda(x, t)\) given state \(x\).
- Parameters:
x (Hashable) – Attribute value to evaluate Poisson intensity at.
t (float) – Time at which to evaluate Poisson intensity.
- Returns:
The Poisson intensity \(\lambda(x, t)\).
- Return type:
numpy.typing.NDArray[numpy.float64]
- λ(x, t)#
The Poisson intensity \(\lambda(x, t)\) for state \(x\) at time \(t\).
- Parameters:
x (Hashable) – State to evaluate Poisson intensity at.
t (float) – Time to evaluate Poisson intensity at (
0.0
corresponds to the root). This only has an effect if the process is time-inhomogeneous.
- Returns:
The Poisson intensity \(\lambda(x, t)\).
- Return type:
numpy.typing.NDArray[numpy.float64]
- Λ(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\).
- 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
seed (int | Generator | None) – A seed to initialize the random number generation. If
None
, 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.
- Returns:
Waiting time \(\Delta t\).
- Return type:
numpy.typing.NDArray[numpy.float64]