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.
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. Thehead
,tail
, andsegment
functions are available, and as of Stan 2.9 you can do (almost) R-like subsetting with integers or integer arrays, such asfirst:last
. – Masque