Cost functions with negative terms: E = (...)^2 - (...)^2 + ....

202 views
Skip to first unread message

Toni Mateos

unread,
Jul 4, 2013, 1:12:19 PM7/4/13
to ceres-...@googlegroups.com
Hi, I need to solve a problem with negative terms in the cost function. By that, I mean that the cost function is of the style:

E(x,y,z) = [ c1 Exp(-c2 x^2) ]^2   -  [ c3 Exp(-c4 x^2) ]^2 +  ...

where c1,...,c4 are constants. I can still prove that E > 0 for all x,y,z given the constants of my problem, i.e. the problem is well-posed. But there is now way to write E as a sum without negative signs.

Is there a way I can run the problem with those minus signs? I tried using a LossFunction with trivial -1 scaling  rho(s) = -s, but there are complaints appearing at run-time in various points of the evaluation.

Help is much welcome!!
Toni


Sameer Agarwal

unread,
Jul 4, 2013, 1:42:12 PM7/4/13
to ceres-...@googlegroups.com
Hi Toni,
Generally speaking problems of this form cannot be solved using Ceres.

In your case if you are certain that your objective function is positive, then you could construct a costfunction which evaluates the square root of the objective function. 

I am not sure how many terms you have in your objective, so this may or may not be an effective way of solving the problem.

Sameer





--
--
----------------------------------------
Ceres Solver Google Group
http://groups.google.com/group/ceres-solver?hl=en?hl=en
 
---
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Toni Mateos

unread,
Jul 5, 2013, 9:30:03 AM7/5/13
to ceres-...@googlegroups.com
Hi Sameer,

I managed to hack in a simple way, and the program is running great now, producing the expected results! 
You might like to consider including this option in future releases, as it really helps (at least, I often encounter problems like these), and it's just a couple of lines.

In the file corrector.xx ,I replaced:

   CHECK_GT(rho[1], 0.0);
   sqrt_rho1_ = sqrt(rho[1]);
   .
   .
   residual_scaling_ =  sqrt_rho1_;

By:

  bool isScalingNegative = (rho[1] < 0) ? true : false;
  if (isScalingNegative) {sqrt_rho1_ = sqrt(-rho[1]);}
  else {sqrt_rho1_ = sqrt(rho[1]);}
  .
  .
  residual_scaling_ = (isScalingNegative) ? -sqrt_rho1_ : sqrt_rho1_;


Note that in my case, where rho is just a sign change, I just have rho[1] = -1, rho[2] = 0.


Thanks!
Toni

Sameer Agarwal

unread,
Jul 5, 2013, 10:19:58 AM7/5/13
to ceres-...@googlegroups.com
Hi Toni,
I am surprised that your hack works, because the underlying math for how the loss functions work does not work anymore.
Sameer

Toni Mateos

unread,
Jul 5, 2013, 10:49:49 AM7/5/13
to ceres-...@googlegroups.com
I know. Actually, the global cost function is perfectly fine, always positive whatever the value of the unknowns. It's just that sometimes it's hard (or impossible) to write it as a sum of positive terms. A simple example is:

E = (x-1)^2  - 1/2  (x-1/2)^2

Which is obviously equivalent to minimizing E = a (x-b) ^2 + c,  where a = 1/2, and b,c are whatever turns out in this case. Clearly, it's perfectly behaved...


You received this message because you are subscribed to a topic in the Google Groups "Ceres Solver" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ceres-solver/PGXge75VpoM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ceres-solver...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages