Visual C++ Odeint integrate
I'm trying to use integrate_const
in Visual C++, as part of a class with an overloaded operator()
. Why is the compiler failing to specialize the template?
size_t steps = boost::numeric::odeint::integrate_const(stepper, *this, x, tbegin, tfinal, dt, obs);
I'm getting IntelliSense and compilation errors saying:
no instance of overloaded function "boost::numeric::odeint::integrate_const" matches the argument list c:Users...srcduffing.cpp 81
Further, it gives the message:
Error C2893 Failed to specialize function template 'size_t boost::numeric::odeint::integrate_const(Stepper,System,const State &,Time,Time,Time,Observer)' aimsexamples C:Users...srcduffing.cpp 81
Error C2893 Failed to specialize function template 'size_t boost::numeric::odeint::integrate_const(Stepper,System,State &,Time,Time,Time,Observer)' aimsexamples C:Users...srcduffing.cpp 81
ADDITIONAL INFO (edited):
Header
typedef std::vector<double> state_type;
struct push_back_state_and_time
{
std::vector< state_type >& m_states;
std::vector< double >& m_times;
push_back_state_and_time(std::vector< state_type > &states, std::vector< double > ×)
: m_states(states), m_times(times) { }
void operator()(const state_type &x, double t)
{
m_states.push_back(x);
m_times.push_back(t);
}
};
class duffingmodel: public forwardmodel
{
private:
uint64_t num_timesteps;
double dt;
std::vector<double> param;
// 'params' is accessible from 'operator()'
// the argument to loglikelihood is copied into 'params'
std::vector<double> data;
// 'data' populated in constructor
// loglikelihood compares a simulation done with different parameters with entries in 'data'
public:
duffingmodel(duffingmodelbuilder const &); // Populates 'data'
double loglikelihood(std::vector<double> const &); // Calls the 'integrate_const'
void operator()(state_type const &, state_type &, const double); // state-derivative
};
Implementation
// state-derivative operator
void duffingmodel::operator()(state_type const &x, state_type &dxdt, const double /*t*/)
{
dxdt[0] = x[1];
dxdt[1] = -this->param[0] * x[1] - this->param[1] * x[0] - this->param[2] * pow(x[0], 3) + this->param[3] * cos(x[2]);
dxdt[2] = this->param[4];
}
// function that does the calculations
double duffingmodel::loglikelihood(std::vector<double> const &s)
{
uint64_t n; // Iterator
double term, val = 0.0;
state_type x(3);
std::vector<double> times;
std::vector<state_type> x_vec;
x[0] = s[5];
x[1] = s[6];
x[2] = 0.0;
double tbegin = 0.0;
double tfinal = ((double)(this->num_timesteps - 1)) * this->dt;
double dt = this->dt;
this->param = s;
boost::numeric::odeint::runge_kutta4<state_type> stepper;
// *** Offending line of code ***
size_t steps = boost::numeric::odeint::integrate_const(stepper, *this, x, tbegin, tfinal, dt, push_back_state_and_time(x_vec, times));
// Just calculations...not relevant to the integral
for (n = 0u; n < this->num_timesteps; n++)
{
term = data[n] - x_vec[n][0];
val += term * term;
}
val = 0.5 * val * exp(-2.0 * s[7]);
val += -0.5 * (double) (this->num_timesteps) * log(2.0 * M_PI) - (double) (this->num_timesteps) * s[7];
return val;
}
Calling program
int main()
{
// Create a builder struct and populate its members
duffingbuilder a;
a.dt = 0.01;
a.num_timesteps = 1000;
a.dataxinit = 0.0;
a.datavinit = 0.0;
a.dataalpha = 1.0;
a.databeta = 0.0;
// etc etc
// Construct the duffingmodel
duffingmodel x(a);
// Define a point at which to evaluate the loglikelihood member
std::vector<double> p(8);
p[0] = 1.01;
// p[1] = ...;
//...
p[7] = -1.0;
double ll = duffingmodel.loglikelihood(p);
// Print everything out
std::cout << "Likelihood f(D;p) = " << p << std::endl;
return 0;
}
Compiler Errors
Severity Code Description Project File Line Suppression State
Error C2672 'boost::numeric::odeint::integrate_const': no matching overloaded function found aimsexamples C:UsersPinakyDesktopaims-2016aimsexamplessrcduffing.cpp 81
Error C2780 'size_t boost::numeric::odeint::integrate_const(Stepper,System,const State &,Time,Time,Time)': expects 6 arguments - 7 provided aimsexamples C:UsersPinakyDesktopaims-2016aimsexamplessrcduffing.cpp 81
Error C2780 'size_t boost::numeric::odeint::integrate_const(Stepper,System,State &,Time,Time,Time)': expects 6 arguments - 7 provided aimsexamples C:UsersPinakyDesktopaims-2016aimsexamplessrcduffing.cpp 81
Error C2893 Failed to specialize function template 'size_t boost::numeric::odeint::integrate_const(Stepper,System,const State &,Time,Time,Time,Observer)' aimsexamples C:UsersPinakyDesktopaims-2016aimsexamplessrcduffing.cpp 81
Error C2893 Failed to specialize function template 'size_t boost::numeric::odeint::integrate_const(Stepper,System,State &,Time,Time,Time,Observer)' aimsexamples C:UsersPinakyDesktopaims-2016aimsexamplessrcduffing.cpp 81
Error C2780 'size_t boost::numeric::odeint::integrate_const(Stepper,System,const State &,Time,Time,Time,Observer,StepOverflowChecker)': expects 8 arguments - 7 provided aimsexamples C:UsersPinakyDesktopaims-2016aimsexamplessrcduffing.cpp 81
Error C2780 'size_t boost::numeric::odeint::integrate_const(Stepper,System,State &,Time,Time,Time,Observer,StepOverflowChecker)': expects 8 arguments - 7 provided aimsexamples C:UsersPinakyDesktopaims-2016aimsexamplessrcduffing.cpp 81
链接地址: http://www.djcxy.com/p/86330.html
上一篇: 用模板进行C ++懒惰评估
下一篇: Visual C ++ Odeint集成