stochrare.fokkerplanck

Numerical solvers for the Fokker-Planck equations

This module contains numerical solvers for the Fokker-Planck equations associated to diffusion processes.

For now, it only contains a basic finite difference solver for the 1D case.

class stochrare.fokkerplanck.FokkerPlanck1DAbstract(drift, diffusion)

Bases: object

Abstract class for 1D Fokker-Planck equations solvers.

Parameters:
  • drift (function with two variables) – The drift coefficient \(a(x, t)\).
  • diffusion (function with two variables) – The diffusion coefficient \(D(x, t)\).

Notes

This is just the legacy code which was migrated from the stochrare.dynamics.DiffusionProcess1D class. It should be rewritten with a better structure. In particular, it only works with a constant diffusion for now.

classmethod gaussian1d(mean, std, X)

Return a 1D Gaussian pdf.

Parameters:
  • mean (float) –
  • std (float) –
  • X (ndarray) – The sample points.
Returns:

pdf – The Gaussian pdf at the sample points.

Return type:

ndarray

classmethod dirac1d(pos, X)

Return a PDF for a certain event.

Parameters:
  • pos (float) – The value occurring with probability one.
  • X (ndarray) – The sample points.
Returns:

pdf – The pdf at the sample points.

Return type:

ndarray

Notes

The method actually returns a vector with a one at the first sample point larger than pos.

classmethod uniform1d(X)

Return a uniform PDF.

Parameters:X (ndarray) – The sample points.
Returns:pdf – The pdf at the sample points.
Return type:ndarray
fpintegrate(t0, T, **kwargs)

Numerical integration of the associated Fokker-Planck equation, or its adjoint.

Parameters:
  • t0 (float) – Initial time.
  • T (float) – Integration time.
Keyword Arguments:
 
  • bounds (float 2-tuple) – Domain where we should solve the equation (default (-10.0, 10.0))
  • npts (ints) – Number of discretization points in the domain (i.e. spatial resolution). Default: 100.
  • dt (float) – Timestep (default choice suitable for the heat equation with forward scheme)
  • bc (stochrare.edpy.BoundaryCondition object or tuple) – Boundary conditions (either a BoundaryCondition object or a tuple sent to _fpbc)
  • method (str) – Numerical scheme: explicit (‘euler’, default), implicit, or crank-nicolson
  • P0 (ndarray) – Initial condition (default is a standard normal distribution).
Returns:

t, X, P – Final time, sample points and solution of the Fokker-Planck equation at the sample points.

Return type:

float, ndarray, ndarray

fpintegrate_generator(*args, **kwargs)

Numerical integration of the associated Fokker-Planck equation, generator version.

Parameters:*args (variable length argument list) – Times at which to yield the pdf.
Yields:t, X, P (float, ndarray, ndarray) – Time, sample points and solution of the Fokker-Planck equation at the sample points.
class stochrare.fokkerplanck.FokkerPlanck1D(drift, diffusion)

Bases: stochrare.fokkerplanck.FokkerPlanck1DAbstract

Solver for the 1D Fokker-Planck equation.

\(\partial_t P(x, t) = - \partial_x a(x, t)P(x, t) + \partial^2_{xx} D(x, t) P(x, t)\)

Parameters:
  • drift (function with two variables) – The drift coefficient \(a(x, t)\).
  • diffusion (function with two variables) – The diffusion coefficient \(D(x, t)\).

Notes

This is just the legacy code which was migrated from the stochrare.dynamics.DiffusionProcess1D class. It should be rewritten with a better structure.

classmethod from_sde(model)

Construct and return a Fokker-Planck object from a DiffusionProcess object. The only thing this constructor does is define the diffusion coefficient \(D(x, t)\) from the diffusion of the stochastic process \(\sigma(x, t)\) as \(D(x, t)=\sigma(x, t)^2/2\).

class stochrare.fokkerplanck.FokkerPlanck1DBackward(drift, diffusion)

Bases: stochrare.fokkerplanck.FokkerPlanck1DAbstract

Solver for the adjoint Fokker-Planck equation.

\(\partial_t P(x, t) = a(x, t)\partial_x P(x, t) + D(x, t) \partial^2_{xx} P(x, t)\)

Parameters:
  • drift (function with two variables) – The drift coefficient \(a(x, t)\).
  • diffusion (function with two variables) – The diffusion coefficient \(D(x, t)\).

Classes

FokkerPlanck1D(drift, diffusion) Solver for the 1D Fokker-Planck equation.
FokkerPlanck1DAbstract(drift, diffusion) Abstract class for 1D Fokker-Planck equations solvers.
FokkerPlanck1DBackward(drift, diffusion) Solver for the adjoint Fokker-Planck equation.
ShortTimePropagator(drift, diffusion, tau) Solver for the Fokker-Planck equation based on the short-time expansion of the generator.