DynamicNumericDifferCostFunction
class DynamicNumericDiffCostFunction
与 AutoDiffCostFunction 类似,NumericDiffCostFunction 也要求在编译时已知参数块的数量及其大小。在许多应用中,可能需要在运行时确定。在这种情况下,如果想使用数值微分,则 DynamicNumericDiffCostFunction
就派上用场了。
template <typename CostFunctor, NumericDiffMethodType method = CENTRAL>
class DynamicNumericDiffCostFunction : public CostFunction {
};
和 NumericDifferCostFunction
一样,用户必须定义一个 functor,但是语法略微有所不同,如下所示
struct MyCostFunctor {
bool operator()(double const* const* parameters, double* residuals) const {
}
}
因为参数块的大小是在运行时确定的,因此用户必须在创建动态数值微分对象之后指定参数块的大小和维度,例如下面的程序
auto cost_function = std::make_unique<DynamicNumericDiffCostFunction<
MyCostFunctor>>();
cost_function->AddParameterBlock(5);
cost_function->AddParameterBlock(10);
cost_function->SetNumResiduals(21);
根据经验,在使用 DynamicNumericDiffCostFunction
之前,请尝试使用 NumericDiffCostFunction
。
The same caution about mixing manifolds with numeric differentiation applies as is the case with NumericDiffCostFunction
.
Last updated