crflynn / stochastic

Generate realizations of stochastic processes in python.
http://stochastic.readthedocs.io/en/stable/
MIT License
451 stars 80 forks source link

Sampling from `FractionalGaussianNoise` and `ColoredNoise` leads to arrays of different size #77

Open JoseAlanis opened 1 year ago

JoseAlanis commented 1 year ago

Hi,

sampling from FractionalGaussianNoise and ColoredNoiseas follows:

import stochastic.processes.noise as sn
import numpy as np

rng = np.random.default_rng(seed=42)

n = 10000

br_noise = sn.ColoredNoise(beta=2.0, rng=rng).sample(n)
fr_noise =  sn.FractionalGaussianNoise(hurst=0.5, rng=rng).sample(n)

Results in arrays of unequal length:


br_noise.shape
# Out: (10001,)

fr_noise.shape
# Out: (10000,)

Is this the intended behaviour?

I believe both classes internally check that n is a positive integer. However, ColoredNoise then does n = n + 1 https://github.com/crflynn/stochastic/blob/90ffba84523751dd205e17c50c84be9904c13330/stochastic/processes/noise/colored_noise.py#L68