LogParabola.cxx
Go to the documentation of this file.
1 
12 #ifdef _MSC_VER
13 #include "msdevstudio/MSconfig.h"
14 #endif
15 
16 #include "LogParabola.h"
17 
18 #include "FunctionHelper.h"
19 
20 #include <cmath>
21 #include <cassert>
22 #include <iostream>
23 
24 using std::distance;
25 
26 #ifdef ITERATOR_MEMBER_DEFECT
27 using namespace std;
28 #else
29 using std::log;
30 using std::exp;
31 using std::pow;
32 using std::vector;
33 #endif
34 
35 namespace hippodraw {
36 
37 LogParabola::LogParabola ( )
38 {
39  initialize ();
40 }
41 
42 LogParabola::LogParabola ( double n, double a, double b)
43 {
44  initialize ();
45 
46  m_parms[NORM] = n;
47  m_parms[ALPHA] = a;
48  m_parms[BETA] = b;
49 }
50 
51 void LogParabola::initialize ()
52 {
53  m_name = "LogParabola";
54 
55  m_parm_names.push_back ( "norm" );
56  m_parm_names.push_back ( "alpha" );
57  m_parm_names.push_back ( "beta" );
58 
59  resize ();
60 }
61 
63 {
64  return new LogParabola ( *this );
65 }
66 
67 double LogParabola::operator () ( double x ) const
68 {
69  double logx = log(x);
70  return m_parms[0]*pow(x,(-(m_parms[1] + m_parms[2]*logx)));
71 }
72 
73 void
74 LogParabola::initialParameters ( const FunctionHelper * helper )
75 {
76  double min_x = helper->minCoord ();
77  double max_x = helper->maxCoord ();
78  int size = helper->size();
79  double total = helper->getTotal ();
80 
81  m_parms[NORM] = total * ( max_x - min_x ) / size;
82  m_parms[ALPHA] = 0.1;
83  m_parms[BETA] = 0.1;
84 }
85 
86 double LogParabola::derivByParm ( int ipar, double x) const
87 {
88  double logx = log(x);
89  double dfdnorm = pow(x,( -(m_parms[1] + m_parms[2]*logx)));
90 
91  double deriv =0.;
92 
93  switch (ipar){
94  case NORM:
95  deriv = dfdnorm;
96  break;
97  case ALPHA:
98  deriv = -m_parms[0]*logx*dfdnorm;
99  break;
100  case BETA:
101  deriv = -m_parms[0]*logx*logx*dfdnorm;
102  break;
103  default:
104  std::cout<<"parameter index not found : "<<ipar<<std::endl;
105  std::cout<<"I know about "<<NORM<<" "<<ALPHA<<" "<<BETA<<" "<<std::endl;
106  assert ( false );
107  break;
108  }
109  return deriv;
110 }
111 
112 bool
113 LogParabola::hasDerivatives () const
114 {
115  return true;
116 }
117 
118 } // namespace hippodraw
119 

Generated for HippoDraw Class Library by doxygen