TBCI Numerical high perf. C++ Library  2.8.0
Macros | Functions | Variables
LM_fit.h File Reference

Levenbaerg-Marquardt non linear data fit routine. More...

#include "tbci/basics.h"
#include "tbci/vector.h"
#include "tbci/matrix.h"
#include "tbci/constants.h"
#include "tbci/solver/gauss_jordan.h"
Include dependency graph for LM_fit.h:

Go to the source code of this file.

Macros

#define DELTAX   1e-30
 
#define DELTA(i, j)   ((i==j)?1:0)
 the kronecker delta More...
 
#define CON2   2.0
 
#define CON   SQRT2
 
#define BIG   1.0e30
 
#define NTAB   10
 
#define SAFE   2.0
 

Functions

 INST (template< typename T > class Vector friend int Basis_Trafo(long int, long int, Vector< T > &);) template< typename T > int Basis_Trafo(long int value
 
 if (value==0) return 1
 
 if (n< (int) CSTD__ ceil(MATH__ sqrt(2 *MATH__ log((double) value)/MATH__ log((double) basis)))||basis<=1) return 0
 
 while (value > 0)
 
 INST (template< typename T > class Vector friend T Partial_Del(T(*func)(const Vector< T > &, const Vector< T > &), const Vector< T > &, const Vector< T > &, int, T, T &);) template< typename T > T Partial_Del(T(*func)(const Vector< T > &
 
Matrix< Ta (10, 10)
 
Vector< Tbuf_plus (xlen)
 
Vector< Tbuf_minus (xlen)
 
STD__ cerr<< "\n error:
partial_del: derivate variable
index out of range \n";hh=h;buf_plus=x;buf_minus=x;buf_plus(mu)+=hh;buf_minus(mu)-=hh;a(0,
0)=((*func)(buf_plus, p)-(*func)(buf_minus,
p))/(2.0 *hh);err=1.0e30;for(int i=1;i< 10;i++){hh/=SQRT2;buf_plus=x;buf_minus=x;buf_plus(mu)+=hh;buf_minus(mu)-=hh;a(0, i)=((*func)(buf_plus, p)-(*func)(buf_minus, p))/(2.0 *hh);fac=2.0;for(REGISTER int j=1;j<=i;j++){a(j, i)=(a(j-1, i)*fac-a(j-1, i-1))/(fac-1.0);fac *=2.0;errt=MAX(MATH__ fabs(a(j, i)-a(j-1, i)), MATH__ fabs(a(j, i)-a(j-1, i-1)));if(errt<=err){err=errt;ans=a(j, i);}}if(MATH__ fabs(a(i, i)-a(i-1, i-1)) >=MATH__ fabs(2.0 *err)) break;}return ans;}INST(template< typename T > class Vector friend T Chisq(Vector< T > &, Vector< T > &, Vector< T > &);) template< typename T > T 
Chisq (Vector< T > &data, Vector< T > &func, Vector< T > &sig)
 
 INST (template< typename T > class Vector friend T Chisquare_2D(T(*func)(const Vector< T > &, const Vector< T > &), Vector< T > &, Vector< T > &, Vector< T > &, Vector< T > &, Vector< T > &);) template< typename T > T Chisquare_2D(T(*func)(const Vector< T > &
 
T chi ALIGN (MIN_ALIGN)=0
 
 for (REGISTER int i=0;i< anzpkt;i++)
 
 INST (template< typename T > class Vector friend TVector< T > Grid_Min_2D(T(*func)(const Vector< T > &, const Vector< T > &), Vector< T > &, Vector< T > &, Vector< T > &, Vector< T > &, Vector< T > &, Vector< T > &, Vector< T > &, long int, int, char);) template< typename T > TVector< T > Grid_Min_2D(T(*func)(const Vector< T > &
 
Vector< Tp (pmin)
 
TVector< Tmin_pos (pmin)
 
Vector< Tfactor (plen)
 
Vector< Targ (2)
 
Vector< Tfval (x.size())
 
Vector< Tindex (plen)
 
Vector< Tb (0, plen)
 
Vector< Ta (0, plen)
 
STD__ cout<< "\n parameter
space discretisation with "
<< len<< " points in progress
... \n ";factor(j)=(pmax(j)-pmin(j))/((T)
res-(T) 1);for(long int i=0;i
< len;i++){STD__ cerr<< "\n
error: basis trafo failed\n";p(j)=factor(j)*index(j)+pmin(j);for(int
l=0;l< xlen;l++){arg(0)=x(l);arg(1)=y(l);fval(l)=(*func)(p,
arg);}chi=Chisq(z, fval, sig);if(chi
< min){min=chi;min_pos=p;}if(i%1000==0)
STD__ cerr<< i<< "\t\t\t\r";}STD__
cout<< " \n done! \n\n"
<< STD__ endl;return min_pos;}INST(template
< typename T > class Vector
friend T LM_fit_2D(Vector< T >
&, Vector< T > &, Vector< T >
&, Vector< T > &, Vector< T >
&, Vector< T > &, Vector< T >
&, T(*func)(const Vector< T >
&, const Vector< T >
&), Vector< T >, Vector< T >
&, T, int, char);) template
< typename T > T 
LM_fit_2D (Vector< T > &x, Vector< T > &y, Vector< T > &z, Vector< T > &sig, Vector< T > &param, Vector< T > &plow, Vector< T > &phigh, T(*func)(const Vector< T > &, const Vector< T > &), Vector< T > lambda, Vector< T > &lscale, T tol, int iter, char ver)
 

Variables

long int basis
 
long int Vector< T > & index
 
int i = 0
 
 return
 
const Vector< T > const Vector
< T > & 
x
 
const Vector< T > const Vector
< T > const Vector< T > & 
p
 
const Vector< T > const Vector
< T > const Vector< T > int 
mu
 
const Vector< T > const Vector
< T > const Vector< T > int T 
h
 
const Vector< T > const Vector
< T > const Vector< T > int T
T
err
 
int xlen = x.size()
 
const Vector< T > Vector< T > & param
 
const Vector< T > Vector< T >
Vector< T > Vector< T > & 
y
 
const Vector< T > Vector< T >
Vector< T > Vector< T >
Vector< T > & 
z
 
const Vector< T > Vector< T >
Vector< T > Vector< T >
Vector< T > Vector< T > & 
sigma
 < calculates function values of func at position x with params param and return chisq with given y values weighted with sigmas More...
 
T chi wfvaldiff
 
int anzpkt = x.size()
 
return chi =0
 
const Vector< T > Vector< T >
Vector< T > Vector< T >
Vector< T > & 
sig
 
const Vector< T > Vector< T >
Vector< T > Vector< T >
Vector< T > Vector< T > & 
pmin
 
const Vector< T > Vector< T >
Vector< T > Vector< T >
Vector< T > Vector< T >
Vector< T > & 
pmax
 
const Vector< T > Vector< T >
Vector< T > Vector< T >
Vector< T > Vector< T >
Vector< T > Vector< T > & 
lambda
 
const Vector< T > Vector< T >
Vector< T > Vector< T >
Vector< T > Vector< T >
Vector< T > Vector< T > long
int 
res
 
const Vector< T > Vector< T >
Vector< T > Vector< T >
Vector< T > Vector< T >
Vector< T > Vector< T > long
int int 
max_it
 
const Vector< T > Vector< T >
Vector< T > Vector< T >
Vector< T > Vector< T >
Vector< T > Vector< T > long
int int char 
v
 < find minimun of func on grid with resolution res More...
 
long int len =0
 
 min =Chisq(z, fval, sig)
 

Detailed Description

Levenbaerg-Marquardt non linear data fit routine.

Definition in file LM_fit.h.

Macro Definition Documentation

#define BIG   1.0e30

Definition at line 88 of file LM_fit.h.

#define CON   SQRT2

Definition at line 87 of file LM_fit.h.

#define CON2   2.0

Definition at line 86 of file LM_fit.h.

#define DELTA (   i,
 
)    ((i==j)?1:0)

the kronecker delta

Definition at line 53 of file LM_fit.h.

Referenced by LM_fit_2D().

#define DELTAX   1e-30

Definition at line 49 of file LM_fit.h.

#define NTAB   10

Definition at line 89 of file LM_fit.h.

#define SAFE   2.0

Definition at line 90 of file LM_fit.h.

Function Documentation

Matrix<T> a ( 10  ,
10   
)
Vector<T> a ( ,
plen   
)
T chi ALIGN ( MIN_ALIGN  )
pure virtual
Vector<T> arg ( )
Vector<T> b ( ,
plen   
)
Vector<T> buf_minus ( xlen  )
Vector<T> buf_plus ( xlen  )
STD__ cerr<< "\n error: partial_del: derivate variable index out of range \n"; hh = h ; buf_plus = x; buf_minus = x; buf_plus(mu) += hh; buf_minus(mu) -= hh; a(0,0) = ((*func)(buf_plus, p) - (*func)(buf_minus, p)) / (2.0*hh); err = 1.0e30 ; for (int i = 1; i < 10 ; i++) { hh /= SQRT2 ; buf_plus = x; buf_minus = x; buf_plus(mu) += hh; buf_minus(mu) -= hh; a(0,i) = ((*func)(buf_plus, p) - (*func)(buf_minus, p)) / (2.0*hh); fac = 2.0 ; for (REGISTER int j = 1; j <= i; j++) { a(j,i) = (a(j-1,i)*fac - a(j-1,i-1))/(fac-1.0); fac *= 2.0 ; errt = MAX (MATH__ fabs(a(j,i)-a(j-1,i)), MATH__ fabs(a(j,i)-a(j-1,i-1))); if (errt <= err) { err = errt; ans = a(j,i); } } if (MATH__ fabs (a(i,i)-a(i-1,i-1)) >= MATH__ fabs ( 2.0 *err)) break; } return ans;}INST(template <typename T> class Vector friend T Chisq (Vector<T>&, Vector<T>&, Vector<T>&);)template <typename T> T Chisq ( Vector< T > &  data,
Vector< T > &  func,
Vector< T > &  sig 
)

