Is there any more mid level documentation about using ceres

11 views
Skip to first unread message

Larry Colen

unread,
Dec 5, 2025, 4:54:33 PM (2 days ago) Dec 5
to Ceres Solver
I'm trying to use Ceres to set up curve fitting on a system with multiple parameters. 

Before I work on the actual problem, I'm trying to learn Ceres by setting up a fit on a simple quadratic function with three parameters. 

The challenge that I'm facing is that the documentation is either very simple cookbook, here are some example programs, with few comments in them. Or documentation that goes pretty deep in the weeds about the math. 

I can't seem to find a lot about things like what the parameters for the cost functor need to be.  I have determined that there have to be a certain number of arguments, that they are passed in as pointers to doubles, aka a simple C array.

I can't find explanations for things like what the values in
ceres::AutoDiffCostFunction<QuadraticResidual, 1, 1, 1>
mean. 

At this point I'm just guessing things like
problem.AddResidualBlock() is used for adding another element of cost based
on parameters to a sum which Ceres tries to minimize.  I haven't seen that explicitly 
mentioned anyplace.  

If there is any documentation on things like this, other than wading through all of
the source code, I'd greatly appreciate a pointer to it.

And yes, I have looked through:
 http://ceres-solver.org/nnls_solving.html

But if there is a midlevel overview of Ceres itself, I haven't found it.

Thanks

Sameer Agarwal

unread,
Dec 5, 2025, 4:57:29 PM (2 days ago) Dec 5
to ceres-...@googlegroups.com
Sorry we don't have a lot more.
Happy to answer specific questions.

--
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 visit https://groups.google.com/d/msgid/ceres-solver/ec4741a8-420a-4a12-872a-c61e5d1eb7fan%40googlegroups.com.

Larry Colen

unread,
Dec 5, 2025, 5:24:11 PM (2 days ago) Dec 5
to Ceres Solver
I'm trying to understand Ceres in general well enough to ask questions more specific than "why does my code just return my starting guess after 11 iterations?"

My test code started with the robust_curve_fit program, tried to modify it for more variables.  I can tell, right off hand that this line is wrong:
 problem.AddResidualBlock(cost_function, new ceres::CauchyLoss(0.5), &m, &c);

But it's not obvious how to change it to work with:
        ceres::CostFunction* cost_function =        
            new ceres::AutoDiffCostFunction<QuadraticResidual, 1, 1, 1>(
                new QuadraticResidual(data_v[2 * idx], data_v[2 * idx + 1], poly[0], poly[1], poly[2]));
trimmed_quad_fit.cc

Sameer Agarwal

unread,
Dec 6, 2025, 8:40:25 PM (4 hours ago) Dec 6
to ceres-...@googlegroups.com
sorry took me a bit to get back to this.

There was too many things going in the example code including broken data generation. So here is the corrected version of the code.

To answer the question you asked

  ceres::CostFunction* cost_function =        
            new ceres::AutoDiffCostFunction<QuadraticResidual, 1, 1, 1>(
                new QuadraticResidual(data_v[2 * idx], data_v[2 * idx + 1], poly[0], poly[1], poly[2]));

It should actually be

  ceres::CostFunction* cost_function =
        new ceres::AutoDiffCostFunction<QuadraticResidual, 1, 3>(
            new QuadraticResidual(data_v[2 * idx], data_v[2 * idx + 1]));


You do not need to pass any coefficients to the cost function when constructing it, the template parameters say that it computes a 1 dimensional residual from a 3 dimensional parameter vector.

I should also mention that I am using the version of Ceres Solver at head (and therefore the use of absl rather than glog, but thats a minor change)

Hope this helps,
Sameer




larry.cc
Reply all
Reply to author
Forward
0 new messages