A.I.M.S algorithms


lmgamma.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 
35 #ifndef AIMS_OPTIMIZATION_LMGAMMA_H
36 #define AIMS_OPTIMIZATION_LMGAMMA_H
37 
39 
40 
41 // Gamma-variate function:
42 // f(t) = k * ( t - ta ) ^ a * exp( - ( t - ta ) / b ) si t > ta
43 // f(t) = 0 sinon
44 template < class T >
45 class LMGamma : public LMFunction< T >
46 {
47 public:
48 
49  LMGamma( T k=(T)1.0, T ta=(T)4.0, T a=(T)3.0, T b=(T)1.5 );
50 
51  T apply( T );
52  T eval( T );
53 };
54 
55 
56 template< class T > inline
57 LMGamma< T >::LMGamma( T k, T ta, T a, T b ) : LMFunction< T >()
58 {
59  this->par.push_back( k );
60  this->par.push_back( ta );
61  this->par.push_back( a );
62  this->par.push_back( b );
63 
64  this->der = std::vector< T >( 4 );
65 }
66 
67 
68 template< class T > inline
70 {
71  if ( x > this->par[ 1 ] )
72  {
73  // k
74  double k = (double)this->par[ 0 ];
75  // a
76  double a = (double)this->par[ 2 ];
77  // t - ta
78  double tta = (double)( x - this->par[ 1 ] );
79  // ln( t - ta )
80  double ltta = log( tta );
81  // ( t - ta ) / b
82  double ttab = tta / this->par[ 3 ];
83  // ( t - ta ) ^ a * exp( - ( t - ta ) / b )
84  // = exp( a * ln( t - ta ) - ( t - ta ) / b )
85  double expf = exp( a * ltta - ttab );
86 
87  // f
88  double f = k * expf;
89 
90  // df / dk
91  this->der[ 0 ] = (T)expf;
92 
93  // df / dta
94  this->der[ 1 ] = (T)( k * ( ttab - a ) * exp( ( a - 1 ) * ltta - ttab ) );
95 
96  // df / da
97  this->der[ 2 ] = (T)( k * ltta * expf );
98 
99  // df / db
100  double b2 = (double)( this->par[ 3 ] * this->par[ 3 ] );
101  this->der[ 3 ] = (T)( k * exp( ( a + 1 ) * ltta - ttab ) / b2 );
102 
103  return (T)f;
104  }
105  else
106  {
107  this->der[ 0 ] = this->der[ 1 ] = this->der[ 2 ] = this->der[ 3 ] = (T)0;
108 
109  return (T)0;
110  }
111 }
112 
113 
114 template< class T > inline
116 {
117  if ( x > this->par[ 1 ] )
118  {
119  // t - ta
120  double tta = (double)( x - this->par[ 1 ] );
121  // ln( t - ta )
122  double ltta = log( tta );
123  // ( t - ta ) / b
124  double ttab = tta / this->par[ 3 ];
125 
126  return (T)( this->par[ 0 ] * exp( this->par[ 2 ] * ltta - ttab ) );
127  }
128  else return (T)0;
129 }
130 
131 #endif
T eval(T)
Definition: lmgamma.h:69
T apply(T)
Definition: lmgamma.h:115
LMGamma(T k=(T) 1.0, T ta=(T) 4.0, T a=(T) 3.0, T b=(T) 1.5)
Definition: lmgamma.h:57
std::vector< T > der
Definition: lmfunc.h:59
std::vector< T > par
Definition: lmfunc.h:54