Definition at line 155 of file LM_fit.h.

References ALIGN, chi, len, MIN_ALIGN, REGISTER, sig, TVector< T >::size(), sqr(), and T.

Vector<T> factor ( plen  )
for ( )

Definition at line 182 of file LM_fit.h.

References arg(), chi, param, sigma, sqr(), wfvaldiff, x, y, and z.

Vector<T> fval ( x.  size())

Referenced by lev_mar(), and LM_fit_2D().

if ( value  = =0)

Referenced by job_vec_sum(), and Vector< T >::Vector().

if ( )
Vector<T> index ( plen  )
INST ( template< typename T > class Vector friend int Basis_Trafo(long int, long int, Vector< T > &);  )
INST ( template< typename T > class Vector friend T Partial_Del(T(*func)(const Vector< T > &, const Vector< T > &), const Vector< T > &, const Vector< T > &, int, T, T &);  ) const
INST ( template< typename T > class Vector friend T Chisquare_2D(T(*func)(const Vector< T > &, const Vector< T > &), Vector< T > &, Vector< T > &, Vector< T > &, Vector< T > &, Vector< T > &);  ) const
INST ( template< typename T > class Vector friend TVector< T > Grid_Min_2D(T(*func)(const Vector< T > &, const Vector< T > &), Vector< T > &, Vector< T > &, Vector< T > &, Vector< T > &, Vector< T > &, Vector< T > &, Vector< T > &, long int, int, char);  ) const
STD__ cout<< "\n parameter space discretisation with " << len << " points in progress ... \n "; factor(j) = (pmax(j) - pmin(j)) / ((T)res - (T)1); for (long int i=0; i<len; i++) { STD__ cerr << "\n error: basis trafo failed\n"; p(j) = factor(j) * index(j) + pmin(j); for (int l=0; l<xlen; l++) { arg(0)=x(l); arg(1)=y(l); fval(l)=(*func)(p, arg); } chi=Chisq(z, fval, sig); if ( chi<min ) { min=chi; min_pos=p; } if ( i%1000==0 ) STD__ cerr << i << "\t\t\t\r"; } STD__ cout << " \n done! \n\n" << STD__ endl; return min_pos;}INST(template <typename T> class Vector friend T LM_fit_2D(Vector<T>&, Vector<T>&, Vector<T>&, Vector<T>&, Vector<T>&, Vector<T>&, Vector<T>&,T (*func)(const Vector<T>&, const Vector<T>&), Vector<T>, Vector<T>&, T, int, char);)template <typename T> T LM_fit_2D ( Vector< T > &  x,
Vector< T > &  y,
Vector< T > &  z,
Vector< T > &  sig,
Vector< T > &  param,
Vector< T > &  plow,
Vector< T > &  phigh,
T(*)(const Vector< T > &, const Vector< T > &)  func,
Vector< T lambda,
Vector< T > &  lscale,
T  tol,
int  iter,
char  ver 
)
Parameters
verfit method: levenberg-marquardt leads to an linear equ derivatives are calculated numerically by num_derivatives parameter space is restricted by plow and phigh

Definition at line 278 of file LM_fit.h.

References a, ALIGN, arg(), b, chi, DELTA, err, std::fabs(), fac, fval(), gaussj(), lambda, len, MATH__, MIN_ALIGN, param, REGISTER, sig, TVector< T >::size(), STD__, T, x, y, and z.

TVector<T> min_pos ( pmin  )
Vector<T> p ( pmin  )
while ( value  ,
 
)

Definition at line 76 of file LM_fit.h.

References basis, and index.

Variable Documentation

int anzpkt = x.size()

Definition at line 180 of file LM_fit.h.

long int basis

Definition at line 66 of file LM_fit.h.

Referenced by basis_trafo(), and while().

T min chi =0

Definition at line 187 of file LM_fit.h.

Referenced by Chisq(), chisq(), for(), lev_mar(), and LM_fit_2D().

T min err
Initial value:
{
T errt ALIGN(MIN_ALIGN), fac, hh, ans = (T)0
#define MIN_ALIGN
Definition: basics.h:421
#define ALIGN(x)
Definition: basics.h:444
tm fac
Definition: f_matrix.h:1052
#define T
Definition: bdmatlib.cc:20

Definition at line 102 of file LM_fit.h.

Referenced by free_threads(), gaussj(), init_threads(), lev_mar(), lina_thread(), LM_fit_2D(), lu_decomp(), QMR(), and thread_wait_result().

const Vector<T> const Vector<T> const Vector<T> int T h
int i = 0

Definition at line 71 of file LM_fit.h.

Referenced by TBCI::_tbci_fill_fn(), BdMatrix< T >::adddiag(), CRMatrix< T >::allocate(), CSCMatrix< T >::allocate(), basis_trafo(), BdMatrix< T >::BdMatrix(), BiCG(), BiCGSTAB(), bind_threads(), binom(), binomial(), BVector< T >::bubble_sort(), BVector< T >::BVector(), BVector< unsigned >::BVector(), CTensor< T >::calc_indx(), CTensor< T >::calc_offs(), CTensor< T >::calclayout(), CTensor< T >::calcsize(), cediv(), cemul(), CG(), CG2(), CGS(), CHEBY(), BdMatrix< T >::check_internal(), chisq(), Tensor< T >::cntrmul(), conj(), Symm_BdMatrix< T >::construct(), BdMatrix< T >::constructor(), FS_Vector< dims, T >::contains(), BVector< T >::contains(), CRMatrix< T >::copy(), CSCMatrix< T >::copy(), Symm_BdMatrix< T >::create(), CRMatrix< T >::CRMatrix(), CSCMatrix< T >::cscm_vec_mul_exact(), CTensor< T >::CTensor(), ctrmul(), CRMatrix< T >::destroy(), BdMatrix< T >::div_row(), BdMatrix< T >::div_rows(), do_bdmat_vec_dotmult(), do_bdmat_vec_mult_lnw(), do_bdmat_vec_mult_lnw_opt(), do_bdmat_vec_transmult_lnw(), do_bdmat_vec_transmult_lnw_opt(), BdMatrix< T >::do_copy(), CSCMatrix< T >::do_export(), do_fbdmat_vec_mul(), dot(), ediv(), eig(), emul(), exact_sum(), BdMatrix< T >::expand(), expm2(), expm3(), fac(), CRMatrix< T >::fill(), FS_Vector< dims, T >::fill(), CSCMatrix< T >::fill(), tbci_memalloc_cache< T >::find_by_sz(), fix_condition(), for(), FS_Vector< dims, T >::FS_Vector(), gaussj(), Symm_BdMatrix< T >::get(), TVector< T >::get(), TSVector< T >::get(), F_BandMatrix< T >::get_col(), CTensor< T >::get_lin_idx(), BdMatrix< T >::get_row(), CTensor< T >::getcref(), TVector< T >::getcref(), TSVector< T >::getcref(), F_TMatrix< T >::herm(), hpsort(), Index::idx_fill_in1(), Index::idx_fill_in2(), Index::idx_remove1(), Index::idx_remove2(), if(), imag(), FS_Vector< dims, T >::incr(), TVector< T >::incr(), TSVector< T >::incr(), Vector< T >::incr(), Index::Index(), CSCMatrix< T >::insert(), inv(), IR(), kahan_sum(), Index::lin_read(), CTensor< T >::lin_read(), LU_bkw_subst(), lu_decomp(), LU_det(), LU_fwd_subst(), lu_solve(), LU_solve(), CRMatrix< T >::MatVecMult(), CSCMatrix< T >::MatVecMult(), metrmul(), CRMatrix< T >::mult(), CSCMatrix< T >::mult(), Tensor< T >::mult(), BdMatrix< T >::mult_row(), BdMatrix< T >::mult_rows(), CSCMatrix< T >::multf(), norm_1(), BdMatrix< T >::operator TMatrix< T >(), operator!=(), FS_Vector< dims, T >::operator()(), Symm_BdMatrix< T >::operator()(), CTensor< T >::operator()(), BVector< T >::operator()(), TVector< T >::operator()(), TSVector< T >::operator()(), Matrix< T >::operator()(), Symm_BdMatrix< T >::operator*(), CRMatrix< T >::operator*(), CSCMatrix< T >::operator*(), BdMatrix< T >::operator*(), Tensor< T >::operator*(), F_TSMatrix< T >::operator*(), TSMatrix< T >::operator*(), Matrix< T >::operator*(), CRMatrix< T >::operator*=(), CSCMatrix< T >::operator*=(), Tensor< T >::operator+(), operator+(), Tensor< T >::operator+=(), CRMatrix< T >::operator-(), FS_Vector< dims, T >::operator-(), CSCMatrix< T >::operator-(), BdMatrix< T >::operator-(), Tensor< T >::operator-(), operator-(), Tensor< T >::operator-=(), FS_Vector< dims, T >::operator/(), CRMatrix< T >::operator/(), CSCMatrix< T >::operator/(), Tensor< T >::operator/(), FS_Vector< dims, T >::operator/=(), CRMatrix< T >::operator/=(), CSCMatrix< T >::operator/=(), BdMatrix< T >::operator/=(), operator<<(), BVector< T >::operator<=(), CRMatrix< T >::operator=(), CRMatrix< T >::operator==(), CSCMatrix< T >::operator==(), operator==(), BdMatrix< T >::operator==(), TSVector< T >::operator==(), Vector< T >::operator==(), BVector< T >::operator>=(), operator>>(), FS_Vector< dims, T >::operator[](), own_ev_(), QMR(), real(), BdMatrix< T >::reconfig(), CSCMatrix< T >::resize(), BdMatrix< T >::resize(), TMatrix< T >::row_expand(), cplx< T >::set(), TVector< T >::set(), F_BandMatrix< T >::set_col(), F_TMatrix< T >::set_ptrs(), TMatrix< T >::set_ptrs(), BdMatrix< T >::set_row(), CRMatrix< T >::setunit(), CSCMatrix< T >::setunit(), F_TMatrix< T >::setunit(), CRMatrix< T >::setval(), Symm_BdMatrix< T >::setval(), TVector< T >::setval(), CRMatrix< T >::size(), ILU0_Symm_BdMatrixPreconditioner< T >::solve(), DILU_BdMatrixPreconditioner< T >::solve(), ILU0_BdMatrixPreconditioner< T >::solve(), sv_decomp(), sv_decomp_backsub(), Tensor< T >::Tensor(), F_TMatrix< T >::trace(), BdMatrix< T >::trace(), F_TMatrix< T >::trans(), F_BandMatrix< T >::transMult(), CRMatrix< T >::transMult(), CSCMatrix< T >::transMult(), Update(), DiagPreconditioner< T, MatrixType >::update(), ILU0_Symm_BdMatrixPreconditioner< T >::update(), DILU_BdMatrixPreconditioner< T >::update(), ILU0_BdMatrixPreconditioner< T >::update(), and Vector< T >::Vector().

index
const Vector<T> Vector<T> Vector<T> Vector<T> Vector<T> Vector<T> Vector<T> Vector<T>& lambda

Definition at line 199 of file LM_fit.h.

Referenced by lev_mar(), and LM_fit_2D().

len =0

Definition at line 209 of file LM_fit.h.

Referenced by Chisq(), chisq(), lev_mar(), and LM_fit_2D().

const Vector<T> Vector<T> Vector<T> Vector<T> Vector<T> Vector<T> Vector<T> Vector<T> long int int max_it

Definition at line 199 of file LM_fit.h.

min =Chisq(z, fval, sig)

Definition at line 222 of file LM_fit.h.

const Vector<T> const Vector<T> const Vector<T> int mu

Definition at line 97 of file LM_fit.h.

const Vector<T> const Vector<T> const Vector<T>& p

Definition at line 97 of file LM_fit.h.

Referenced by BiCG(), BiCGSTAB(), CG(), CG2(), CGS(), CHEBY(), expm(), QMR(), and BdMatrix< T >::setoutopts().

const Vector<T> Vector<T>& param

Definition at line 172 of file LM_fit.h.

Referenced by for(), lev_mar(), LM_fit_2D(), and slice().

const Vector<T> Vector<T> Vector<T> Vector<T> Vector<T> Vector<T> Vector<T>& pmax

Definition at line 199 of file LM_fit.h.

const Vector<T> Vector<T> Vector<T> Vector<T> Vector<T> Vector<T>& pmin

Definition at line 199 of file LM_fit.h.

const Vector<T> Vector<T> Vector<T> Vector<T> Vector<T> Vector<T> Vector<T> Vector<T> long int res
return

Definition at line 82 of file LM_fit.h.

Referenced by cgamma_(), chgf_(), and conhyp_().

const Vector<T> Vector<T> Vector<T> Vector<T> Vector<T>& sig

Definition at line 199 of file LM_fit.h.

Referenced by Chisq(), chisq(), lev_mar(), and LM_fit_2D().

const Vector<T> Vector<T> Vector<T> Vector<T> Vector<T> Vector<T>& sigma
Initial value:
{
T arg(const TBCI__ cplx< T > &c)
Definition: cplx.h:690
Definition: bvector.h:54

< calculates function values of func at position x with params param and return chisq with given y values weighted with sigmas

Definition at line 176 of file LM_fit.h.

Referenced by for(), and own_ew_().

const Vector<T> Vector<T> Vector<T> Vector<T> Vector<T> Vector<T> Vector<T> Vector<T> long int int char v
T chi wfvaldiff

Definition at line 179 of file LM_fit.h.

Referenced by for().

const Vector< T > Vector< T > & x
int xlen = x.size()

Definition at line 105 of file LM_fit.h.

const Vector< T > Vector< T > Vector< T > & y
const Vector< T > Vector< T > Vector< T > Vector< T > & z