FunctionBase.cxx
Go to the documentation of this file.
1 
12 // for truncation warning in debug mode
13 #ifdef _MSC_VER
14 #include "msdevstudio/MSconfig.h"
15 #endif
16 
17 #include "FunctionBase.h"
18 
19 #include <cassert>
20 
21 using std::string;
22 using std::vector;
23 
24 namespace hippodraw {
25 
31 {
32  m_name = "nil";
33 }
34 
39 FunctionBase ( const FunctionBase & fb )
40  : m_name ( fb.m_name ),
41  m_parm_names ( fb.m_parm_names ),
42  m_parms ( fb.m_parms ),
43  m_fixed_flags ( fb.m_fixed_flags )
44 {
45 }
46 
48 {
49 }
50 
53 clone () const
54 {
55  assert ( false );
56  return 0;
57 }
58 
59 void
62 {
63 }
64 
65 void
67 setName ( const char * name )
68 {
69  m_name = name;
70 }
71 
73 {
74  assert ( ! m_parm_names.empty () );
75 
76  size_t size = m_parm_names.size ();
77  m_parms.resize ( size );
78  m_fixed_flags.resize ( size, 0 ); // set to free parameter
79 }
80 
81 const string & FunctionBase::name () const
82 {
83  return m_name;
84 }
85 
86 const vector < string > & FunctionBase::parmNames ( ) const
87 {
88  return m_parm_names;
89 }
90 
91 void
93 setParmNames ( const std::vector < std::string > & names )
94 {
95  m_parm_names = names;
96  resize ();
97 }
98 
99 const vector < double > & FunctionBase::getParameters () const
100 {
101  return m_parms;
102 }
103 
104 const vector < int > &
106 getFixedFlags ( ) const
107 {
108  return m_fixed_flags;
109 }
110 
111 void
113 setFixedFlags ( const vector < int > & flags )
114 {
115  vector < int > :: const_iterator it = flags.begin ();
116  setFixedFlags ( it );
117 }
118 
119 void
121 setParameters ( const std::vector< double > & incr )
122 {
123  vector< double >::const_iterator it = incr.begin ();
124  setParameters ( it );
125 }
126 
127 vector < double > ::const_iterator
129 setParameters ( std::vector < double > :: const_iterator it )
130 {
131  unsigned int size = m_parms.size();
132  for ( unsigned int i = 0; i < size; i++ ) {
133  m_parms[i] = *it++;
134  }
135 
136  return it;
137 }
138 
139 vector < int > ::const_iterator
141 setFixedFlags ( std::vector < int > :: const_iterator it )
142 {
143 
144  unsigned int size = m_parms.size ();
145  for ( unsigned int i = 0; i < size; i++ ) {
146  m_fixed_flags[i] = *it++;
147 }
148  return it;
149 }
150 
151 bool
154 {
155  return true;
156 }
157 
165 double FunctionBase::integrate ( double a, double b ) const
166 {
167  int n = 10;
168  double h = (b - a)/n;
169  double x = a;
170  double sumt = operator()( a ) / 2;
171 
172  for( int i = 1; i <= n - 1; i++ )
173  {
174  x += h;
175  sumt += operator()( x );
176  }
177 
178  sumt = ( sumt + operator()( b ) / 2 ) * h;
179 
180  return sumt;
181 }
182 
183 int FunctionBase::size () const
184 {
185  return m_parm_names.size ();
186 }
187 
189 {
190  return false;
191 }
192 
194 {
195 }
196 
198 {
199 }
200 
202 {
203  return 0;
204 }
205 
206 double
208 operator () ( const std::vector < double > & v ) const
209 {
210  assert ( v.size () == 1 );
211 
212  return this -> operator () ( v.front () );
213 }
214 
215 double
217 derivByParm ( int, double ) const
218 {
219  assert ( false );
220  return 0.;
221 }
222 
223 void
226 {
227  assert ( false );
228 }
229 
230 double
232 operator () ( double ) const
233 {
234  assert ( false );
235  return 0.;
236 }
237 
238 unsigned int
240 dimensions () const
241 {
242  return 1;
243 }
244 
245 } // namespace hippodraw
246 
virtual void removeFromComposite(FunctionBase *)
Does nothing.
unsigned int i
virtual const std::vector< int > & getFixedFlags() const
Returns the flags indicating which parameters should remain fixed during any minimization process...
virtual bool isComposite() const
Returns false.
virtual double integrate(double lower_limit, double upper_limit) const
Returns the integral of the function from the lower limit to the higher limit.
virtual double operator()(double x) const
The function call operator.
void setName(const char *)
Sets the name of the function.
virtual int size() const
Returns the number of parameters.
std::vector< int > m_fixed_flags
The flags to indicated which parameters are to be held fixed during minimization of this objective fu...
Definition: FunctionBase.h:117
void setParmNames(const std::vector< std::string > &names)
Sets the names of the parameters.
virtual int count()
Returns 0.
virtual unsigned int dimensions() const
Returns the number of dimensions of the data coordinate.
virtual void addToComposite(FunctionBase *)
Does nothing.
virtual void initialize()
Initializes the function and parameter names.
std::vector< double > m_parms
The parameter values.
Definition: FunctionBase.h:109
virtual void setFixedFlags(const std::vector< int > &flags)
Sets to flags indicating that a function parameter is to be held fixed in a minimization process...
virtual FunctionBase * clone() const
Creates a new function object by copying an existing one.
ViewBase * v
Definition: PlotTable.cxx:104
virtual ~FunctionBase()
The virtual destructor.
virtual void initialParameters(const FunctionHelper *helper)
Sets the FunctionHelper so that the function can calculate a reasonable set of initial parameter valu...
virtual bool hasDerivatives() const
Returns true if function can calculate its partial derivatives.
A function that can be added to a DataRep and used in a fitter.
Definition: FunctionBase.h:90
virtual const std::vector< double > & getParameters() const
Returns the values of the parameters as a vector.
An abstract base class to help FunctionBase objects perform some operations.
std::string m_name
The name of the function.
Definition: FunctionBase.h:103
virtual void setParameters(const std::vector< double > &incr)
Sets the parameter values.
std::vector< std::string > m_parm_names
The names of the function parameters.
Definition: FunctionBase.h:106
hippodraw::FunctionBase class interface
virtual void resize()
Re-sizes the appropriate vectors maintained in this base class.
FunctionBase()
The default constructor.
virtual double derivByParm(int i, double x) const
Returns the function&#39;s derivative at the coordinate value x with respect to the i-th parameter...
virtual const std::vector< std::string > & parmNames() const
Returns a reference to a vector of parameter names.
list< QAction * >::iterator it
const std::string & name() const
Returns the name of the function.

Generated for HippoDraw Class Library by doxygen