I am trying to use integrate_ode_rkf to perform a double definite integration \int_{0}^{x}\int_{0}^{y}f(x, y)dydx. The basic idea is that the first integration wrt y takes place in a user-defined function (of x) and that function is then integrated wrt x to give the result.
The following Stan code is apparently ‘syntactically correct’:
functions {
// Example integrand
real[] integrand_ode(real y, real[] f, real[] theta, real[] x_r, int[] x_i) {
real df_dx[1];
df_dx[1] = exp(-square(y) - x_r[1]^2) ;
return(df_dx);
}
//User-defined function of x after y integrated out
real ode_integrate(real x, real[] f, real[] theta, real[] xx_r, int[] x_i) {
return(integrate_ode_rk45(integrand_ode,
rep_array(0.0, 1),
0,
rep_array(1.0, 1),
rep_array(0.0, 0),
rep_array(x, 1),
x_i)[1,1]);
}
// Final integration wrt x
real ode_integrate2( ) {
return(integrate_ode_rk45( ode_integrate,
rep_array(0.0, 1),
0,
rep_array(1.0, 1),
rep_array(0.0, 0),
rep_array(0.0, 0) ,
rep_array(0, 0))[1,1]);
}
}
data {
}
model {}
but when I use expose_stan_functions an error is generated. In the masses of output (which I can happily attach if it is needed) the key points seem to be
In file included from /Users/Jeremy1/Rlibs/StanHeaders/include/stan/math/prim/arr.hpp:37:
/Users/Jeremy1/Rlibs/StanHeaders/include/stan/math/prim/arr/functor/coupled_ode_system.hpp:98:15: error: no viable overloaded '='
dy_dt = f_(t, y, theta_dbl_, x_, x_int_, msgs_);
~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/Jeremy1/Rlibs/BH/include/boost/numeric/odeint/stepper/dense_output_runge_kutta.hpp:329:13: note: in instantiation of member function 'stan::math::coupled_ode_system<ode_integrate_functor__, double, double>::operator()' requested here
sys( get_current_state() , get_current_deriv() , m_t );
^
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/vector:537:13: note: candidate function not viable: no known conversion from 'double' to 'const std::__1::vector<double, std::__1::allocator<double> >' for 1st argument
vector& operator=(const vector& __x);
The problem is with the final stage of the integration but I do not know what the error messages mean.