1 | initial version |
To incorporate a monthly GaussianRandomWalk into PyMC5, you can use the RandomWalk
class provided by the pymc4
library.
First, you will need to install pymc4
using pip:
pip install pymc4
Then, you can create a RandomWalk
object with a standard deviation parameter for the Gaussian distribution:
import pymc4 as pm
def monthly_gaussian_random_walk(name, mu, sigma, shape, nsamples):
with pm.Model():
std = pm.HalfNormal('std', sigma=sigma)
values = pm.Normal('values', mu=mu, sigma=std, shape=shape)
# Create the monthly GaussianRandomWalk
rw = pm.RandomWalk('rw', sigma=std, shape=(nsamples, shape))
# Link the values to the GaussianRandomWalk
pm.Deterministic(name, values.cumsum(axis=0) + rw)
return values
This function takes the name of the variable you want to create, the mean mu
, the standard deviation sigma
, the shape of the variable (e.g. (n, 1)
for a 1D array with n
samples), and the number of samples nsamples
.
You can then use this function to create your monthly GaussianRandomWalk variable:
my_variable = monthly_gaussian_random_walk('my_variable', mu=0, sigma=1, shape=(n, 1), nsamples=12)
This will create a variable called my_variable
with a monthly GaussianRandomWalk that has n
samples.