2

MCMC ルーチンで Boost odeint ライブラリを使用して、ODE モデルのパラメーターを推定するつもりです。これらの ODE はスティッフな可能性があるため、導関数を使用してヤコビアンをソルバーに渡すことができる必要があります。パラメーターと初期値をプライベート メンバーとして持ち、派生、ヤコビアン、およびパラメーターを変更するメソッドをパブリック メソッドとして持つクラスを作成したいと考えています。odeint Web サイトの堅い例を変更して、両方を含む 1 つのクラスを使用しようとしましたが、コンパイル時に「エラー: 'Fitzhugh::deriv() への呼び出しに一致する関数がありません」というエラーが表示されます。私は経験豊富な C++ プログラマーではないので、これはおそらく概念的な間違いです。これがコードです。

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

ここに完全な出力があります

/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
4

1 に答える 1

2

メンバー関数を渡すには、バインド メカニズムを使用する必要があります。C++11 コンパイラを使用している場合は、std::bind; を使用できます。std::placeholders 名前空間を含めます:using namespace std::placeholders;次に、 std::bind from を使用します<functional>:

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

于 2013-09-21T06:07:34.330 に答える