Ask Your Question
0

How can a monthly GaussianRandomWalk be incorporated into pymc 5 without causing a shape matching error?

asked 2021-05-02 11:00:00 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-04-08 22:00:00 +0000

lakamha gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-05-02 11:00:00 +0000

Seen: 10 times

Last updated: Apr 08 '23