in this Ceres example, SizedCostFunction<1,1>
is used. I would like to change it to CostFunction
since I do not know the size of input parameters during compilation time. I found out that the number of residuals can be easily changed with set_num_residuals(int)
, however, I cannot find a way to set the number of inputs. Could you tell me how to set it?
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;
}
};