我正在使用ceres-solver为我的 Monte-Carlo (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);
}
当使用 -lceres 和 -lglog 在 Xcode 中编译时(并且我安装了 eigen3 并且所有内容都安装了。包的示例运行良好,没有错误),我有non-matching member function for call to 'AddResidualBlock'
一个错误。如果我需要提供更多信息来帮助您帮助我,请告诉我。
谢谢。
编辑错误就problem.AddResidualBlock
行了。