I've posted this in the math SE, but since it's algorithm related, I figured it would fit here as well.
I want to generate a series of random numbers corresponding to a given distribution, but in such a way that each draw is correlated to the previous according to some relation.
Suppose I have a correlation and a Gaussian distribution with mean mu
and standard deviation sigma
. I know that the following algorithm will give me exponentially correlated draws from the Gaussian distribution (algorithm modified from here):
f = exp(-lambda * dt)
r[0] = mu
for n > 0:
g = sigma * randn()
r[n] = f * r[n-1] + sqrt(1 - f^2) * g + mu
An example can be seen in this figure. Here, lambda = 0.1
, mu = 10
, and sigma = 4
.
I'm plotting with two different series, each with a different dt
.
As can be seen in this figure, the resultant series of draws (after enough samples) is approximately Gaussian with the same mu
and sigma
.
How can I achieve this same effect with a gamma distribution?
Aucun commentaire:
Enregistrer un commentaire