【问题标题】:Ceres solver - Set size of parameter block of CostFunctionCeres 求解器 - 设置 CostFunction 参数块的大小
【发布时间】:2022-11-15 00:20:57
【问题描述】:

在这个 Ceres 示例中,使用了 SizedCostFunction<1,1>。我想将其更改为CostFunction,因为我不知道编译期间输入参数的大小。我发现使用set_num_residuals(int) 可以轻松更改残差数,但是我找不到设置输入数的方法。能告诉我怎么设置吗?

class QuadraticCostFunction
    : public SizedCostFunction<1 /* number of residuals */,
                               1 /* size of first parameter */> {
 public:
  bool Evaluate(double const* const* parameters,
                double* residuals,
                double** jacobians) const override {
    double x = parameters[0][0];
    // f(x) = 10 - x.
    residuals[0] = 10 - x;
   
    if (jacobians != nullptr && jacobians[0] != nullptr) {
      jacobians[0][0] = -1;
    }
    return true;
  }
};

【问题讨论】:

    标签: c++ ceres-solver


    【解决方案1】:

    您可以从QuadraticCostFunction 调用这些受保护的CostFunction 成员函数:

    set_num_residuals(num);
    *mutable_parameter_block_sizes() = std::vector<int32_t>{ /* size_1, ..., size_num */ };
    

    您似乎不需要继承SizedCostFunction

    class QuadraticCostFunction
        : public CostFunction {
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-13
      • 1970-01-01
      • 1970-01-01
      • 2015-03-28
      • 1970-01-01
      • 2021-11-19
      相关资源
      最近更新 更多