3

I'm trying to infer parameters of a stochastic dynamical system using pymc3. I have a theano expression that seems to come together without errors, but I can't seem to compile it, which I was hoping to do in order to generate toy data for fitting. My model is

dx/dt = ax(t) - x(t)^3 + epsilon (i.e. epsilon is some state noise)

epsilon ~ Normal(0, sigma^2)

The plan is to set up epsilon, sigma, and a with prior distributions in pymc3 and use theano.scan to integrate the differential equation. I then need to generate some data, which I figure I can do by compiling the output of scan into a python function which I would run with fixed values for sigma, a, and x(0). Here's where I'm at so far:

import theano.tensor as T
import theano
import pymc3 as mc

with mc.Model() as model:
    # Time-related variables for performing the integration
    dt = T.fscalar('dt')
    tau = T.fscalar('tau')
    steps = T.cast(tau / dt, 'int32')
    
    x = mc.Uniform('x', lower=-10, upper=10)
    a = mc.Gamma('a', 1, 1)
    sigma = mc.Gamma('sigma', mu=1, sd=1)
    epsilon = mc.Normal('epsilon', mu=0, sd=sig_s)
    
    # Symbolic loop through Euler updates
    xout, updates = theano.scan(fn=lambda x, sigma, a, dt: x + dt * (a * x - x**3) + T.sqrt(dt) * epsilon,
                                outputs_info=x,
                                non_sequences=[sigma, a, dt],
                                n_steps=steps)

    simulation = theano.function(inputs=[x, sigma, a, dt, tau],
                           outputs=xout,
                           updates=updates,
                           allow_input_downcast=True)

The last line gives me

MissingInputError: ("An input of the graph, used to compute for{cpu,scan_fn}(Elemwise{Cast{int32}}.0, IncSubtensor{Set;:int64:}.0, sigma, a, dt, epsilon), was not provided and not given a value.Use the Theano flag exception_verbosity='high',for more information on this error.", epsilon)

(the verbosity flag does nothing).

One thing I am not sure of is how pymc3 random variables work inside scan. If I provide a value for sigma, will epsilon draw a new random value at each iteration of the loop? Do I need to give epsilon a size?

Community
  • 1
  • 1
Noah
  • 196
  • 10
  • Theano is telling you that a variable named ```epsilon``` is used to define an operation buy not defined. You forgot to add ```epsilon``` to your lambda function. – aloctavodia Aug 23 '16 at 05:36

0 Answers0