InfinitesimalGenerators.jl computes stationary distributions, conditional expectations, and tail indices of continuous-time Markov processes. It works in two steps. The first step is to build the generator matrix: a Markov-chain approximation of the process on a finite grid, representing transition rates between grid points (in particular, rows must sum to zero and off-diagonal elements are non-negative).
The second step is to use this generator to turn the linear PDEs associated with the process into linear algebra. In particular, the package covers the following problems:
- Stationary distributions (the Kolmogorov forward equation): the distribution of wealth, firm size, or any state in the long run — see Computing distributions (Kolmogorov forward).
- Conditional expectations (the Kolmogorov backward equation): present values, forecasts, survival probabilities — see Computing expectations (Kolmogorov backward).
- Power-law tail indices of stationary distributions generated by random growth (wealth, firm size, city size) — see Computing tail indices.
The same generator matrices also appear inside finite-difference methods for nonlinear HJB equations. InfinitesimalGenerators.jl focuses on the linear PDEs once a process is known; for nonlinear HJB problems, see EconPDEs.jl and Application to a consumption-saving problem.
using Pkg
Pkg.add("InfinitesimalGenerators")using InfinitesimalGenerators
# an Ornstein-Uhlenbeck process dx = -0.03 x dt + 0.01 dZ, discretized on a grid
x = range(-1, 1, length = 100)
X = DiffusionProcess(x, -0.03 .* x, 0.01 .* ones(100))
generator(X) # the generator (transition-rate) matrix
stationary_distribution(X) # its stationary distribution
feynman_kac(X, 0:0.1:10; ψ = collect(x)) # conditional expectations E[x_T | x_t]Beyond univariate diffusions, the package supports finite-state continuous-time Markov chains (ContinuousTimeMarkovChain), multivariate diffusions (MultivariateDiffusionProcess), and their compositions (ProductProcess, SwitchingProcess) — all through the same three verbs: generator, state_space, and size. Generators are discretized with the standard upwind finite-difference scheme, with reflecting boundaries.
Process types subtype ContinuousTimeMarkovProcess{N}, where N is the number of tensor-product state-space axes. For example, a scalar diffusion has N == 1, while ProductProcess(X, Z) has N == ndims(X) + ndims(Z).
The documentation has a manual — processes and generators and the operators that apply to them — and four tutorials, each showing the computation by hand from the generator matrix before introducing the helper function:
- Computing expectations (Kolmogorov backward) — the Kolmogorov backward equation and
feynman_kac. - Computing distributions (Kolmogorov forward) — the Kolmogorov forward equation and
stationary_distribution. - Application to a consumption-saving problem — how generator matrices enter implicit finite-difference methods for nonlinear HJB equations.
- Computing tail indices — principal eigenvalues of tilted generators,
cgf, andtail_index.
- EconPDEs is focused on nonlinear PDEs resulting from optimization problems (HJB equations), while InfinitesimalGenerators is focused on solving linear PDEs. Of course, there is a decent overlap between the two: see this worked example in the EconPDEs documentation and Application to a consumption-saving problem in this one.
- SimpleDifferentialOperators contains more general tools to define operators with different boundary conditions. In contrast, InfinitesimalGenerators always assumes reflecting boundaries.