Visual C ++ Odeint集成

我试图在Visual C ++中使用integrate_const ,作为带有重载operator()的类的一部分。 为什么编译器无法专门化模板?

size_t steps = boost::numeric::odeint::integrate_const(stepper, *this, x, tbegin, tfinal, dt, obs);

我收到了IntelliSense和编译错误:

没有重载函数“boost :: numeric :: odeint :: integrate_const”的实例匹配参数列表c: Users ... src duffing.cpp 81

此外,它给出了消息:

错误C2893未能特化函数模板'size_t boost :: numeric :: odeint :: integrate_const(步进器,系统,常量状态&,时间,时间,时间,观察者)'aimsexamples C: Users ... src duffing .cpp 81
错误C2893未能特化函数模板'size_t boost :: numeric :: odeint :: integrate_const(步进器,系统,状态和时间,时间,时间,观察者)'aimsexamples C: Users ... src duffing。 cpp 81


其他信息 (编辑):

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 > &times)
        : 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
};

履行

// 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;
}

调用程序

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;
}

编译器错误

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/86329.html

上一篇: Visual C++ Odeint integrate

下一篇: Avoiding the main (entry point) in a C program