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 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.

Return type:

ndarray[tuple[int, ...], dtype[floating]]

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.

Parameters:
  • x (Hashable) – State to evaluate Poisson intensity measure at.

  • t (float) – Start time.

  • Δt (float) – Time interval duration.

Return type:

ndarray[tuple[int, ...], dtype[floating]]

Returns:

The Poisson intensity measure \(\Lambda(x, t, \Delta t)\).

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\).

Parameters:
  • x (Hashable) – State.

  • t (float) – Start time of the interval.

  • τ (float) – Poisson intensity measure of the interval.

Return type:

ndarray[tuple[int, ...], dtype[floating]]

Returns:

The inverse Poisson intensity measure \(\Lambda_t^{-1}(x, t, \tau)\).

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 an int, then it will be used to derive the initial state. If a numpy.random.Generator, then it will be used directly.

Return type:

ndarray[tuple[int, ...], dtype[floating]]

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\).

Parameters:

x (Union[Hashable, Sequence[Hashable], ndarray[tuple[int, ...], dtype[Any]]]) – State to evaluate Poisson intensity at.

Return type:

ndarray[tuple[int, ...], dtype[floating]]

Returns:

The Poisson intensity \(\lambda(x)\).

λ(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.

Return type:

ndarray[tuple[int, ...], dtype[floating]]

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.

Parameters:
  • x (Hashable) – State to evaluate Poisson intensity measure at.

  • t (float) – Start time.

  • Δt (float) – Time interval duration.

Return type:

ndarray[tuple[int, ...], dtype[floating]]

Returns:

The Poisson intensity measure \(\Lambda(x, t, \Delta t)\).

Λ_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\).

Parameters:
  • x (Hashable) – State.

  • t (float) – Start time of the interval.

  • τ (float) – Poisson intensity measure of the interval.

Return type:

ndarray[tuple[int, ...], dtype[floating]]

Returns:

The inverse Poisson intensity measure \(\Lambda_t^{-1}(x, t, \tau)\).

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 (Union[Hashable, Sequence[Hashable], ndarray[tuple[int, ...], dtype[Any]]]) – State to evaluate Poisson intensity at.

Return type:

ndarray[tuple[int, ...], dtype[floating]]

Returns:

The Poisson intensity \(\lambda(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\).

Parameters:

x (Union[Hashable, Sequence[Hashable], ndarray[tuple[int, ...], dtype[Any]]]) – State to evaluate Poisson intensity at.

Return type:

ndarray[tuple[int, ...], dtype[floating]]

Returns:

The Poisson intensity \(\lambda(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:
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.

Return type:

ndarray[tuple[int, ...], dtype[floating]]

Returns:

The Poisson intensity \(\lambda(x, t)\).

λ(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.

Return type:

ndarray[tuple[int, ...], dtype[floating]]

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.

Parameters:
  • x (Hashable) – State to evaluate Poisson intensity measure at.

  • t (float) – Start time.

  • Δt (float) – Time interval duration.

Return type:

ndarray[tuple[int, ...], dtype[floating]]

Returns:

The Poisson intensity measure \(\Lambda(x, t, \Delta t)\).

Λ_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\).

Parameters:
  • x (Hashable) – State.

  • t (float) – Start time of the interval.

  • τ (float) – Poisson intensity measure of the interval.

Return type:

ndarray[tuple[int, ...], dtype[floating]]

Returns:

The inverse Poisson intensity measure \(\Lambda_t^{-1}(x, t, \tau)\).