0

I was hoping someone may be able to clarify something for me. I am trying to do a timeseries forecasting with the GaussianRandomWalk function in PyMC3. I have been suggested that my code is wrong as I’ve modeled it so that the standard deviation of the latent walk is the same as the observation noise, which seems like it might be a mistake. Is it a mistake? How would i change it?

 import pymc3 as pm
#import seaborn as sns
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# generate a random walk

sd = .1
N = 200
deltas = np.random.normal(scale=sd, size=N)
y = np.cumsum(deltas)
x = np.arange(N)
df = pd.DataFrame({‘y’: y})
df = df.reindex(np.arange(250))

with pm.Model() as model:
    sd = pm.HalfNormal(‘sd’)
    mu = pm.Uniform(“mu”, 0, 100)
    prior = pm.GaussianRandomWalk(‘prior’, mu=mu, sd=sd, shape=len(df))

    obs = pm.Normal("obs", mu=prior, sd=sd, observed=df["y"])

    # graph = pm.model_to_graphviz(model)
    # print(graph)

    trace = pm.sample(2000, chains=1)
    pm.traceplot(trace)
    plt.show()

with model:
    ppc = pm.sample_posterior_predictive(trace)
    pm.traceplot(ppc)
    plt.show()
    print(ppc)

Forecast starting after 200

merv
  • 67,214
  • 13
  • 180
  • 245
Bjorn
  • 1
  • The criticism might be justified, and could be addressed by adding another latent `sigma` variable to use for the `sd` argument to the `obs` distribution. However, unless you have multiple observations per step, or very strong and distinct priors on the two sigmas (i.e., measurement error sigma << RW sigma), such a model is unidentifiable. That is, you can't tell what is observational error and what is intrinsic to the random walk. Perhaps the point of the criticism is that that is also implicitly true about your current model. – merv Mar 14 '20 at 17:54

1 Answers1

-1

GuassianRandomWalk is pure random, without any trend/inertia. You might want to look into tfp.sts.LocalLinearTrend or pm.AR which has some "inertia" in it.

I don't know more about how to model timeseries.

buckle2000
  • 139
  • 8