Min / max for Jet?

297 views
Skip to first unread message

Tobias Nöll

unread,
Jun 28, 2016, 6:20:50 AM6/28/16
to Ceres Solver
Hi,
I am modelling a nonlinear optimization problem using ceres and the autodiff. I really love the overall framework!

For evaluating the objective function I'm using the Jet types for automatic differentiation.
E.g.
T fitVal = *param1 + *param2;
pResidual
[0] = (T)val - fitVal;

This works nice, however, I actually want to make shure that the objective function will be bounded by some range.
E.g.
if(fitVal) < 0.0)
  fitVal  
= (T)0.0;
if(fitVal > 255.0)
  fitVal
= (T)255.0;

However, doing it like this will generate artifacts in the fitted data. Is something like this anyhow possible using the automatic differentiation? Because the modeled function is then not smooth anymore?

Regards
Tobias

Sameer Agarwal

unread,
Jun 28, 2016, 6:26:07 AM6/28/16
to Ceres Solver
You can do this, but as you suspect it will generate non-smooth points. 
my recommendation is to do a smooth approximation to your bound constraint, you can make it as sharp as you like.

--
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/9c11254e-88ed-4eb9-86a6-add5d1aa364c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tobias Nöll

unread,
Jun 28, 2016, 8:24:13 AM6/28/16
to Ceres Solver
Ok, thanks for the hint. This makes sense and I guess it should fix the issue quite efficiently.

I'm generally wondering if doing something like

fitVal = (T)0.0;

is valid or if it breaks the Jet concept, because I assume that the Jet datatype also carries somehow the partial derivatives? So are these invalidated if assigning a fixed value or what is actually happening under the hood?
Regards
Tobias

Keir Mierle

unread,
Jun 28, 2016, 5:54:18 PM6/28/16
to ceres-...@googlegroups.com
Hi Tobias,

You are correct; if you set 

T x = T(0.0)

Then x has no partial derivative associated with it (and so will break the optimization in some cases). Take a look at jet.h to see how it works; it's fairly straightforward.

Thanks,
Keir

Reply all
Reply to author
Forward
0 new messages