How to use stans integrate_ode x inputs?
Asked Answered
S

0

8

Recently stan has added the integrate_ode method. Unfortunately the only documentation I can find is the stan reference manual (p.191ff). I have a model that would require some driving signal. As I understand the parameter x_r and x_i are supposed to be used for this.

For the sake of a concrete example lets assume I want to implement the example from the documentation with following change:

 real[] sho(real t,
               real[] y,
               real[] theta,
               real[] x_r,
               int[] x_i) {
      real dydt[2];
      real input_signal; // Change from here!!!
      input_signal <- how_to(t, x_r, x_i); 
      dydt[1] <- y[2] + input_signal; // Change to here!!!
      dydt[2] <- -y[1] - theta[1] * y[2];
      return dydt;
}

the input signal is supposed to be a time series that is inputted - let's say I submit input_signal_vector <- sin(t) + rnorm(T, sd=0.1) (which is supposed to be a signal at the time points in ts) and I plan to use for input_signal the closest value in time.

The only way I can imagine is one could concat ts and input_signal_vector in x_r and then a search in this array. But I can not imagine this is the intended use of these parameter. It would also be extremely inefficient.

So if someone could show how such a case is supposed to be solved I would be very grateful.

Start answered 20/12, 2015 at 9:3 Comment(4)
I think you have the right intuition that you would have to pack all (real) inputs into the x_r array, but I don't think the cost of extraction would be noticeable relative to the cost of solving an ODE and doing the autodifferentiation. The head, tail, and segment functions are available, and as of Stan 2.9 you can do (almost) R-like subsetting with integers or integer arrays, such as first:last.Masque
Too bad. But part of my confusion comes from the question how x_r is different from theta. Why did the author choose to use two arrays?Start
Essentially, x_r and x_i allow you to specify constant/fixed parameters that Stan does not learn about. They are referred to as "data" in the manual, since everything that you are not learning about is "data".Scottie
Also, it would be better to send Stan related questions to the Stan users group: groups.google.com/forum/?fromgroups#!forum/stan-usersScottie

© 2022 - 2024 — McMap. All rights reserved.