Boost odeint class with derivative and jacobian

caburke

I intend to use the Boost odeint library in an MCMC routine to estimate parameters in an ODE model. Since these ODEs may be stiff, I need to be able to pass the jacobian into the solver with the derivative. I would like to make a class which has the parameters and initial values as private members and then the derivative, jacobian, and methods to change the parameters as public methods. I tried to modify the stiff example from the odeint website to use one class containing both, but am receiving the error 'error: no matching function for call to 'Fitzhugh::deriv()' when comiling. I am not an experienced C++ programmer, so this is likely a conceptual mistake. Here is the code.

/* Fitzhugh Nagumo Equation in odeint */

#include <iostream>
#include <fstream>
#include <utility>
#include <cmath>

#include <boost/numeric/odeint.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/operator.hpp>

using namespace std;
using namespace boost::numeric::odeint;
namespace phoenix = boost::phoenix;

//[ stiff_system_definition
typedef boost::numeric::ublas::vector< double > vector_type;
typedef boost::numeric::ublas::matrix< double > matrix_type;

class Fitzhugh
{
    private:
        double a;
        double b;
        double c;

    public:
        Fitzhugh( double a_, double b_, double c_ ) : a(a_), b(b_), c(c_) { }

        void deriv ( const vector_type &x , vector_type &dxdt , double )
        {
            dxdt[ 0 ] = c*(x[0] - pow(x[0], 3.0)/3.0 + x[1]);
            dxdt[ 1 ] = -(x[0] - a + b*x[1])/c;
        }

        void jac ( const vector_type &x, matrix_type &J , const double &  , vector_type &dfdt )
        {
            J( 0 , 0 ) = c*(1 - pow(x[0], 2.0));
            J( 0 , 1 ) = c;
            J( 1 , 0 ) = -1/c;
            J( 1 , 1 ) = -b/c;
            dfdt[0] = 0.0;
            dfdt[1] = 0.0;
        }
};



int main( int argc , char **argv )
{
//    typedef rosenbrock4< double > stepper_type;
//    typedef rosenbrock4_controller< stepper_type > controlled_stepper_type;
//    typedef rosenbrock4_dense_output< controlled_stepper_type > dense_output_type;
    //[ integrate_stiff_system
    vector_type x( 2 , 1.0 );

    Fitzhugh fitzhugh(0.2, 0.2, 3.0);

    size_t num_of_steps = integrate_const( make_dense_output< rosenbrock4< double > >( 1.0e-6 , 1.0e-6 ) ,
            make_pair( fitzhugh.deriv() , fitzhugh.jac() ) ,
            x , 0.0 , 50.0 , 0.01 ,
            cout << phoenix::arg_names::arg2 << " " << phoenix::arg_names::arg1[0] << "\n" );
    //]
    clog << num_of_steps << endl;


    return 0;
}

Here is the full output

/home/chris/C++/examples/fitzhugh/main.cpp: In function ‘int main(int, char**)’:
/home/chris/C++/examples/fitzhugh/main.cpp:60:39: error: no matching function for call to ‘Fitzhugh::deriv()’
/home/chris/C++/examples/fitzhugh/main.cpp:60:39: note: candidate is:
/home/chris/C++/examples/fitzhugh/main.cpp:30:14: note: void Fitzhugh::deriv(const vector_type&, vector_type&, double)
/home/chris/C++/examples/fitzhugh/main.cpp:30:14: note:   candidate expects 3 arguments, 0 provided
/home/chris/C++/examples/fitzhugh/main.cpp:60:56: error: no matching function for call to ‘Fitzhugh::jac()’
/home/chris/C++/examples/fitzhugh/main.cpp:60:56: note: candidate is:
/home/chris/C++/examples/fitzhugh/main.cpp:36:14: note: void Fitzhugh::jac(const vector_type&, matrix_type&, const double&, vector_type&)
/home/chris/C++/examples/fitzhugh/main.cpp:36:14: note:   candidate expects 4 arguments, 0 provided
mariomulansky

to pass member function you need to use a bind mechanism. if you have a c++11 compiler you can use std::bind; include the std::placeholders namespace: using namespace std::placeholders; then use std::bind from <functional>:

