This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Using BigFloat for Levenberg-Marquardt optimizer

Tags: None
(comma "," separated)
User avatar
dzenanz
Registered Member
Posts
35
Karma
0
OS
I am trying to use TTMath's Big class to deal with extra large numbers in some computations. However, when I try to call LevenbergMarquardt<fit_functor,Real>::lmdif1(functor,xvec,&nfev,eps), I get these errors about inability to convert to double (see below).

I looked through the Eigen's code and I cannot find where the double is being declared, because "Scalar" is always used. Is what I am trying to do supported?

Code: Select all
d:\sdk\eigen\unsupported\eigen\src/NonLinearOptimization/LevenbergMarquardt.h(644): error C2440: '=' : cannot convert from 'const Real' to 'double'
          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
          d:\sdk\eigen\unsupported\eigen\src/NonLinearOptimization/LevenbergMarquardt.h(633) : while compiling class template member function 'Eigen::LevenbergMarquardtSpace::Status Eigen::LevenbergMarquardt<FunctorType,Scalar>::lmdif1(FunctorType &,Eigen::Matrix<_Scalar,_Rows,_Cols> &,Eigen::LevenbergMarquardt<FunctorType,Scalar>::Index *,const Scalar)'
          with
          [
              FunctorType=fit_functor,
              Scalar=Real,
              _Scalar=Real,
              _Rows=-1,
              _Cols=1
          ]
          D:\Repo\bugTester\bugTester.cpp(135) : see reference to class template instantiation 'Eigen::LevenbergMarquardt<FunctorType,Scalar>' being compiled
          with
          [
              FunctorType=fit_functor,
              Scalar=Real
          ]
d:\sdk\eigen\unsupported\eigen\src/NonLinearOptimization/LevenbergMarquardt.h(645): error C2440: '=' : cannot convert from 'const Real' to 'double'
          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
d:\sdk\eigen\unsupported\eigen\src/NonLinearOptimization/LevenbergMarquardt.h(648): error C2664: 'Eigen::LevenbergMarquardt<FunctorType>::minimize' : cannot convert parameter 1 from 'Eigen::Matrix<_Scalar,_Rows,_Cols>' to 'Eigen::Matrix<_Scalar,_Rows,_Cols> &'
          with
          [
              FunctorType=Eigen::NumericalDiff<fit_functor>
          ]
          and
          [
              _Scalar=Real,
              _Rows=-1,
              _Cols=1
          ]
          and
          [
              _Scalar=double,
              _Rows=-1,
              _Cols=1
          ]
d:\sdk\eigen\unsupported\eigen\src/NonLinearOptimization/LevenbergMarquardt.h(648): error C2514: 'Eigen::LevenbergMarquardtSpace::Status' : class has no constructors
          d:\sdk\eigen\unsupported\eigen\src/NonLinearOptimization/LevenbergMarquardt.h(33) : see declaration of 'Eigen::LevenbergMarquardtSpace::Status'
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
It seems the second template parameter is missing, so what if you change line 644 with:

LevenbergMarquardt<NumericalDiff<FunctorType>, Scalar > lm(numDiff);
User avatar
dzenanz
Registered Member
Posts
35
Karma
0
OS
After this fix, I discovered that ttmath library is missing operators with standard types (int, double) and std::abs, std::sqrt and std::pow (not hard to fix). But it is not possible to cast BigFloat to an int the standard way (\eigen\src\Core\StableNorm.h, line 127).

The killing blow, however, is that computation with double takes a fraction of a second, while with BigFloat I had to cancel it after an hour of computation: I realized I had to find a more efficient way.

Edit: Thanks Gael.


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]