What exactly happens when a cost function returns false when it is evaluated?

868 views
Skip to first unread message

Stefan R

unread,
Aug 12, 2017, 6:13:16 AM8/12/17
to Ceres Solver
Hi everyone,

I wanted to ask what exactly happens when a cost function returns false when it is evaluated? 

In our application in rare cases there can be Infs or NaNs in the computation inside the cost function, that we catch and return false from the evaluation scope. 
From a previous answer (https://groups.google.com/d/msg/ceres-solver/AnJgpidXqA4/zslk65zFBgAJ) it seems that the solver then stops. I would expect that ceres::Solve() then either yields TerminationType::NO_CONVERGENCE or TerminationType::FAILURE. However, it seems that this is not the case. Instead the solver runs for more iterations and the stops with TerminationType::CONVERGENCE.

Thanks,
Stefan

Sameer Agarwal

unread,
Aug 12, 2017, 1:55:09 PM8/12/17
to Ceres Solver
Stefan,

If the cost function returns false or nans or inf, ceres assumes that the entire objective function evaluation has failed. This has different implications depending upon what stage of the algorithm you are in.

If you are at iteration zero and the evaluation of the cost and the jacobian fails, then the solver will terminate because the starting state of the solver cannot be relied upon.

during the trust region loop, we call evaluate twice. once to evaluate the cost of the candidate solution, if that fails, the candidate solution is treated as if it has infinite cost and the trust region loop runs again with a smaller trust region radius.

If the cost evaluation is successful and the step is deemed to be good and we move to it, we then evaluate the cost and the jacobian, and here if a failure occurs, we have reached a state which cannot be recovered from, therefore the solver terminates.

generally speaking, you can return false to implement a poor man's feasible region, and as long as you start with a feasible point, this will ensure that you remain in it.

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/cc408cc2-9db5-412b-9a3e-cb708cb384fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stefan R

unread,
Aug 12, 2017, 4:56:13 PM8/12/17
to Ceres Solver
Dear Sameer,

thank you for your detailed response. This makes it a lot clearer to me!

One more question regarding the "poor man's feasible region": If I understand correctly I could use the mechanism above to enforce a certain range for valid parameter ranges. What is the advantage of or the difference to the upper and lower bound constraints that Ceres also supports over the former approach?

Thanks!
Stefan

Sameer Agarwal

unread,
Aug 12, 2017, 4:59:30 PM8/12/17
to Ceres Solver
Stefan,
The only real advantage is for feasible regions which are not captured by bounds.
or you do not want to pay the cost of the line search that comes from adding bounds constraints to ceres.
Sameer


Reply all
Reply to author
Forward
0 new messages