make_pair( bind( &Fitzhugh::deriv , &fitzhugh , _1 , _2 , _3 ) , bind( &Fitzhugh::jac , &fitzhugh , _1 , _2 , _3, _4 ) )

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

boost::odeint called within member class

From Dev

boost::odeint called within member class

From Dev

returning derivatives with boost odeint

From Dev

DDE using boost odeint

From Dev

returning derivatives with boost odeint

From Dev

Boost lib error in using odeint

From Dev

Using Boost::odeint with Eigen::Matrix as state vector

From Dev

error with installing odeint <boost/config.hpp>

From Dev

does boost odeint have a leapfrog algorithm?

From Dev

Accurate multidimensional integral using boost odeint

From Dev

role of get_unit_value in boost ODEINT

From Dev

does boost odeint have a leapfrog algorithm?

From Dev

Using Boost::odeint with Eigen::Matrix as state vector

From Dev

using several eigen matrices as statetypes in boost/odeint

From Dev

C++ derivative class with virtual function

From Dev

Error C2309 in boost odeint package example code

From Dev

Second order differential equation using C++ Boost odeint library

From Dev

Assertion error in a simple C++ program using boost:odeint

From Dev

Can't get BOOST odeint to work with Adams-Bashforth-Moulton

From Dev

wrong output of boost::odeint with custom tensor data structure

From Dev

Segmentation fault in boost::odeint my_vector.cpp example

From Dev

how to control the order of bulirsch_stoer method in boost::odeint?

From Dev

Segmentation fault in boost::odeint my_vector.cpp example

From Dev

wrong output of boost::odeint with custom tensor data structure

From Dev

Armadillo's cx_mat and Boost's odeint compilation error

From Dev

Calling ODE solver (odeint) within c++ class

From Dev

Template based member initialisation, where the template is a derivative of an abstract class

From Dev

Template based member initialisation, where the template is a derivative of an abstract class

From Dev

Template parameters of `boost::numeric::odeint::runge_kutta-X` compatible with CUDA/OpenMP

Related Related

  1. 1

    boost::odeint called within member class

  2. 2

    boost::odeint called within member class

  3. 3

    returning derivatives with boost odeint

  4. 4

    DDE using boost odeint

  5. 5

    returning derivatives with boost odeint

  6. 6

    Boost lib error in using odeint

  7. 7

    Using Boost::odeint with Eigen::Matrix as state vector

  8. 8

    error with installing odeint <boost/config.hpp>

  9. 9

    does boost odeint have a leapfrog algorithm?

  10. 10

    Accurate multidimensional integral using boost odeint

  11. 11

    role of get_unit_value in boost ODEINT

  12. 12

    does boost odeint have a leapfrog algorithm?

  13. 13

    Using Boost::odeint with Eigen::Matrix as state vector

  14. 14

    using several eigen matrices as statetypes in boost/odeint

  15. 15

    C++ derivative class with virtual function

  16. 16

    Error C2309 in boost odeint package example code

  17. 17

    Second order differential equation using C++ Boost odeint library

  18. 18

    Assertion error in a simple C++ program using boost:odeint

  19. 19

    Can't get BOOST odeint to work with Adams-Bashforth-Moulton

  20. 20

    wrong output of boost::odeint with custom tensor data structure

  21. 21

    Segmentation fault in boost::odeint my_vector.cpp example

  22. 22

    how to control the order of bulirsch_stoer method in boost::odeint?

  23. 23

    Segmentation fault in boost::odeint my_vector.cpp example

  24. 24

    wrong output of boost::odeint with custom tensor data structure

  25. 25

    Armadillo's cx_mat and Boost's odeint compilation error

  26. 26

    Calling ODE solver (odeint) within c++ class

  27. 27

    Template based member initialisation, where the template is a derivative of an abstract class

  28. 28

    Template based member initialisation, where the template is a derivative of an abstract class

  29. 29

    Template parameters of `boost::numeric::odeint::runge_kutta-X` compatible with CUDA/OpenMP

HotTag

Archive