Solve Non-linear Least Squares with Ceres given external function

Viewed 28

I'm new to C++ and trying to use Google's Ceres solver for solving a Non-linear Least Squares problem. I'm using an external fortran function that returns 10 values which I want to use as my loss values of the least squares problem. I've already been able to minimize the loss of the function using LBFGS as follows:

void minimizer() {
struct Approx {
  bool operator()(const double* parameters, double* cost) const {
    cost[0] = fortran_minimizer_sum(parameters, additional_params);
    return true;
  }

  static ceres::FirstOrderFunction* Create() {
    constexpr int kNumParameters = 12;
    return new ceres::NumericDiffFirstOrderFunction<Approx,
                                                    ceres::CENTRAL,
                                                    kNumParameters>(new Approx);
  }
};

ceres::GradientProblemSolver::Options options;

ceres::GradientProblemSolver::Summary summary;
ceres::GradientProblem problem(Approx::Create());

ceres::Solve(options, problem, parameters, &summary);

}

Now, how can I use the Trust Region solver of Ceres to to the same with a slightly different fortran function fortran_minimizer that doesn't only have one single cost value but multiple values that I want to use as input to a Non-linear Least Squares solver?

0 Answers
Related