在ceres_solver中的模型拟合

时间:2016-12-21 00:11:09

标签: c++ ceres-solver

我正在使用ceres-solver为我的蒙特卡罗(MC)模拟优化一组参数(总共9个)。基本上,MC代码为每组参数返回results = { {1,2,3,...,19} }类型的犰狳双矩阵。我有一组相应的数据。如何使用ceres-solver优化参数?

到目前为止,这是代码:

using ceres::AutoDiffCostFunction;
using ceres::CostFunction;
using ceres::CauchyLoss;
using ceres::Problem;
using ceres::Solver;
using ceres::Solve;

struct SimulationResidual {
SimulationResidual(): y_{346.301,346.312,346.432,346.394,346.471,346.605,346.797,346.948,347.121,347.384,347.626,348.08,348.561,349.333,350.404,351.761,352.975,354.17,354.809} {};
template <typename T> bool operator()(const T* const T_params,
                                      T* residual) const {
    Tm = T_params[0];
    g31= T_params[1];
    g32= T_params[2];
    gg31= T_params[3];
    gg32= T_params[4];
    bn = T_params[5];
    bu = T_params[6];
    mn = T_params[7];
    mu = T_params[8];
    mat Tjumpave = Tjump_ave(); //  MC simulation
    residual[0] =  Tjumpave(0,0) - T(y_[0]);
    residual[1] =  Tjumpave(0,1) - T(y_[1]);
    residual[2] =  Tjumpave(0,2) - T(y_[2]);
    residual[3] =  Tjumpave(0,3) - T(y_[3]);
    residual[4] =  Tjumpave(0,4) - T(y_[4]);
    residual[5] =  Tjumpave(0,5) - T(y_[5]);
    residual[6] =  Tjumpave(0,6) - T(y_[6]);
    residual[7] =  Tjumpave(0,7) - T(y_[7]);
    residual[8] =  Tjumpave(0,8) - T(y_[8]);
    residual[9] =  Tjumpave(0,9) - T(y_[9]);
    residual[10] =  Tjumpave(0,10) - T(y_[10]);
    residual[11] =  Tjumpave(0,11) - T(y_[11]);
    residual[12] =  Tjumpave(0,12) - T(y_[12]);
    residual[13] =  Tjumpave(0,13) - T(y_[13]);
    residual[14] =  Tjumpave(0,14) - T(y_[14]);
    residual[15] =  Tjumpave(0,15) - T(y_[15]);
    residual[16] =  Tjumpave(0,16) - T(y_[16]);
    residual[17] =  Tjumpave(0,17) - T(y_[17]);
    residual[18] =  Tjumpave(0,18) - T(y_[18]);
    return true;
}
private:
    const double y_[19];
};

int main(int argc, char** argv) {
    wall_clock timer;
    timer.tic();
    google::InitGoogleLogging(argv[0]);
    double T_params[] = { Tm,g31,g32,gg31,gg32,bn,bu,mn,mu }; //  initial guess
    Problem problem;
    CostFunction* cost_function =
    new AutoDiffCostFunction<SimulationResidual, 19, 1, 1>
    ( new SimulationResidual() );
    problem.AddResidualBlock(cost_function, new CauchyLoss(0.5), &T_params);
}

在Xcode中使用-lceres和-lglog进行编译时(我安装了eigen3和所有内容。包的示例运行良好而没有错误),我有non-matching member function for call to 'AddResidualBlock'作为错误之一。 如果我需要提供更多信息来帮助您,请告诉我。

感谢。

修改错误发生在problem.AddResidualBlock行。

1 个答案:

答案 0 :(得分:1)

我知道这个问题已经有将近 5 年的历史了,但是您必须通过 T_params,而不是 &T_params,不客气:)