Ceres for curve optimization

151 views
Skip to first unread message

AutoCar

unread,
Sep 14, 2022, 7:22:24 PM9/14/22
to Ceres Solver
Hi, 

I am using Ceres to modify a curve (x, y way points) to make it smoother and shorter. So my reside is sum of absolute curvature along the curve and others. My code is as below. I found the optimization result did not move the curve much from the initial value. What option changes can I use to make the optimization more aggressive?

Problem problem;
 DynamicNumericDiffCostFunction<CostFunctor>* cost_function =
        new DynamicNumericDiffCostFunction<CostFunctor>(
            new CostFunctor(num));

    cost_function->AddParameterBlock((int)num);
    cost_function->AddParameterBlock((int)num);
    cost_function->SetNumResiduals(1);

    std::vector<double*> parameter_block = ...
    problem.AddResidualBlock( cost_function, nullptr,  parameter_block);

    Solver::Options options;
    options.linear_solver_type = ceres::DENSE_QR;
   
    //options.minimizer_progress_to_stdout = true;
    Solver::Summary summary;
    Solve(options, &problem, &summary);

Sameer Agarwal

unread,
Sep 14, 2022, 7:27:01 PM9/14/22
to ceres-...@googlegroups.com
two things.
one, why are you solving this as a sum of squares problem if your objective is already the sum of absolute curvature? by squaring the sum you are only making the objective even more non-linear.
two, is the sum of absolute curvature differentiable?
finally you maybe better off using something like the GradientSolver.
also why you using DynamicNumericDiffCostFunction? 
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/280f63cc-45b8-49e1-8927-9d5b482a46dfn%40googlegroups.com.

Ge Cong

unread,
Sep 14, 2022, 7:52:43 PM9/14/22
to ceres-...@googlegroups.com
User DynamicNumbercDiffCostFunction because curve point number are different from run to run...

Sameer Agarwal

unread,
Sep 14, 2022, 7:53:59 PM9/14/22
to ceres-...@googlegroups.com
if you are going to use nonlinear least squares maybe try to reduce the sum of squared curvature ? and create one residual per point.


Ge Cong

unread,
Sep 14, 2022, 8:17:13 PM9/14/22
to ceres-...@googlegroups.com
Hi Sameer:

Could you provide some sample code about how to use Gradient Solver?

THanks,



On Wed, Sep 14, 2022 at 4:27 PM 'Sameer Agarwal' via Ceres Solver <ceres-...@googlegroups.com> wrote:

Sameer Agarwal

unread,
Sep 14, 2022, 8:19:50 PM9/14/22
to ceres-...@googlegroups.com

Ge Cong

unread,
Sep 14, 2022, 8:42:32 PM9/14/22
to ceres-...@googlegroups.com
Thanks, my number of parameters can not be determined at run time...

Sameer Agarwal

unread,
Sep 14, 2022, 8:44:41 PM9/14/22
to ceres-...@googlegroups.com
it should be relatively straightforward to hack the numeric differentiation routine to support dynamic number of parameters.
Sameer


Ge Cong

unread,
Sep 14, 2022, 9:22:33 PM9/14/22
to ceres-...@googlegroups.com
Seems the version of ceres I have does not have  NumericDiffFirstOrderFunction...

Ge Cong

unread,
Sep 15, 2022, 2:23:03 PM9/15/22
to ceres-...@googlegroups.com
Could you give me some hint how to hack the  numeric differentiation routine to support dynamic number of parameters?

Thank you very much. 

Sameer Agarwal

unread,
Sep 15, 2022, 2:25:56 PM9/15/22
to ceres-...@googlegroups.com
have a look at NumericDiffCostFunction and DynamicNumericDiffCostFunction.
You basically want the latter with just one parameter block.
Sameer


Sameer Agarwal

unread,
Sep 15, 2022, 3:25:33 PM9/15/22
to ceres-...@googlegroups.com
let me see what I can do.
Sameer


Ge Cong

unread,
Sep 15, 2022, 6:06:22 PM9/15/22
to ceres-...@googlegroups.com
Could you let me know which version of ceres started to have NumericDiffFirstOrderFunction?


Sameer Agarwal

unread,
Sep 15, 2022, 6:13:00 PM9/15/22
to ceres-...@googlegroups.com
Try the version of ceres solver at head
with this patch


this allows NumericDiffFirstOrderFunction to take runtime number of arguments.

Sameer


Ge Cong

unread,
Sep 15, 2022, 7:23:49 PM9/15/22
to ceres-...@googlegroups.com

Sameer Agarwal

unread,
Sep 15, 2022, 7:24:42 PM9/15/22
to ceres-...@googlegroups.com
yw, I will clean the patch up and send it out for review shortly. It should be merged in the next day or two.
Sameer


Ge Cong

unread,
Sep 19, 2022, 9:51:48 PM9/19/22
to ceres-...@googlegroups.com
Thank you for your work. This is really helpful. 

I am wondering if you can also add SetParameterLowerBound to GradientProblem?

Thanks,


Sameer Agarwal

unread,
Sep 19, 2022, 9:53:26 PM9/19/22
to ceres-...@googlegroups.com
Sorry the first order optimizer does not support bounds constraints yet.

Reply all
Reply to author
Forward
0 new messages