Ceres 求解器在任何地方都表明它可以
[...] 解决鲁棒边界约束非线性最小二乘问题
并且它支持参数块的上限和下限约束(例如在http://ceres-solver.org/modeling_faqs.html它指出Ceres Solver only supports upper and lower bounds constraints on the parameter blocks
),但不知何故我无法在文档中找到如何设置这些上限和下限。
那么,如何在 ceres 求解器中设置参数块的上限和下限?
具体来说,我该怎么做AutoDiffCostFunction
?如果我使用if
语句返回一个非常大的超出范围的残差,那么该函数是不可微的。
例如,这是 ceres Hello World:
struct CostFunctor {
template <typename T>
bool operator()(const T* const x, T* residual) const {
residual[0] = 10.0 - x[0];
return true;
}
};
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, nullptr, &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;
}
在这个例子中,我将如何对参数 x 施加 2.0 的下限和 20.0 的上限?