Skip to main content

Stochastic process realizations.

Project description

A python package for generating realizations of common (and perhaps some less common) stochastic processes, with some optimization for repeated simulation.

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

    • continuous

      • BesselProcess

      • BrownianBridge

      • BrownianExcursion

      • BrownianMeander

      • BrownianMotion

      • CauchyProcess

      • FractionalBrownianMotion

      • GammaProcess

      • GeometricBrownianMotion

      • PoissonProcess

      • SquaredBesselProcess

      • VarianceGammaProcess

      • WienerProcess

    • diffusion

      • ConstantElasticityVarianceProcess

      • CoxIngersollRossProcess

      • OrnsteinUhlenbeckProcess

      • VasicekProcess

    • discrete

      • BernoulliProcess

      • ChineseRestaurantProcess

      • MarkovChain

      • MoranProcess

      • RandomWalk

    • noise

      • GaussianNoise

      • FractionalGaussianNoise

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.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.continuous import BrownianMotion


bm = BrownianMotion(t=1, drift=1, scale=1)
times = [0, 3, 10, 11, 11.2, 20]
s = 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.continuous import FractionalBrownianMotion


fbm = FractionalBrownianMotion(t=1, hurst=0.7)
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.noise import FractionalGaussianNoise


fgn = FractionalGaussianNoise(t=1, hurst=0.6)
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.1.0.tar.gz (27.2 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.1.0-py2.py3-none-any.whl (35.8 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: stochastic-0.1.0.tar.gz
  • Upload date:
  • Size: 27.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for stochastic-0.1.0.tar.gz
Algorithm Hash digest
SHA256 723163bc7c4e1059c386bff902554b00df4b2b94ed9dcb32a81d8b4ba8fd92c1
MD5 7c7f9997d5b4f2fc72a6cf3eabd4fb1c
BLAKE2b-256 bb21dca2b28f7c9a778717cd6a3185364f51fd95c98238f3c7f16aa349485e9c

See more details on using hashes here.

File details

Details for the file stochastic-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for stochastic-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d1f27cda6c0a11e2bf7642c858a9a78f3421bc370a4f9c953f8910ad128a454b
MD5 e21773cfbd9c38d0694a6346c2306ebe
BLAKE2b-256 989c22542e369450a1af04090fd37899f92e4dc8a71186bbb889865e1a269850

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