Skip to main content

Generate realizations of stochastic processes

Project description

travis rtd codecov pypi pyversions

A python package for generating realizations of stochastic processes.

Installation

The stochastic package is available on pypi and can be installed using pip

pip install stochastic

Dependencies

Stochastic uses numpy for many calculations and scipy for sampling specific random variables.

Processes

This package offers a number of common discrete-time, continuous-time, and noise process objects for generating realizations of stochastic processes as numpy arrays.

The diffusion processes are approximated using the Euler–Maruyama method.

Here are the currently supported processes and their class references within the package.

  • stochastic.processes

    • continuous

      • BesselProcess

      • BrownianBridge

      • BrownianExcursion

      • BrownianMeander

      • BrownianMotion

      • CauchyProcess

      • FractionalBrownianMotion

      • GammaProcess

      • GeometricBrownianMotion

      • InverseGaussianProcess

      • MixedPoissonProcess

      • MultifractionalBrownianMotion

      • PoissonProcess

      • SquaredBesselProcess

      • VarianceGammaProcess

      • WienerProcess

    • diffusion

      • DiffusionProcess (generalized)

      • ConstantElasticityVarianceProcess

      • CoxIngersollRossProcess

      • ExtendedVasicekProcess

      • OrnsteinUhlenbeckProcess

      • VasicekProcess

    • discrete

      • BernoulliProcess

      • ChineseRestaurantProcess

      • DirichletProcess

      • MarkovChain

      • MoranProcess

      • RandomWalk

    • noise

      • BlueNoise

      • BrownianNoise

      • ColoredNoise

      • PinkNoise

      • RedNoise

      • VioletNoise

      • WhiteNoise

      • FractionalGaussianNoise

      • GaussianNoise

Usage patterns

Sampling

To use stochastic, import the process you want and instantiate with the required parameters. Every process class has a sample method for generating realizations. The sample methods accept a parameter n for the quantity of steps in the realization, but others (Poisson, for instance) may take additional parameters. Parameters can be accessed as attributes of the instance.

from stochastic.processes.discrete import BernoulliProcess


bp = BernoulliProcess(p=0.6)
s = bp.sample(16)
success_probability = bp.p

Continuous processes provide a default parameter, t, which indicates the maximum time of the process realizations. The default value is 1. The sample method will generate n equally spaced increments on the interval [0, t].

Sampling at specific times

Some continuous processes also provide a sample_at() method, in which a sequence of time values can be passed at which the object will generate a realization. This method ignores the parameter, t, specified on instantiation.

from stochastic.processes.continuous import BrownianMotion


bm = BrownianMotion(drift=1, scale=1, t=1)
times = [0, 3, 10, 11, 11.2, 20]
s = bm.sample_at(times)

Sample times

Continuous processes also provide a method times() which generates the time values (using numpy.linspace) corresponding to a realization of n steps. This is particularly useful for plotting your samples.

import matplotlib.pyplot as plt
from stochastic.processes.continuous import FractionalBrownianMotion


fbm = FractionalBrownianMotion(hurst=0.7, t=1)
s = fbm.sample(32)
times = fbm.times(32)

plt.plot(times, s)
plt.show()

Specifying an algorithm

Some processes provide an optional parameter algorithm, in which one can specify which algorithm to use to generate the realization using the sample() or sample_at() methods. See the documentation for process-specific implementations.

from stochastic.processes.noise import FractionalGaussianNoise


fgn = FractionalGaussianNoise(hurst=0.6, t=1)
s = fgn.sample(32, algorithm='hosking')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stochastic-0.6.0.tar.gz (28.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stochastic-0.6.0-py3-none-any.whl (49.5 kB view details)

Uploaded Python 3

File details

Details for the file stochastic-0.6.0.tar.gz.

File metadata

  • Download URL: stochastic-0.6.0.tar.gz
  • Upload date:
  • Size: 28.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.8.5 Darwin/17.7.0

File hashes

Hashes for stochastic-0.6.0.tar.gz
Algorithm Hash digest
SHA256 fd38e9ccc83bac74f04361452f2ad3cfae865cf2700788484599005dfb407b88
MD5 3f6318d2f907cfc087fe8d899a37886c
BLAKE2b-256 0cf9a8093eb101cb9274c435068e14410a65c0167e3e0235241d7c6e6624c505

See more details on using hashes here.

File details

Details for the file stochastic-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: stochastic-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 49.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.8.5 Darwin/17.7.0

File hashes

Hashes for stochastic-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0c9d662e6d4f113d441264a23710c1b896c52269aa775c9736ddc88f00ad419
MD5 bd732a5e9ebb9b910336ba1e66103b85
BLAKE2b-256 a00e380ace1d576d64be4d4315f61e7b8ef1583ece70a4112ab8575c7b173ef2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page