#include "ceres/ceres.h"
using ceres::AutoDiffCostFunction;
using ceres::CostFunction;
using ceres::Problem;
using ceres::Solver;
using ceres::Solve;
class myfunction : public ceres::FirstOrderFunction {
public:
virtual ~myfunction() {}
virtual bool Evaluate(const double* parameters,
double* cost,
double* gradient) const {
cost[0] = MY_FUNCTION_EVALUATION(parameters); // exists
if (gradient != NULL) {
// I do not have any explicit information on the gradient
// Is there any function I can use to calculate the gradient numerically
// and not "hardcode" it explicitly?
}
return true;
}
virtual int NumParameters() const { return 2; }
};
int main(int argc, char** argv)
{
double parameters[2] = ...;
ceres::GradientProblemSolver::Options options;
options.minimizer_progress_to_stdout = true;
ceres::GradientProblemSolver::Summary summary;
ceres::GradientProblem problem(new myfunction());
ceres::Solve(options, problem, parameters, &summary);
std::cout << summary.FullReport() << "\n";
return 0;
}