• Stars
    star
    448
  • Rank 97,523 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 8 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Generate realizations of stochastic processes in python.

stochastic

build 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')

More Repositories

1

pypistats.org

PyPI downloads analytics dashboard
Python
139
star
2

fbm

Exact methods for simulating fractional Brownian motion and fractional Gaussian noise in python
Python
95
star
3

databricks-api

A simplified, autogenerated API client interface using the databricks-cli package
Python
60
star
4

skranger

scikit-learn compatible Python bindings for ranger C++ random forest library
Python
50
star
5

chicken-dinner

Python PUBG API wrapper and CLI with replay visualizations
Python
38
star
6

skgrf

scikit-learn compatible Python bindings for grf (generalized random forests) C++ random forest library
Python
30
star
7

databricks-dbapi

DBAPI and SQLAlchemy dialect for Databricks Workspace and SQL Analytics clusters
Python
22
star
8

pbspark

protobuf pyspark conversion
Python
21
star
9

sqlalchemy-databricks

SQLAlchemy dialect for Databricks
Python
21
star
10

redisgraph-ex

RedisGraph client implementation in Elixir
Elixir
20
star
11

celery-slack

A Slack messaging extension for Celery.
Python
17
star
12

voting

Diversity / (dis)proportionality measures, election quotas, and apportionment methods in pure Python.
Python
14
star
13

sklearn-instrumentation

Generalized scikit-learn machine learning model instrumentation library
Python
5
star
14

soh

Sleight-of-hand (soh) CLI tool
Rust
4
star
15

apple-devices-csv

A csv file of Apple device identifiers mapped to their market names.
2
star
16

lol-champions-quickfind

Shortest string sequences for finding your favorite League of Legends champions in queue.
2
star
17

poetry-current-active-python-test

Dockerfile
1
star
18

excoverflow

Appends google/stackoverflow search links to unhandled exceptions in python.
Python
1
star
19

protobuf-init

python protoc plugin for generating __init__.py (init) files
Python
1
star