samplepaths 0.1.0__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- samplepaths-0.2.0/PKG-INFO +204 -0
- samplepaths-0.2.0/README.md +172 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/pyproject.toml +10 -5
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/continuous/bessel_process.py +7 -4
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/continuous/brownian_excursion.py +4 -12
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/continuous/brownian_motion.py +1 -1
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/continuous/cauchy_process.py +29 -17
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/continuous/gamma_process.py +6 -7
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/continuous/inverse_gaussian_process.py +5 -19
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/continuous/multifractional_brownian_motion.py +14 -21
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/continuous/poisson_process.py +1 -3
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/continuous/squared_bessel_process.py +6 -4
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/continuous/variance_gamma_process.py +1 -10
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/discrete/bernoulli_process.py +1 -8
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/discrete/chinese_restaurant_process.py +20 -8
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/discrete/dirichlet_process.py +11 -6
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/discrete/markov_chain.py +20 -5
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/discrete/moran_process.py +15 -4
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/discrete/random_walk.py +2 -1
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/noise/colored/colored_noise.py +9 -13
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/noise/fractional_gaussian_noise.py +11 -12
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/noise/gaussian_noise.py +1 -10
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/utils/validation.py +4 -3
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/continuous/test_cauchy_process.py +14 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/discrete/test_moran_process.py +10 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/noise/colored/test_colored_noise.py +15 -0
- samplepaths-0.1.0/PKG-INFO +0 -159
- samplepaths-0.1.0/README.rst +0 -127
- {samplepaths-0.1.0 → samplepaths-0.2.0}/.gitignore +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/LICENSE +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/__init__.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/base/__init__.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/base/base_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/base/base_sequence_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/base/base_time_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/continuous/__init__.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/continuous/brownian_bridge.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/continuous/brownian_meander.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/continuous/fractional_brownian_motion.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/continuous/geometric_brownian_motion.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/continuous/mixed_poisson_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/continuous/wiener_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/diffusion/__init__.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/diffusion/constant_elasticity_variance_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/diffusion/cox_ingersoll_ross_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/diffusion/diffusion_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/diffusion/extended_vasicek_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/diffusion/ornstein_uhlenbeck_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/diffusion/vasicek_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/discrete/__init__.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/noise/__init__.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/noise/colored/__init__.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/noise/colored/blue_noise.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/noise/colored/brownian_noise.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/noise/colored/pink_noise.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/noise/colored/red_noise.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/noise/colored/violet_noise.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/noise/colored/white_noise.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/py.typed +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/random.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/utils/__init__.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/__init__.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/base/__init__.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/base/test_base_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/base/test_base_sequence_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/base/test_base_time_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/continuous/__init__.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/continuous/test_bessel_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/continuous/test_brownian_bridge.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/continuous/test_brownian_excursion.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/continuous/test_brownian_meander.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/continuous/test_brownian_motion.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/continuous/test_fractional_brownian_motion.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/continuous/test_gamma_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/continuous/test_geometric_brownian_motion.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/continuous/test_inverse_gaussian_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/continuous/test_mixed_poisson_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/continuous/test_multifractional_brownian_motion.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/continuous/test_poisson_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/continuous/test_squared_bessel_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/continuous/test_variance_gamma_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/continuous/test_wiener_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/diffusion/__init__.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/diffusion/test_constant_elasticity_variance_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/diffusion/test_cox_ingersoll_ross_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/diffusion/test_diffusion_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/diffusion/test_extended_vasicek_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/diffusion/test_ornstein_uhlenbeck_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/diffusion/test_vasicek_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/discrete/__init__.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/discrete/test_bernoulli_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/discrete/test_chinese_restaurant_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/discrete/test_dirichlet_process.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/discrete/test_markov_chain.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/discrete/test_random_walk.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/noise/__init__.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/noise/colored/__init__.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/noise/colored/test_blue_noise.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/noise/colored/test_brownian_noise.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/noise/colored/test_pink_noise.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/noise/colored/test_red_noise.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/noise/colored/test_violet_noise.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/noise/colored/test_white_noise.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/noise/test_fractional_gaussian_noise.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/noise/test_gaussian_noise.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/test_import.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/test_random.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/test_times.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/utils/__init__.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/utils/test_utils.py +0 -0
- {samplepaths-0.1.0 → samplepaths-0.2.0}/tests/utils/test_validation.py +0 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: samplepaths
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Generate realizations of stochastic processes
|
|
5
|
+
Project-URL: Homepage, https://github.com/samplepaths/samplepaths
|
|
6
|
+
Project-URL: Documentation, https://samplepaths.readthedocs.io/
|
|
7
|
+
Project-URL: Repository, https://github.com/samplepaths/samplepaths
|
|
8
|
+
Project-URL: Issues, https://github.com/samplepaths/samplepaths/issues
|
|
9
|
+
Project-URL: Author, https://girgis.me
|
|
10
|
+
Author-email: Bassem Girgis <brgirgis@gmail.com>, Christopher Flynn <crf204@gmail.com>
|
|
11
|
+
Maintainer-email: Bassem Girgis <brgirgis@gmail.com>
|
|
12
|
+
License-Expression: MIT
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Keywords: monte carlo,processes,simulation,stochastic
|
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: Natural Language :: English
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering
|
|
25
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
26
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
27
|
+
Classifier: Typing :: Typed
|
|
28
|
+
Requires-Python: >=3.12
|
|
29
|
+
Requires-Dist: numpy>=2.2.6
|
|
30
|
+
Requires-Dist: scipy>=1.15.3
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# samplepaths
|
|
34
|
+
|
|
35
|
+
[](https://github.com/samplepaths/samplepaths/actions/workflows/tests.yml)
|
|
36
|
+
[](https://samplepaths.readthedocs.io/)
|
|
37
|
+
[](https://pypi.org/project/samplepaths/)
|
|
38
|
+
[](https://pypi.org/project/samplepaths/)
|
|
39
|
+
[](https://pypistats.org/packages/samplepaths)
|
|
40
|
+
[](https://pepy.tech/projects/samplepaths)
|
|
41
|
+
[](https://github.com/samplepaths/samplepaths/blob/master/LICENSE)
|
|
42
|
+
|
|
43
|
+
Generate realizations (sample paths) of stochastic processes as NumPy arrays.
|
|
44
|
+
|
|
45
|
+

|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from samplepaths import BrownianMotion
|
|
49
|
+
|
|
50
|
+
bm = BrownianMotion(drift=1, scale=2, t=10)
|
|
51
|
+
path = bm.sample(1000) # 1001 values on [0, 10]
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
- **37 processes** in four families: continuous-time, diffusion, discrete-time and noise
|
|
55
|
+
- **One interface**: every process is a class with a `sample(n)` method
|
|
56
|
+
- **Reproducible**: built on `numpy.random.Generator`, per process or through a seedable default
|
|
57
|
+
- **Typed**: type hints throughout, checked with mypy in strict mode
|
|
58
|
+
- **Light**: depends only on NumPy and SciPy
|
|
59
|
+
|
|
60
|
+
Full documentation: **https://samplepaths.readthedocs.io/**
|
|
61
|
+
|
|
62
|
+
## Installation
|
|
63
|
+
|
|
64
|
+
```shell
|
|
65
|
+
pip install samplepaths
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`samplepaths` requires Python 3.12 or newer, NumPy 2.2 or newer and SciPy 1.15 or newer.
|
|
69
|
+
|
|
70
|
+
## Quickstart
|
|
71
|
+
|
|
72
|
+
Create a process with its parameters, then call `sample(n)` to generate a realization of `n` increments.
|
|
73
|
+
For a process on a time interval, the realization holds `n + 1` values and `times` holds the matching time values.
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
import matplotlib.pyplot as plt
|
|
77
|
+
from samplepaths import FractionalBrownianMotion
|
|
78
|
+
|
|
79
|
+
fbm = FractionalBrownianMotion(hurst=0.7, t=5)
|
|
80
|
+
|
|
81
|
+
for _ in range(3):
|
|
82
|
+
path = fbm.sample(512)
|
|
83
|
+
plt.plot(fbm.times, path)
|
|
84
|
+
|
|
85
|
+
plt.show()
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Reproducible results
|
|
89
|
+
|
|
90
|
+
Give a process its own generator, or seed the generator shared by all processes created without one.
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
import numpy as np
|
|
94
|
+
from samplepaths import BrownianMotion
|
|
95
|
+
from samplepaths import random
|
|
96
|
+
|
|
97
|
+
bm = BrownianMotion(rng=np.random.default_rng(42))
|
|
98
|
+
|
|
99
|
+
random.seed(value=42)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Sampling at chosen times
|
|
103
|
+
|
|
104
|
+
Most continuous-time processes can be sampled at times of your choice with `sample_at()`.
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from samplepaths import BrownianMotion
|
|
108
|
+
|
|
109
|
+
bm = BrownianMotion(drift=1, scale=1)
|
|
110
|
+
values = bm.sample_at([0, 3, 10, 11, 11.2, 20])
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### More than one way to sample
|
|
114
|
+
|
|
115
|
+
`sample(n)` has the same signature on every process. Variants have their own methods.
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from samplepaths import FractionalGaussianNoise
|
|
119
|
+
from samplepaths import GeometricBrownianMotion
|
|
120
|
+
from samplepaths import PoissonProcess
|
|
121
|
+
|
|
122
|
+
prices = GeometricBrownianMotion(drift=0.05, volatility=0.2).sample_with_initial(252, initial=100.0)
|
|
123
|
+
arrivals = PoissonProcess(rate=2.0).sample_with_length(10.0)
|
|
124
|
+
noise = FractionalGaussianNoise(hurst=0.6).sample_hosking(32)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Generic simulation code
|
|
128
|
+
|
|
129
|
+
Because the interface is shared, simulation code does not depend on the process it simulates.
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
import numpy as np
|
|
133
|
+
from samplepaths import CoxIngersollRossProcess
|
|
134
|
+
from samplepaths import GeometricBrownianMotion
|
|
135
|
+
from samplepaths.base import BaseTimeProcess
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def final_values(process: BaseTimeProcess, n: int, paths: int) -> np.ndarray:
|
|
139
|
+
"""Simulate a number of paths and collect the last value of each."""
|
|
140
|
+
return np.array([process.sample(n)[-1] for _ in range(paths)])
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
final_values(GeometricBrownianMotion(drift=0.05, volatility=0.2), n=64, paths=1000)
|
|
144
|
+
final_values(CoxIngersollRossProcess(speed=1, mean=1, vol=0.5), n=64, paths=1000)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Processes
|
|
148
|
+
|
|
149
|
+

|
|
150
|
+
|
|
151
|
+
Every process can be imported from `samplepaths` or from the subpackage of its family.
|
|
152
|
+
|
|
153
|
+
| Family | Subpackage | Processes |
|
|
154
|
+
| --- | --- | --- |
|
|
155
|
+
| Continuous-time | `samplepaths.continuous` | `BesselProcess`, `BrownianBridge`, `BrownianExcursion`, `BrownianMeander`, `BrownianMotion`, `CauchyProcess`, `FractionalBrownianMotion`, `GammaProcess`, `GeometricBrownianMotion`, `InverseGaussianProcess`, `MixedPoissonProcess`, `MultifractionalBrownianMotion`, `PoissonProcess`, `SquaredBesselProcess`, `VarianceGammaProcess`, `WienerProcess` |
|
|
156
|
+
| Diffusion | `samplepaths.diffusion` | `DiffusionProcess`, `ConstantElasticityVarianceProcess`, `CoxIngersollRossProcess`, `ExtendedVasicekProcess`, `OrnsteinUhlenbeckProcess`, `VasicekProcess` |
|
|
157
|
+
| Discrete-time | `samplepaths.discrete` | `BernoulliProcess`, `ChineseRestaurantProcess`, `DirichletProcess`, `MarkovChain`, `MoranProcess`, `RandomWalk` |
|
|
158
|
+
| Noise | `samplepaths.noise` | `GaussianNoise`, `FractionalGaussianNoise`, `ColoredNoise`, `VioletNoise`, `BlueNoise`, `WhiteNoise`, `PinkNoise`, `RedNoise`, `BrownianNoise` |
|
|
159
|
+
|
|
160
|
+
Diffusion processes are approximated with the Euler-Maruyama method.
|
|
161
|
+
|
|
162
|
+
## Documentation
|
|
163
|
+
|
|
164
|
+
The documentation at https://samplepaths.readthedocs.io/ contains:
|
|
165
|
+
|
|
166
|
+
- a [quickstart](https://samplepaths.readthedocs.io/en/latest/getting-started/quickstart.html)
|
|
167
|
+
- a user guide for [sampling](https://samplepaths.readthedocs.io/en/latest/guide/usage.html), [random number generation](https://samplepaths.readthedocs.io/en/latest/guide/random.html) and every family of processes
|
|
168
|
+
- an [API reference](https://samplepaths.readthedocs.io/en/latest/reference/index.html) for every class, method and function
|
|
169
|
+
|
|
170
|
+
## Coming from stochastic
|
|
171
|
+
|
|
172
|
+
`samplepaths` is an independently maintained fork of [stochastic](https://github.com/crflynn/stochastic) 0.7.0 by Christopher Flynn.
|
|
173
|
+
It keeps the original processes and algorithms and modernizes everything around them: current Python, NumPy and SciPy, type hints, one sampling interface, and corrected drift handling.
|
|
174
|
+
|
|
175
|
+
Porting is mostly a change of import:
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
# stochastic
|
|
179
|
+
from stochastic.processes.continuous import BrownianMotion
|
|
180
|
+
|
|
181
|
+
# samplepaths
|
|
182
|
+
from samplepaths.continuous import BrownianMotion
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
See the [migration guide](https://samplepaths.readthedocs.io/en/latest/project/migration.html) for the full list of changes.
|
|
186
|
+
|
|
187
|
+
## Development
|
|
188
|
+
|
|
189
|
+
The project is managed with [uv](https://docs.astral.sh/uv/) and `make`.
|
|
190
|
+
|
|
191
|
+
```shell
|
|
192
|
+
git clone https://github.com/samplepaths/samplepaths.git
|
|
193
|
+
cd samplepaths
|
|
194
|
+
make install # create the environment
|
|
195
|
+
make check # lint, type check, test and build the docs
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Run `make` to list all targets. Bug reports and pull requests are welcome on [GitHub](https://github.com/samplepaths/samplepaths/issues).
|
|
199
|
+
|
|
200
|
+
## License
|
|
201
|
+
|
|
202
|
+
`samplepaths` is released under the [MIT license](https://github.com/samplepaths/samplepaths/blob/master/LICENSE).
|
|
203
|
+
|
|
204
|
+
It is maintained by [Bassem Girgis](https://girgis.me).
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# samplepaths
|
|
2
|
+
|
|
3
|
+
[](https://github.com/samplepaths/samplepaths/actions/workflows/tests.yml)
|
|
4
|
+
[](https://samplepaths.readthedocs.io/)
|
|
5
|
+
[](https://pypi.org/project/samplepaths/)
|
|
6
|
+
[](https://pypi.org/project/samplepaths/)
|
|
7
|
+
[](https://pypistats.org/packages/samplepaths)
|
|
8
|
+
[](https://pepy.tech/projects/samplepaths)
|
|
9
|
+
[](https://github.com/samplepaths/samplepaths/blob/master/LICENSE)
|
|
10
|
+
|
|
11
|
+
Generate realizations (sample paths) of stochastic processes as NumPy arrays.
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from samplepaths import BrownianMotion
|
|
17
|
+
|
|
18
|
+
bm = BrownianMotion(drift=1, scale=2, t=10)
|
|
19
|
+
path = bm.sample(1000) # 1001 values on [0, 10]
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
- **37 processes** in four families: continuous-time, diffusion, discrete-time and noise
|
|
23
|
+
- **One interface**: every process is a class with a `sample(n)` method
|
|
24
|
+
- **Reproducible**: built on `numpy.random.Generator`, per process or through a seedable default
|
|
25
|
+
- **Typed**: type hints throughout, checked with mypy in strict mode
|
|
26
|
+
- **Light**: depends only on NumPy and SciPy
|
|
27
|
+
|
|
28
|
+
Full documentation: **https://samplepaths.readthedocs.io/**
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```shell
|
|
33
|
+
pip install samplepaths
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`samplepaths` requires Python 3.12 or newer, NumPy 2.2 or newer and SciPy 1.15 or newer.
|
|
37
|
+
|
|
38
|
+
## Quickstart
|
|
39
|
+
|
|
40
|
+
Create a process with its parameters, then call `sample(n)` to generate a realization of `n` increments.
|
|
41
|
+
For a process on a time interval, the realization holds `n + 1` values and `times` holds the matching time values.
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
import matplotlib.pyplot as plt
|
|
45
|
+
from samplepaths import FractionalBrownianMotion
|
|
46
|
+
|
|
47
|
+
fbm = FractionalBrownianMotion(hurst=0.7, t=5)
|
|
48
|
+
|
|
49
|
+
for _ in range(3):
|
|
50
|
+
path = fbm.sample(512)
|
|
51
|
+
plt.plot(fbm.times, path)
|
|
52
|
+
|
|
53
|
+
plt.show()
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Reproducible results
|
|
57
|
+
|
|
58
|
+
Give a process its own generator, or seed the generator shared by all processes created without one.
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
import numpy as np
|
|
62
|
+
from samplepaths import BrownianMotion
|
|
63
|
+
from samplepaths import random
|
|
64
|
+
|
|
65
|
+
bm = BrownianMotion(rng=np.random.default_rng(42))
|
|
66
|
+
|
|
67
|
+
random.seed(value=42)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Sampling at chosen times
|
|
71
|
+
|
|
72
|
+
Most continuous-time processes can be sampled at times of your choice with `sample_at()`.
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from samplepaths import BrownianMotion
|
|
76
|
+
|
|
77
|
+
bm = BrownianMotion(drift=1, scale=1)
|
|
78
|
+
values = bm.sample_at([0, 3, 10, 11, 11.2, 20])
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### More than one way to sample
|
|
82
|
+
|
|
83
|
+
`sample(n)` has the same signature on every process. Variants have their own methods.
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from samplepaths import FractionalGaussianNoise
|
|
87
|
+
from samplepaths import GeometricBrownianMotion
|
|
88
|
+
from samplepaths import PoissonProcess
|
|
89
|
+
|
|
90
|
+
prices = GeometricBrownianMotion(drift=0.05, volatility=0.2).sample_with_initial(252, initial=100.0)
|
|
91
|
+
arrivals = PoissonProcess(rate=2.0).sample_with_length(10.0)
|
|
92
|
+
noise = FractionalGaussianNoise(hurst=0.6).sample_hosking(32)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Generic simulation code
|
|
96
|
+
|
|
97
|
+
Because the interface is shared, simulation code does not depend on the process it simulates.
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
import numpy as np
|
|
101
|
+
from samplepaths import CoxIngersollRossProcess
|
|
102
|
+
from samplepaths import GeometricBrownianMotion
|
|
103
|
+
from samplepaths.base import BaseTimeProcess
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def final_values(process: BaseTimeProcess, n: int, paths: int) -> np.ndarray:
|
|
107
|
+
"""Simulate a number of paths and collect the last value of each."""
|
|
108
|
+
return np.array([process.sample(n)[-1] for _ in range(paths)])
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
final_values(GeometricBrownianMotion(drift=0.05, volatility=0.2), n=64, paths=1000)
|
|
112
|
+
final_values(CoxIngersollRossProcess(speed=1, mean=1, vol=0.5), n=64, paths=1000)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Processes
|
|
116
|
+
|
|
117
|
+

|
|
118
|
+
|
|
119
|
+
Every process can be imported from `samplepaths` or from the subpackage of its family.
|
|
120
|
+
|
|
121
|
+
| Family | Subpackage | Processes |
|
|
122
|
+
| --- | --- | --- |
|
|
123
|
+
| Continuous-time | `samplepaths.continuous` | `BesselProcess`, `BrownianBridge`, `BrownianExcursion`, `BrownianMeander`, `BrownianMotion`, `CauchyProcess`, `FractionalBrownianMotion`, `GammaProcess`, `GeometricBrownianMotion`, `InverseGaussianProcess`, `MixedPoissonProcess`, `MultifractionalBrownianMotion`, `PoissonProcess`, `SquaredBesselProcess`, `VarianceGammaProcess`, `WienerProcess` |
|
|
124
|
+
| Diffusion | `samplepaths.diffusion` | `DiffusionProcess`, `ConstantElasticityVarianceProcess`, `CoxIngersollRossProcess`, `ExtendedVasicekProcess`, `OrnsteinUhlenbeckProcess`, `VasicekProcess` |
|
|
125
|
+
| Discrete-time | `samplepaths.discrete` | `BernoulliProcess`, `ChineseRestaurantProcess`, `DirichletProcess`, `MarkovChain`, `MoranProcess`, `RandomWalk` |
|
|
126
|
+
| Noise | `samplepaths.noise` | `GaussianNoise`, `FractionalGaussianNoise`, `ColoredNoise`, `VioletNoise`, `BlueNoise`, `WhiteNoise`, `PinkNoise`, `RedNoise`, `BrownianNoise` |
|
|
127
|
+
|
|
128
|
+
Diffusion processes are approximated with the Euler-Maruyama method.
|
|
129
|
+
|
|
130
|
+
## Documentation
|
|
131
|
+
|
|
132
|
+
The documentation at https://samplepaths.readthedocs.io/ contains:
|
|
133
|
+
|
|
134
|
+
- a [quickstart](https://samplepaths.readthedocs.io/en/latest/getting-started/quickstart.html)
|
|
135
|
+
- a user guide for [sampling](https://samplepaths.readthedocs.io/en/latest/guide/usage.html), [random number generation](https://samplepaths.readthedocs.io/en/latest/guide/random.html) and every family of processes
|
|
136
|
+
- an [API reference](https://samplepaths.readthedocs.io/en/latest/reference/index.html) for every class, method and function
|
|
137
|
+
|
|
138
|
+
## Coming from stochastic
|
|
139
|
+
|
|
140
|
+
`samplepaths` is an independently maintained fork of [stochastic](https://github.com/crflynn/stochastic) 0.7.0 by Christopher Flynn.
|
|
141
|
+
It keeps the original processes and algorithms and modernizes everything around them: current Python, NumPy and SciPy, type hints, one sampling interface, and corrected drift handling.
|
|
142
|
+
|
|
143
|
+
Porting is mostly a change of import:
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
# stochastic
|
|
147
|
+
from stochastic.processes.continuous import BrownianMotion
|
|
148
|
+
|
|
149
|
+
# samplepaths
|
|
150
|
+
from samplepaths.continuous import BrownianMotion
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
See the [migration guide](https://samplepaths.readthedocs.io/en/latest/project/migration.html) for the full list of changes.
|
|
154
|
+
|
|
155
|
+
## Development
|
|
156
|
+
|
|
157
|
+
The project is managed with [uv](https://docs.astral.sh/uv/) and `make`.
|
|
158
|
+
|
|
159
|
+
```shell
|
|
160
|
+
git clone https://github.com/samplepaths/samplepaths.git
|
|
161
|
+
cd samplepaths
|
|
162
|
+
make install # create the environment
|
|
163
|
+
make check # lint, type check, test and build the docs
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Run `make` to list all targets. Bug reports and pull requests are welcome on [GitHub](https://github.com/samplepaths/samplepaths/issues).
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
`samplepaths` is released under the [MIT license](https://github.com/samplepaths/samplepaths/blob/master/LICENSE).
|
|
171
|
+
|
|
172
|
+
It is maintained by [Bassem Girgis](https://girgis.me).
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = ["hatchling"]
|
|
2
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
3
3
|
build-backend = "hatchling.build"
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
[project]
|
|
7
7
|
name = "samplepaths"
|
|
8
|
-
|
|
8
|
+
dynamic = ["version"]
|
|
9
9
|
description = "Generate realizations of stochastic processes"
|
|
10
|
-
readme = "README.
|
|
10
|
+
readme = "README.md"
|
|
11
11
|
requires-python = ">=3.12"
|
|
12
12
|
license = "MIT"
|
|
13
13
|
license-files = ["LICENSE"]
|
|
@@ -67,8 +67,13 @@ dev = [
|
|
|
67
67
|
]
|
|
68
68
|
|
|
69
69
|
|
|
70
|
+
# The version is the git tag of the release, for example v0.2.0 gives 0.2.0.
|
|
71
|
+
[tool.hatch.version]
|
|
72
|
+
source = "vcs"
|
|
73
|
+
|
|
74
|
+
|
|
70
75
|
[tool.hatch.build.targets.sdist]
|
|
71
|
-
include = ["/src", "/tests", "/README.
|
|
76
|
+
include = ["/src", "/tests", "/README.md", "/LICENSE"]
|
|
72
77
|
|
|
73
78
|
|
|
74
79
|
[tool.pytest.ini_options]
|
|
@@ -105,7 +110,7 @@ convention = "pep257"
|
|
|
105
110
|
[tool.ruff.lint.per-file-ignores]
|
|
106
111
|
"tests/**" = ["D"]
|
|
107
112
|
"docs/conf.py" = ["D"]
|
|
108
|
-
"docs/scripts
|
|
113
|
+
"docs/scripts/*.py" = ["T20"]
|
|
109
114
|
|
|
110
115
|
|
|
111
116
|
[tool.mypy]
|
|
@@ -63,17 +63,20 @@ class BesselProcess(BrownianMotion):
|
|
|
63
63
|
"""Generate a realization of a Bessel process."""
|
|
64
64
|
check_positive_integer(n=n, name="Number of increments")
|
|
65
65
|
|
|
66
|
-
samples = [self._sample_brownian_motion(n) for _ in range(self.dim)]
|
|
66
|
+
samples = np.array([self._sample_brownian_motion(n) for _ in range(self.dim)])
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
norms: npt.NDArray[np.float64] = np.sqrt(np.sum(np.square(samples), axis=0))
|
|
69
|
+
return norms
|
|
69
70
|
|
|
70
71
|
def _sample_bessel_process_at(
|
|
71
72
|
self,
|
|
72
73
|
times: npt.NDArray[np.float64],
|
|
73
74
|
) -> npt.NDArray[np.float64]:
|
|
74
75
|
"""Generate a realization of a Bessel process."""
|
|
75
|
-
samples = [self._sample_brownian_motion_at(times) for _ in range(self.dim)]
|
|
76
|
-
|
|
76
|
+
samples = np.array([self._sample_brownian_motion_at(times) for _ in range(self.dim)])
|
|
77
|
+
|
|
78
|
+
norms: npt.NDArray[np.float64] = np.sqrt(np.sum(np.square(samples), axis=0))
|
|
79
|
+
return norms
|
|
77
80
|
|
|
78
81
|
@override
|
|
79
82
|
def sample(self, n: int) -> npt.NDArray[np.float64]:
|
|
@@ -53,12 +53,8 @@ class BrownianExcursion(BrownianBridge):
|
|
|
53
53
|
"""Generate a Brownian excursion."""
|
|
54
54
|
brownian_bridge = self._sample_brownian_bridge(n)
|
|
55
55
|
idx_min = np.argmin(brownian_bridge)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
brownian_bridge[(idx_min + idx) % n] - brownian_bridge[idx_min]
|
|
59
|
-
for idx in range(n + 1)
|
|
60
|
-
]
|
|
61
|
-
)
|
|
56
|
+
indices = (idx_min + np.arange(n + 1)) % n
|
|
57
|
+
s: npt.NDArray[np.float64] = brownian_bridge[indices] - brownian_bridge[idx_min]
|
|
62
58
|
return s
|
|
63
59
|
|
|
64
60
|
def _sample_brownian_excursion_at(
|
|
@@ -75,12 +71,8 @@ class BrownianExcursion(BrownianBridge):
|
|
|
75
71
|
brownian_bridge = self._sample_brownian_bridge_at(times)
|
|
76
72
|
idx_min = np.argmin(brownian_bridge)
|
|
77
73
|
n = len(brownian_bridge)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
brownian_bridge[(idx_min + idx) % (n - 1)] - brownian_bridge[idx_min]
|
|
81
|
-
for idx in range(n)
|
|
82
|
-
]
|
|
83
|
-
)
|
|
74
|
+
indices = (idx_min + np.arange(n)) % (n - 1)
|
|
75
|
+
s: npt.NDArray[np.float64] = brownian_bridge[indices] - brownian_bridge[idx_min]
|
|
84
76
|
|
|
85
77
|
if zero:
|
|
86
78
|
return s
|
|
@@ -7,7 +7,7 @@ import numpy.typing as npt
|
|
|
7
7
|
from numpy.random import Generator
|
|
8
8
|
from scipy.stats import levy
|
|
9
9
|
|
|
10
|
-
from ..utils.validation import check_positive_integer
|
|
10
|
+
from ..utils.validation import check_positive_integer, times_to_increments
|
|
11
11
|
from .brownian_motion import BrownianMotion
|
|
12
12
|
|
|
13
13
|
|
|
@@ -51,17 +51,30 @@ class CauchyProcess(BrownianMotion):
|
|
|
51
51
|
|
|
52
52
|
delta_t = 1.0 * self.t / n
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
levys = np.asarray(
|
|
55
55
|
levy.rvs(
|
|
56
56
|
loc=0,
|
|
57
57
|
scale=delta_t**2 / 2,
|
|
58
58
|
size=n,
|
|
59
59
|
random_state=self.rng,
|
|
60
|
-
)
|
|
60
|
+
),
|
|
61
|
+
dtype=np.float64,
|
|
61
62
|
)
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
return np.insert(self._subordinate(levys), 0, 0.0)
|
|
65
|
+
|
|
66
|
+
def _subordinate(self, levys: npt.NDArray[np.float64]) -> npt.NDArray[np.float64]:
|
|
67
|
+
"""Evaluate the Brownian motion over the increments of the subordinator.
|
|
68
|
+
|
|
69
|
+
The Brownian increments are generated from the increments of the Levy
|
|
70
|
+
subordinator directly. Accumulating the subordinator first and taking
|
|
71
|
+
differences loses the small increments next to a large one.
|
|
72
|
+
"""
|
|
73
|
+
samples = np.cumsum(self.scale * self.rng.normal(scale=np.sqrt(levys)))
|
|
74
|
+
if self.drift != 0:
|
|
75
|
+
samples += self.drift * np.cumsum(levys)
|
|
76
|
+
|
|
77
|
+
return samples
|
|
65
78
|
|
|
66
79
|
def _sample_cauchy_process_at(
|
|
67
80
|
self,
|
|
@@ -74,25 +87,24 @@ class CauchyProcess(BrownianMotion):
|
|
|
74
87
|
else:
|
|
75
88
|
zero = True
|
|
76
89
|
|
|
77
|
-
deltas =
|
|
78
|
-
|
|
90
|
+
deltas = times_to_increments(times=times)
|
|
91
|
+
# Standard Levy variates, scaled per increment.
|
|
92
|
+
standard = np.asarray(
|
|
79
93
|
levy.rvs(
|
|
80
94
|
loc=0,
|
|
81
|
-
scale=
|
|
82
|
-
size=
|
|
95
|
+
scale=1.0,
|
|
96
|
+
size=len(deltas),
|
|
83
97
|
random_state=self.rng,
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
]
|
|
87
|
-
|
|
88
|
-
ts: npt.NDArray[np.float64] = np.cumsum(
|
|
89
|
-
levys, # type: ignore[arg-type]
|
|
98
|
+
),
|
|
99
|
+
dtype=np.float64,
|
|
90
100
|
)
|
|
101
|
+
levys = standard * (deltas**2 / 2)
|
|
91
102
|
|
|
103
|
+
samples = self._subordinate(levys)
|
|
92
104
|
if zero:
|
|
93
|
-
|
|
105
|
+
samples = np.insert(samples, 0, 0.0)
|
|
94
106
|
|
|
95
|
-
return
|
|
107
|
+
return samples
|
|
96
108
|
|
|
97
109
|
@override
|
|
98
110
|
def sample(self, n: int) -> npt.NDArray[np.float64]:
|
|
@@ -138,20 +138,19 @@ class GammaProcess(BaseTimeProcess):
|
|
|
138
138
|
|
|
139
139
|
def _sample_gamma_process_at(self, times: npt.NDArray[np.float64]) -> npt.NDArray[np.float64]:
|
|
140
140
|
"""Sample a Gamma process at specific times."""
|
|
141
|
-
|
|
142
|
-
if
|
|
141
|
+
zero = times[0] == 0
|
|
142
|
+
if not zero:
|
|
143
143
|
times = np.insert(times, 0, [0])
|
|
144
|
-
else:
|
|
145
|
-
s.append(0)
|
|
146
144
|
increments = times_to_increments(times=times)
|
|
147
145
|
|
|
148
146
|
scale = self.variance / self.mean
|
|
149
147
|
shape_coef = self.mean**2 / self.variance
|
|
150
148
|
|
|
151
|
-
|
|
152
|
-
|
|
149
|
+
samples = np.cumsum(self.rng.gamma(shape=shape_coef * increments, scale=scale))
|
|
150
|
+
if zero:
|
|
151
|
+
samples = np.concatenate(([0.0], samples))
|
|
153
152
|
|
|
154
|
-
return
|
|
153
|
+
return samples
|
|
155
154
|
|
|
156
155
|
@override
|
|
157
156
|
def sample(self, n: int) -> npt.NDArray[np.float64]:
|
{samplepaths-0.1.0 → samplepaths-0.2.0}/src/samplepaths/continuous/inverse_gaussian_process.py
RENAMED
|
@@ -122,7 +122,7 @@ class InverseGaussianProcess(BaseTimeProcess):
|
|
|
122
122
|
)
|
|
123
123
|
|
|
124
124
|
assert self.__ms is not None
|
|
125
|
-
ls =
|
|
125
|
+
ls = self.scale * self.__ms**2
|
|
126
126
|
|
|
127
127
|
gn = self.rng.normal(size=n)
|
|
128
128
|
ys = gn**2
|
|
@@ -135,16 +135,9 @@ class InverseGaussianProcess(BaseTimeProcess):
|
|
|
135
135
|
|
|
136
136
|
zs = self.rng.uniform(size=n)
|
|
137
137
|
|
|
138
|
-
ign =
|
|
139
|
-
for z, x, m in zip(zs, xs, self.__ms, strict=True):
|
|
140
|
-
if z <= m / (m + x):
|
|
141
|
-
ign.append(x)
|
|
142
|
-
else:
|
|
143
|
-
ign.append(m**2 / x)
|
|
138
|
+
ign = np.where(zs <= self.__ms / (self.__ms + xs), xs, self.__ms**2 / xs)
|
|
144
139
|
|
|
145
|
-
|
|
146
|
-
ig = np.insert(ig, [0], 0)
|
|
147
|
-
return ig
|
|
140
|
+
return np.concatenate(([0.0], np.cumsum(ign)))
|
|
148
141
|
|
|
149
142
|
@override
|
|
150
143
|
def sample(self, n: int) -> npt.NDArray[np.float64]:
|
|
@@ -163,7 +156,7 @@ class InverseGaussianProcess(BaseTimeProcess):
|
|
|
163
156
|
for k in range(n):
|
|
164
157
|
ms[k] = self._check_mean(times[k], times[k + 1])
|
|
165
158
|
|
|
166
|
-
ls =
|
|
159
|
+
ls = self.scale * ms**2
|
|
167
160
|
|
|
168
161
|
gn = self.rng.normal(size=n)
|
|
169
162
|
ys = gn**2
|
|
@@ -172,14 +165,7 @@ class InverseGaussianProcess(BaseTimeProcess):
|
|
|
172
165
|
|
|
173
166
|
zs = self.rng.uniform(size=n)
|
|
174
167
|
|
|
175
|
-
|
|
176
|
-
for z, x, m in zip(zs, xs, ms, strict=True):
|
|
177
|
-
if z <= m / (m + x):
|
|
178
|
-
ign.append(x)
|
|
179
|
-
else:
|
|
180
|
-
ign.append(m**2 / x)
|
|
181
|
-
|
|
182
|
-
ig = np.array(ign).cumsum()
|
|
168
|
+
ig = np.cumsum(np.where(zs <= ms / (ms + xs), xs, ms**2 / xs))
|
|
183
169
|
if times[0] == 0:
|
|
184
170
|
ig = np.insert(ig, 0, [0])
|
|
185
171
|
|