GaussianRandomWalk (original) (raw)

@pymc-bot Is it possible to have a GaussianRandomWalk with more than just the time dimension (e.g. having 10 uncorrelated random walks being modelled as a single variable)? I seem to be getting dimension errors every time I add a new dimension to the random walk.

It is possible, but curious to see if the bot is useful here…

Let’s see what it says :slight_smile: I’m running into shape issues, still haven’t figured out if it’s a matter of the init_dist or sigma not being well specified. Do you know of any examples I could learn from?

pymc-bot April 23, 2025, 3:29pm 6

To model multiple uncorrelated Gaussian random walks in PyMC, you can use the pm.GaussianRandomWalk distribution and specify the additional dimensions using the dims argument. Here’s an example of how you can set up a model with 10 uncorrelated random walks:

import pymc as pm
import pytensor as pt

# Define the number of time steps and the number of random walks
n_timesteps = 100
n_walks = 10

# Create a PyMC model
with pm.Model() as model:
    # Add a coordinate for the number of random walks
    model.add_coord('walks', range(n_walks))
    
    # Define the Gaussian random walk with an additional dimension for the walks
    random_walks = pm.GaussianRandomWalk('random_walks', sigma=1, dims=('walks', 'time'))

    # Sample from the model
    trace = pm.sample()

# The trace will contain samples for each of the 10 random walks over the specified time steps

Key Points:

This setup should help you avoid dimension errors by clearly defining the structure of your random walks. If you encounter any specific errors, please provide more details so I can assist further.

This answer was generated by the PyMC Assistant bot in response to your command. Please let us know if it was helpful!

Yeah that was terrible response.

To answer myself, shape issues usually happen because GaussianRandomWalk requires time to be the rightmost dimension and only allows one sigma / drift per random walk. If you want sigma/ drift to change over time you need to use a CustomDist as mentioned in this recent thread: Can't use GaussianRandomWalk output as sigma for another GaussianRandomWalk - #2 by ricardoV94

Do you mean more than one dimension of evolution, like in a spatial or spatio-temporal model as opposed to the 1D evolution of a time series? Or do you just mean there’s a 10-vector evolving over time rather than just a scalar?

Just one dimension of evolution, so the latter:10-vector evolving over time, each with its own random walk, uncorrelated with each other. I’ve tried specifying 10 independent ones with a loop, but it was painfully slow

Just pass shape=(10, t) possible with 10 different sigma/drifts