Sampling a new variable makes model unstable

Dear all,

While trying to implement a Multivariate Linear Dynamical System (state-space model) in Pyro, we ran into a surprising problem: the sampling of a specific variable seems to make the whole model unstable.

Attached are the model’s predictions before and after the sampling in question, so you can see for yourself. The full code is accessible here under the section “Pyro sampling influence”: https://github.com/Jacques-29/mbml-project/blob/master/Pyro%20Forum.ipynb

Can someone give an explanation to this?

Best regards,
Jacques

Note: we are using Google Collaboratory for running the notebook.

Hi @Jacques, this is strange. I was a bit worried that this is the problem of your model, where you use MCMC to sample forecast values. There is a similar thread (see also my comment there) which discussed the instability when we switch the order of the variables in the model. I don’t think that the model

def model(data):
    sigma = sample('x', Exponential(0, 1))
    sample('data', Normal(0, sigma), obs=data)
    sample('forecast', Normal(0, sigma), obs=None)

will give something useful. For that model, forecast will concentrate around 0. Maximizing probability of forecast will lead to small sigma. But small sigma will lead to small probability of data

What happens if you just use MCMC to get posterior samples, rather than to get forecasting values?

Hi @fehiepsi, thanks for your answer. Indeed it seems that when using MCMC only for prior sampling the model converges. I tested by setting our T_forecast to 0 and the samples of e.g. B seem to be coherent. See images below.

However, I’m now wondering what would be the correct way of forecasting in our case. I looked at the tutorial here: https://pyro.ai/numpyro/time_series_forecasting.html, but I am not sure as to how to implement it in our case. Any suggestions?

Regards,
Jacques

Whoa, it is nice to see that disabling forecasting works for you! I do agree that that tutorial is not a good place to demonstrate forecasting. For many situations like your model, you can just add a condition: if T_forecast > 0: sample(‘pred’, …) to your model. In MCMC, you run with argument T_forecast=0. After getting mcmc samples, you just simply run Predictive(model, samples)(rngkey, data, T_forecast=100). Please let me know if it works or you need a concrete example. I’ll update the forecasting tutorial in the mean time.

1 Like

@Jacques I have made a PR to update the notebook with the usage of Predictive (with just 2 lines of code). You can see its rendered version here. Please let me know if you have any suggestion to improve the content. :slight_smile:

Hi @fehiepsi, thanks a lot for your time and effort. With your suggestions I will try to implement a new model, and when I get some results I will let you know. :wink: