2

在 ceres 求解器http://ceres-solver.org/nnls_tutorial.html的非线性最小二乘教程中, 给出了以下示例:

int main(int argc, char** argv) {
  google::InitGoogleLogging(argv[0]);

  // The variable to solve for with its initial value.
  double initial_x = 5.0;
  double x = initial_x;

  // Build the problem.
  Problem problem;

  // Set up the only cost function (also known as residual). This uses
  // auto-differentiation to obtain the derivative (jacobian).
  CostFunction* cost_function =
      new AutoDiffCostFunction<CostFunctor, 1, 1>(new CostFunctor);
  problem.AddResidualBlock(cost_function, NULL, &x);

  // Run the solver!
  Solver::Options options;
  options.linear_solver_type = ceres::DENSE_QR;
  options.minimizer_progress_to_stdout = true;
  Solver::Summary summary;
  Solve(options, &problem, &summary);

  std::cout << summary.BriefReport() << "\n";
  std::cout << "x : " << initial_x
            << " -> " << x << "\n";
  return 0;
}

堆分配的成本函数和仿函数永远不会被删除。这只是示例的简化,还是 Ceres 拥有这些对象的所有权并删除它们?

4

1 回答 1

0

是的,它需要功能的所有权。您可以使用以下标志更改此行为。

http://ceres-solver.org/nnls_modeling.html#_CPPv4N5ceres7Problem7Options23cost_function_ownershipE

于 2020-12-22T11:13:30.530 回答