Weighting based on 2 residual blocks

122 views
Skip to first unread message

Adit

unread,
Dec 28, 2017, 11:45:52 AM12/28/17
to Ceres Solver

Hello all,

I am using LM for my problem, where I have around 120 equations and need to determine the values of parameters a,b,c (depending on the experiment I have three to eight variables). The equations are non linear with a,b,c in the powers of 1 to cubic. I am quite happy w the performance of ceres. My question is, is there a way to implement weighted residuals, where the weighting is dependent on two separate ceres Residual Blocks?
And is there a way to do this without changing the cost function equations (see definitions below)? I need to implement these two weightings:

 

Weightings:


1. residual_new1 = res1^2/ (const)

 

where res1^2 = summation(i=1:N) { [ (y_abc - y_abc_calc)^2 + (y_abc_C2 - y_abc_C2_calc)^2] / [y_abc^2 + y_abc_C2^2] }

 

where y_abc and y_abc_C2 are from two different cost functions as defined below.

 

2. residual_new2 = res2^2/ (const)

 

where res2^2 = summation(i=1:N) { [ (y_abc - y_abc_calc)^2 / (y_abc^2) ] + [(y_abc_C2 - y_abc_C2_calc)^2 / (y_abc_C2^2) ] }

 

where y_abc and y_abc_C2 are from two different cost functions as defined below.

 

DEFINITIONS of the ceres problem and the residual blocks:

 

DEFINE_string(minimizer, "trust_region",
   "Minimizer type to use, choices are: line_search & trust_region");
Solver::Options options_smart;
   options_smart.trust_region_strategy_type = ceres::LEVENBERG_MARQUARDT;
   options_smart.max_num_iterations = 500;
   options_smart.linear_solver_type = ceres::DENSE_QR;
   options_smart.minimizer_progress_to_stdout = true;

   Problem problem;
   double a, b, c;
    for (int i = 0; i < logf.size(); ++i) {
         eqn_abc_t *eqn_abc_1 = new eqn_abc_t(logf[i], Zr[i]);
         problem.AddResidualBlock(new AutoDiffCostFunction<eqn_abc_t, 1, 1, 1, 1>(eqn_abc_1), NULL, &a, &b, &c);
         eqn_C2_abc_t *eqn_C2_abc_1 = new eqn_C2_abc_t(logf[i],ZC2[i]);        
         problem.AddResidualBlock(new AutoDiffCostFunction<eqn_C2_abc_t, 1, 1, 1, 1>(eqn_C2_abc_1), NULL, &a, &b, &c);
      }

      Solver::Summary summary;
      Solve(options_smart, &problem, &summary);

The cost functions:

class eqn_abc_t{
public:
   eqn_abc_t(double x, double y)
      : x_(x), y_(y) {}
   template <typename T>
   bool operator()(const T* const a, const T* const b, const T* const c, T* residual) const {
      residual[0] = (T(y_) - a[0])*(1.0 + (4.0 * Pisq * pow(10, T(x_)) * pow(10, T(x_)) * b[0] * b[0] * c[0] * c[0]))
         - b[0];
      return true;
   } 
private:
   const double x_;
   const double y_;
};

class eqn_C2_abc_t{
public:
   eqn_C2_abc_t(double x, double y)
      : x_(x), y_(y) {}
   template <typename T>
   bool operator()(const T* const a, const T* const b, const T* const c, T* residual) const {
      residual[0] = T(y_) + (T(y_) * (4.0 * Pisq * pow(10, T(x_)) * pow(10, T(x_)) * b[0] * b[0] * c[0] * c[0]))
         - (b[0] * b[0] * 2.0 * Pi * c[0] * pow(10, T(x_)));
      return true;
   }
private:
   const double x_;
   const double y_;
};

Thanks.

 

-Adit

Sameer Agarwal

unread,
Dec 29, 2017, 5:12:31 AM12/29/17
to ceres-...@googlegroups.com

There is no automatic way to do this.
I am curious though, why are you trying to do this?


--
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/46614c29-f03c-4e54-b065-788d5b46b025%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adit

unread,
Dec 29, 2017, 10:33:07 AM12/29/17
to Ceres Solver
In certain cases of the problem I am working with, I have seen that weighting the individual points shows a better performance in optimization performance, particularly the second weighting equation above (tested in Matlab). Is there a better way to implement weighting for the individual points in Ceres? Thanks.

Adit

Sameer Agarwal

unread,
Dec 29, 2017, 11:31:38 AM12/29/17
to ceres-...@googlegroups.com
are you hoping to change the weighting every iteration as the residual changes?

Aditya Gupta

unread,
Dec 29, 2017, 11:38:38 AM12/29/17
to ceres-...@googlegroups.com
No not every iteration. The weight is dependent on the input data points and fixed for all the iterations. What is the best way to implement this? Particularly if the weighting is dependent on two separate ceres Residual Blocks? Thanks.

Adit


To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver+unsubscribe@googlegroups.com.

--
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/H3JKVp5p6tg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ceres-solver+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/CABqdRUByjq_DNM1W%2B6S4zAxhzhYF-dX%3DgDFgCcjLTym%3Ds7AdLQ%40mail.gmail.com.

Sameer Agarwal

unread,
Dec 29, 2017, 11:40:23 AM12/29/17
to ceres-...@googlegroups.com
Thats the part I do not understand. What does it mean for the weight to be dependent on the cost functions if they are not changing every iteration? if they can be computed at the start of the solve, just compute them and set them in the cost function.

--
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/H3JKVp5p6tg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ceres-solver...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
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.

Adit

unread,
Dec 29, 2017, 11:57:17 AM12/29/17
to Ceres Solver
Yes you are the right, the weights can be computed at the start of the solve. I guess I was complicating a simpler implementation. Thanks for your replies.
Reply all
Reply to author
Forward
0 new messages