Fitter.cxx
Go to the documentation of this file.
1 
12 #include "Fitter.h"
13 
14 #include "StatedFCN.h"
15 
16 #include <stdexcept>
17 
18 using std::string;
19 using std::vector;
20 
21 #include <climits>
22 #include <cstdlib>
23 
24 using namespace hippodraw;
25 
27 Fitter ( const char * name )
28  : m_name ( name ),
29  m_fcn ( 0 ),
30  m_max_iterations ( 100 )
31 {
32 }
33 
35 Fitter ( const Fitter & fitter )
36  : m_name ( fitter.m_name ),
37  m_max_iterations ( fitter.m_max_iterations )
38 {
39  if ( fitter.m_fcn != 0 ) m_fcn = fitter.m_fcn -> clone ();
40 }
41 
44 {
45  if ( m_fcn != 0 ) delete m_fcn;
46 }
47 
48 void
50 copyFrom ( const Fitter * fitter )
51 {
52  m_fcn -> copyFrom ( fitter -> m_fcn );
53 }
54 
55 const std::string &
57 name () const
58 {
59  return m_name;
60 }
61 
62 void
64 setFCN ( StatedFCN * fcn )
65 {
66  if ( m_fcn != 0 ) delete m_fcn;
67 
68  m_fcn = fcn;
69 }
70 
71 StatedFCN *
74 {
75  return m_fcn;
76 }
77 
78 bool
80 isCompatible ( const FunctionBase * function ) const
81 {
82  bool yes = false;
83  if ( m_fcn != 0 ) {
84  yes = m_fcn -> isCompatible ( function );
85  }
86  return yes;
87 }
88 
89 void
91 setFunction ( FunctionBase * function )
92 {
93  if ( m_fcn != 0 ) {
94  m_fcn -> setFunction ( function );
95  }
96 }
97 
98 void
100 setDataSource ( const DataSource * source )
101 {
102  if ( m_fcn != 0 ) {
103  m_fcn -> setDataSource ( source );
104  m_fcn -> setUseErrors ();
105  }
106 }
107 
108 void
109 Fitter::
111 {
112  if ( m_fcn != 0 ) {
113  m_fcn -> setUseErrors ( yes );
114  }
115 }
116 
117 bool
118 Fitter::
119 getUseErrors () const
120 {
121  bool yes = false;
122  if ( m_fcn != 0 ) {
123  yes = m_fcn -> getUseErrors ();
124  }
125 
126  return yes;
127 }
128 
129 bool
130 Fitter::
132 {
133  bool yes = true;
134  if ( m_fcn != 0 ) {
135  yes = m_fcn -> needsIntegrated ();
136  }
137  return yes;
138 }
139 
140 void
141 Fitter::
142 fillFreeParameters ( std::vector < double > & free_parms) const
143 {
144  return m_fcn -> fillFreeParameters ( free_parms );
145 }
146 
147 void
148 Fitter::
149 setFixedFlags ( const std::vector < int > & flags )
150 {
151  m_fcn -> setFixedFlags ( flags );
152 }
153 
154 const vector < int > &
155 Fitter::
156 getFixedFlags ( ) const
157 {
158  return m_fcn -> getFixedFlags ();
159 }
160 
161 void
162 Fitter::
163 setLimits ( unsigned int, double, double )
164 {
165  string what ( "The " );
166  what += m_name;
167  what += " minimizer does not support limits on parameters";
168  throw std::runtime_error ( what );
169 }
170 
171 unsigned int
172 Fitter::
173 getParameterIndex ( const std::string & name )
174 {
175  unsigned int index = UINT_MAX;
176  const vector < string > & names = m_fcn -> getParmNames ();
177  unsigned int size = names.size();
178  for ( unsigned int i = 0; i < size; i++ ) {
179  const string & pname = names [i];
180  if ( pname == name ) {
181  index = i;
182  break;
183  }
184  }
185  if ( index == UINT_MAX ) {
186  string what ( "No parameter named `" );
187  what += name;
188  what += "' for this function.";
189  throw std::runtime_error ( what );
190  }
191 
192  return index;
193 }
194 
195 void
196 Fitter::
197 setLimits ( const std::string & name, double lower, double upper )
198 {
199  unsigned int index = getParameterIndex ( name );
200  setLimits ( index, lower, upper );
201 }
202 
203 void
204 Fitter::
205 setStepSize ( unsigned int, double )
206 {
207  string what ( "This " );
208  what += m_name;
209  what += " minimizer does not support setting step size.";
210  throw std::runtime_error ( what );
211 }
212 
213 void
214 Fitter::
215 setStepSize ( const std::string & name, double size )
216 {
217  unsigned int index = getParameterIndex ( name );
218  setStepSize ( index, size );
219 }
220 
221 double
223 {
224  return m_fcn -> objectiveValue ();
225 }
226 
227 int
228 Fitter::
230 {
231  return m_fcn -> degreesOfFreedom();
232 }
233 
234 int
235 Fitter::
236 calcCovariance ( std::vector < std::vector < double > > & )
237 {
238  return EXIT_FAILURE;
239 }
240 
241 void
242 Fitter::
244 {
245  m_fcn -> setFitCut ( cut );
246 }
247 
248 void
249 Fitter::
250 setFitRange ( bool yes )
251 {
252  m_fcn -> setFitRange ( yes );
253 }
void fillFreeParameters(std::vector< double > &) const
Fills the vector with the free parameters values.
Definition: Fitter.cxx:142
unsigned int i
StatedFCN * getFCN()
Returns the objective function object.
Definition: Fitter.cxx:73
std::string m_name
The name of the fitter.
Definition: Fitter.h:51
bool isCompatible(const FunctionBase *) const
Returns true if the function is compatible with the objective function.
Definition: Fitter.cxx:80
virtual void setFitCut(TupleCut *cut)
Sets the cut to limit range of fitting.
Definition: Fitter.cxx:243
The class expresses a cut on a DataSource, i.e.
Definition: TupleCut.h:43
void setUseErrors(bool yes=true)
Sets the fitter to use error data from the DataSource, if available.
Definition: Fitter.cxx:110
return yes
Definition: CanvasView.cxx:883
virtual void setFCN(StatedFCN *fcn)
Sets the objective function object.
Definition: Fitter.cxx:64
The base class for fitters.
Definition: Fitter.h:33
virtual void setStepSize(unsigned int i, double size)
Sets the step size for parameter of the minimization.
Definition: Fitter.cxx:205
virtual Fitter * clone() const =0
Makes a copy of the receiving object.
intp size(numeric::array arr)
Definition: num_util.cpp:296
Fitter(const Fitter &)
The copy constructor.
Definition: Fitter.cxx:35
bool getUseErrors() const
Returns true if error data from the DataSource will be used if available.
Definition: Fitter.cxx:119
hippodraw::Fitter class interface
bool needsIntegrated() const
Returns true if the Fitter needs integrated intervals.
Definition: Fitter.cxx:131
virtual int calcDegreesOfFreedom() const
Returns the number of degrees of freedom in the fit.
Definition: Fitter.cxx:229
A function that can be added to a DataRep and used in a fitter.
Definition: FunctionBase.h:90
virtual void setLimits(unsigned int i, double lower, double upper)
Sets the limits for the parameter of the model function indexed by i.
Definition: Fitter.cxx:163
const std::string & name() const
Returns the name of the fitter.
Definition: Fitter.cxx:57
virtual void setFitRange(bool yes=true)
Sets use of a fitting range on or off.
Definition: Fitter.cxx:250
virtual int calcCovariance(std::vector< std::vector< double > > &cov)
Calculates the covariance matrix.
Definition: Fitter.cxx:236
virtual void setFixedFlags(const std::vector< int > &flags)
Sets the parameters that are to be held fixed during objective function minimization.
Definition: Fitter.cxx:149
virtual double objectiveValue() const
Calculates the value of the objective function at the current set of parameters.
Definition: Fitter.cxx:222
unsigned int getParameterIndex(const std::string &name)
Returns the index to the model function parameters name.
Definition: Fitter.cxx:173
return index
Definition: PickTable.cxx:182
void setFunction(FunctionBase *function)
Sets the model function.
Definition: Fitter.cxx:91
virtual ~Fitter()
The virtual destructor.
Definition: Fitter.cxx:43
hippodraw::StatedFCN class interface
virtual const std::vector< int > & getFixedFlags() const
Sets the limits of the model function parameter values.
Definition: Fitter.cxx:156
A derived class for FCNBase class.
Definition: StatedFCN.h:70
virtual void copyFrom(const Fitter *other)
Makes a copy of other.
Definition: Fitter.cxx:50
StatedFCN * m_fcn
The objective function.
Definition: Fitter.h:59
void setDataSource(const DataSource *source)
Sets the source of data to be used.
Definition: Fitter.cxx:100
Base class for DataSource.
Definition: DataSource.h:55

Generated for HippoDraw Class Library by doxygen