Differentiation in unconstrained minimization

287 views
Skip to first unread message

Max Busch

unread,
Jul 25, 2017, 5:02:06 AM7/25/17
to Ceres Solver
Hi everyone, 

it's me again..
My goal is to use ceres to minimize a self-written function. Unfortunately, I haven't got any derivate information, because it's not a "formula-based" function.
I don't unterstand the ceres derivative section, unfortunately.. Are those functions (numerical or auto differetiation) functions to calculate the gradient df/dx for a given function f(x) or are those simply functions to transform existing gradients into a proper form?

Is there anyfunction or way to calculate the gradient numemerically, instead of "hardcoding" it into the FirstOrderFunction (like in the rosenbrock example where the gradient is explicitly calculated)?

This is what I would like to do:
- create my own function:
- I have a function which defines my costs
- but how do I calculate the gradient? Is there a function within ceres I can use?

#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;
}

Thanks in advance and best regards,

Max

Sameer Agarwal

unread,
Jul 27, 2017, 10:50:09 AM7/27/17
to Ceres Solver
Max,
There is no automatic or numeric differentiation for FirstOrderFunction right now.  You can use the autodiff primitives in ceres to implement it, but it will take some work.
Sameer


--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/795de68b-40a5-409c-b941-53375c12a2cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mike Wu

unread,
May 18, 2018, 8:01:36 PM5/18/18
to Ceres Solver
Hi Sameer,

I would also like to do a unconstrained minimization. Is there any support for automatic differentiation for FirstOrderFunction now? If not is there a plan to add it?

Thanks

Sameer Agarwal

unread,
May 23, 2018, 12:32:29 AM5/23/18
to ceres-...@googlegroups.com
Mike,
Unfortunately, I have not had time to do this. But this is something that should be relatively straightforward to do.


Sameer


Reply all
Reply to author
Forward
0 new messages