Conjugate gradient fit.  
 More...
#include <JGradient.hh>
Conjugate gradient fit. 
Definition at line 73 of file JGradient.hh.
 
◆ JGradient()
  
  
      
        
          | JFIT::JGradient::JGradient  | 
          ( | 
          const size_t  | 
          Nmax = std::numeric_limits<size_t>::max(),  | 
         
        
           | 
           | 
          const size_t  | 
          Nextra = 0,  | 
         
        
           | 
           | 
          const double  | 
          epsilon = 1.0e-4,  | 
         
        
           | 
           | 
          const int  | 
          debug = 3  | 
         
        
           | 
          ) | 
           |  | 
         
       
   | 
  
inline   | 
  
 
Constructor. 
The number of iterations and epsilon refer to the number of steps and the distance to the minimum, respectively.
The number of extra steps can be used to overcome a possible hurdle on the way.
- Parameters
 - 
  
    | Nmax | maximum number of iterations  | 
    | Nextra | maximum number of extra steps  | 
    | epsilon | epsilon  | 
    | debug | debug  | 
  
   
Definition at line 88 of file JGradient.hh.
size_t Nmax
maximum number of iterations
 
size_t Nextra
maximum number of extra steps
 
 
 
 
◆ operator()()
template<class T > 
  
  
      
        
          | double JFIT::JGradient::operator()  | 
          ( | 
          const T &  | 
          getChi2 | ) | 
           | 
         
       
   | 
  
inline   | 
  
 
Fit. 
The template parameter should provide for the following function operator. 
   double operator()(int option);
 The value of the option corresponds to the following cases.
- 0 => step wise improvement of the chi2;
 
- 1 => evaluation of the chi2 before the determination of the gradient of the chi2; and
 
- 2 => evaluation of the derivative of the chi2 to each fit parameter.
 
- Parameters
 - 
  
  
 
- Returns
 - chi2 
 
Definition at line 115 of file JGradient.hh.
  123         return numeric_limits<double>::max();
 
  128       const size_t N = this->size();
 
  133       for (
size_t i = 0; i != N; ++i) {
 
  152         for (
double ds = 1.0; ds > 1.0e-3; ) {
 
  154           this->
move(+1.0 * ds);
 
  158           DEBUG(
"chi2[3]  " << setw(4) << m << 
' ' << 
FIXED(12,5) << chi2[3] << 
' ' << 
FIXED(12,5) << ds << endl);
 
  160           if (chi2[3] < chi2[2]) {
 
  184               for ( ; m != 0; --m) {
 
  185                 this->
move(-1.0 * ds);
 
  192           this->
move(-1.0 * ds);
 
  194           if (chi2[2] < chi2[3]) {
 
  202             const double f21 = chi2[2] - chi2[1];   
 
  203             const double f23 = chi2[2] - chi2[3];   
 
  205             const double xs  =  0.5 * (f21 - f23) / (f23 + f21);
 
  207             this->
move(+1.0 * xs * ds);
 
  211             if (chi2[3] < chi2[2]) {
 
  217               this->
move(-1.0 * xs * ds);
 
  232         if (fabs(chi2[2] - chi2[0]) < 
epsilon * 0.5 * (fabs(chi2[0]) + fabs(chi2[2]))) {
 
  244         for (
size_t i = 0; i != N; ++i){
 
  255         for (
size_t i = 0; i != N; ++i){
 
  257           H[i] =  G[i] + dgg * 
H[i];
 
#define DEBUG(A)
Message macros.
 
double getChi2(const double P)
Get chi2 corresponding to given probability.
 
static const double H
Planck constant [eV s].
 
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
 
Auxiliary data structure for floating point format specification.
 
void move(const double factor)
Move.
 
std::vector< double > gradient
 
double evaluate(const T &getChi2)
Evaluate gradient.
 
size_t numberOfIterations
 
Auxiliary data structure for floating point format specification.
 
 
 
 
◆ evaluate()
template<class T > 
  
  
      
        
          | double JFIT::JGradient::evaluate  | 
          ( | 
          const T &  | 
          getChi2 | ) | 
           | 
         
       
   | 
  
inlineprivate   | 
  
 
Evaluate gradient. 
- Returns
 - chi2 
 
Definition at line 282 of file JGradient.hh.
  287       const size_t N = this->size();
 
  299       for (
size_t i = 0; i != N; ++i) {
 
  300         if ((*
this)[i].name.size() > width) {
 
  301           width = (*this)[i].name.size();
 
  307       for (
size_t i = 0; i != N; ++i) {
 
  309         if ((*
this)[i].value != 0.0) {
 
  311           (*this)[i]->apply(+0.5 * (*
this)[i].value);
 
  315           (*this)[i]->apply(-0.5 * (*
this)[i].value);
 
  316           (*this)[i]->apply(-0.5 * (*
this)[i].value);
 
  322           (*this)[i]->apply(+0.5 * (*
this)[i].value);
 
  324           DEBUG(setw(width) << left << (*
this)[i].name << right << 
' ' << 
FIXED(12,5) << (*
this)[i].value << 
' ' << 
FIXED(12,5) << 
gradient[i] << endl);
 
  334       DEBUG(setw(width) << left << 
"|gradient|" << right << 
' ' << 
FIXED(12,5) << sqrt(V) << endl);
 
 
 
 
◆ move()
  
  
      
        
          | void JFIT::JGradient::move  | 
          ( | 
          const double  | 
          factor | ) | 
           | 
         
       
   | 
  
inlineprivate   | 
  
 
Move. 
- Parameters
 - 
  
  
 
Definition at line 345 of file JGradient.hh.
  348         for (
size_t i = 0; i != this->size(); ++i) {
 
  349           (*this)[ i ]->apply((*
this)[ i ].value * 
gradient[ i ] * factor);
 
  351       } 
else if (factor < 0.0) {
 
  352         for (
size_t i = this->size(); i != 0; --i) {
 
  353           (*this)[i-1]->apply((*
this)[i-1].value * 
gradient[i-1] * factor);
 
 
 
 
◆ Nmax
      
        
          | size_t JFIT::JGradient::Nmax | 
        
      
 
 
◆ Nextra
      
        
          | size_t JFIT::JGradient::Nextra | 
        
      
 
 
◆ epsilon
      
        
          | double JFIT::JGradient::epsilon | 
        
      
 
 
◆ debug
      
        
          | int JFIT::JGradient::debug | 
        
      
 
 
◆ numberOfIterations
      
        
          | size_t JFIT::JGradient::numberOfIterations | 
        
      
 
 
◆ gradient
The documentation for this struct was generated from the following file: