Discrete-time Processes

The stochastic.processes.discrete module provides classes for generating discrete-time stochastic processes.

class stochastic.processes.discrete.BernoulliProcess(p=0.5, rng=None)[source]

Bernoulli process.


A Bernoulli process consists of a sequence of Bernoulli random variables. A Bernoulli random variable is

  • 1 with probability \(p\)

  • 0 with probaiility \(1-p\)

  • p – in \([0,1]\), the probability of success of each Bernoulli random variable

  • rng (numpy.random.Generator) – a custom random number generator

property p

Probability of success.


Generate a Bernoulli process realization.


n (int) – the number of steps to simulate.

class stochastic.processes.discrete.ChineseRestaurantProcess(discount=0, strength=1, rng=None)[source]

Chinese restaurant process.


A Chinese restaurant process consists of a sequence of arrivals of customers to a Chinese restaurant. Customers may be seated either at an occupied table or a new table, there being infinitely many customers and tables.

The first customer sits at the first table. The \(n\)-th customer sits at a new table with probability \(1/n\), and at each already occupied table with probability \(t_k/n\), where \(t_k\) is the number of customers already seated at table \(k\). This is the canonical process with \(discount=0\) and \(strength=1\).

The generalized process gives the \(n\)-th customer a probability of \((strength + T * discount) / (n - 1 + strength)\) to sit at a new table and a probability of \((t_k - discount) / (n - 1 + strength)\) of sitting at table \(k\). \(T\) is the number of occupied tables.

Samples provide a sequence of tables selected by a sequence of customers.

  • discount (float) – the discount value of existing tables. Must be strictly less than 1.

  • strength (float) – the strength of a new table. If discount is negative, strength must be a multiple of discount. If discount is nonnegative, strength must be strictly greater than the negative discount.

  • rng (numpy.random.Generator) – a custom random number generator

property discount

Discount parameter.


Create a sequence from a partition.


partition – a Chinese restaurant partition.


Generate a Chinese restaurant process with \(n\) customers.


n – the number of customers to simulate.


Generate a Chinese restaurant process partition.


n – the number of customers to simulate.


Create a partition from a sequence.


sequence – a Chinese restaurant sample.

property strength

Strength parameter.

class stochastic.processes.discrete.DirichletProcess(base=None, alpha=1, rng=None)[source]

Dirichlet process.


A Dirichlet process is a stochastic process in which the resulting samples can be interpreted as discrete probability distributions.

For each step \(k \geq 1\), draw from the base distribution with probability

\[\frac{\alpha}{\alpha + k - 1}\]

Otherwise draw randomly from the previous steps.

  • base (callable) – a zero argument callable used as the base distribution sampler. The default base distribution is Uniform(0, 1).

  • alpha (float) – a non-negative value used to determine probability of drawing a new value from the base distribution

  • rng (numpy.random.Generator) – a custom random number generator

property alpha

Parameter for determining the probability of sampling new values.

property base

The base distribution callable for sampling new step values.


Generate a realization of the Dirichlet process.


n (int) – the number of steps of the Dirichlet process to generate.

class stochastic.processes.discrete.MarkovChain(transition=None, initial=None, rng=None)[source]

Finite state Markov chain.


A Markov Chain which changes between states according to the transition matrix.

  • transition (2darray) – a square matrix representing the transition probabilities between states.

  • initial (1darray) – a vector representing the initial state probabilities. If not provided, each state has equal initial probability.

  • rng (numpy.random.Generator) – a custom random number generator

property initial

Vector of initial state probabilities.


Generate a realization of the Markov chain.


n (int) – the number of steps of the Markov chain to generate.

property transition

Transition probability matrix.

class stochastic.processes.discrete.MoranProcess(maximum, rng=None)[source]

Moran process.


A neutral drift Moran process, typically used to model populations. At each step this process will increase by one, decrease by one, or remain at the same value between values of zero and the number of states, \(n\). The process ends when its value reaches zero or the maximum valued state.

  • maximum (int) – the maximum possible value for the process.

  • rng (numpy.random.Generator) – a custom random number generator

property maximum

Maximum value.

sample(n, start)[source]

Generate a realization of the Moran process.

Generate a Moran process until absorption occurs (state 0 or maximum) or length of process reaches length \(n\).

  • n (int) – the maximum number of steps to generate assuming absorption does not occur.

  • start (int) – the initial state of the process.

class stochastic.processes.discrete.RandomWalk(steps=None, weights=None, rng=None)[source]

Random walk.


A random walk is a sequence of random steps taken from a set of step sizes with a probability distribution. By default this object defines the steps to be [-1, 1] with probability 1/2 for each possibility.

  • steps – a vector of possible deltas to apply at each step.

  • weights – a corresponding vector of weights associated with each step value. If not provided each step has equal weight/probability.

property p

Step probabilities, normalized from weights.


Generate a sample random walk.


n (int) – the number of steps to generate


Generate a sample of random walk increments.


n (int) – the number of increments to generate.

property steps

Possible steps.

property weights

Step weights provided.