Implementing inequality constraints by returning false from cost function

Skip to first unread message

Joseph DeCunha

Mar 23, 2023, 6:01:39 PM3/23/23
to Ceres Solver
Hi all,

I'm trying to implement an inequality constraint by having my cost function return "false" when the function being optimized takes on negative values over a certain range. I haven't had any success using this method however. On the first iteration of the optimizer, the message returned is: "] Terminating: Residual and Jacobian evaluation failed".

I assume this is because, even if I set an initial guess is set which is in a valid region, when numeric differentiation occurs some of the calls to the cost function are in the "forbidden region" preventing the derivative from being calculated.

Primarily, my question is, have others had success using this approach for setting inequality constraints while using numeric differentiation? and if so, can you provide any advice on how to proceed?

Thank you very much,

Joseph DeCunha

Sameer Agarwal

Mar 23, 2023, 6:04:10 PM3/23/23
Hi Joseph, This is indeed a problem with numeric differentiation. It is not aware of manifold or inequality constraints :/

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
To view this discussion on the web visit

Joseph DeCunha

Mar 23, 2023, 6:14:49 PM3/23/23
to Ceres Solver
Thanks for your fast reply!

I will try implementing some penalty terms in the cost function rather than returning false.



Reply all
Reply to author
0 new messages