ceres quadratic problem

78 views
Skip to first unread message

maximilia...@gmail.com

unread,
Jun 2, 2017, 9:58:18 AM6/2/17
to Ceres Solver
Hi there,

I have reduced my problem to the following minimal example:


///////////////////////////////////////////////////////////////////////////////////////////////////////////

int main()

{

      double x1 = 20.0;
      double x2 = 5.00;

Problem TestProblem;

CostFunction * cost_function = new AutoDiffCostFunction<testfunctor,1,1,1>(
                                                 new testfunctor());


Solver::Summary summary;
Solver::Options solver_options;
solver_options.minimizer_progress_to_stdout = true;
Solve(solver_options,&TestProblem,&summary);

}

template <typename T>
bool testfunctor::operator()(const T* x,
                             const T* y,
                                      T* value) const
{

        T res = ceres::sqrt((x0] )*
                                       (x[0]) +
                                       (y[0])*
                                        (y[0]);

    value[0] = res;

if(ceres::IsNaN(value[0]))
{
std::cout <<"IsNan"<<std::endl;
value[0] = T(0.);
}
    return true;
}

 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////


which means nothing else than minimising (x^2 + y^2)/2. Obviously the solution is xsol=0, ysol=0. But ceres does not converge properly.

Instead i get x1:-0.00392972 x2: 1.4489 :/.


I received the following output:



Solver Summary (v 1.13.0-eigen-(3.2.92)-lapack-suitesparse-(4.4.6)-cxsparse-(3.1.4)-openmp)

                                     Original                  Reduced
Parameter blocks                            2                        2
Parameters                                  2                        2
Residual blocks                             1                        1
Residual                                    1                        1

Minimizer                        TRUST_REGION

Sparse linear algebra library    SUITE_SPARSE
Trust region strategy     LEVENBERG_MARQUARDT

                                        Given                     Used
Linear solver          SPARSE_NORMAL_CHOLESKY   SPARSE_NORMAL_CHOLESKY
Threads                                     1                        1
Linear solver threads                       1                        1
Linear solver ordering              AUTOMATIC                        2

Cost:
Initial                          2.125000e+02
Final                            1.049660e+00
Change                           2.114503e+02

Minimizer iterations                       51
Successful steps                           33
Unsuccessful steps                         18

Time (in seconds):
Preprocessor                           0.0001

  Residual evaluation                  0.0007
  Jacobian evaluation                  0.0011
  Linear solver                        0.0003
Minimizer                              0.0027

Postprocessor                          0.0000
Total                                  0.0027

Termination:                   NO_CONVERGENCE (Maximum number of iterations reached. Number of iterations: 50.)




 What i am doing wrong? Thanks for your help!


kind regards,


Max

Sameer Agarwal

unread,
Jun 2, 2017, 10:02:19 AM6/2/17
to Ceres Solver
Two problems.
By combining the two terms into one and taking the square root, you are reducing the dimension of the Jacobian to a 1x2 matrix instead of the 2x2 matrix it can be. This takes away information from the optimization algorithm. 
Two, as you get closer to zero the jacobian becomes ill defined since you have

(x^2 + y^2)^{1/2}

The automatic differentiated jacobian will be

[x * (x^2 + y^2)^{-1/2}, y * (x^2 + y^2)^{-1/2}]

which will lead to a 0/0 division error. 

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/c53bd9ec-587a-43a0-8dab-5ad510d1ee4f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages