OneParameter.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2005 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/More/MEAL/MEAL/OneParameter.h
10 
11 #ifndef __OneParameter_H
12 #define __OneParameter_H
13 
14 #include "MEAL/ParameterPolicy.h"
15 #include "Estimate.h"
16 #include "Error.h"
17 
18 namespace MEAL {
19 
21  class OneParameter : public ParameterPolicy {
22 
23  public:
24 
26  OneParameter (Function* context = 0);
27 
29  OneParameter (const OneParameter& np);
30 
33 
35  OneParameter* clone (Function* context) const;
36 
38  std::string get_name () const
39  {
40  return name;
41  }
42 
44  void set_name (const std::string& _name)
45  {
46  name = _name;
47  }
48 
50  std::string get_description () const
51  {
52  return description;
53  }
54 
56  void set_description (const std::string& _description)
57  {
58  description = _description;
59  }
60 
62  virtual double get_param () const
63  {
64  return param.val;
65  }
66 
68  virtual void set_param (double value);
69 
71  double get_variance () const
72  {
73  return param.var;
74  }
75 
77  void set_variance (double value)
78  {
79  param.var = value;
80  }
81 
83  bool get_infit () const
84  {
85  return fit;
86  }
87 
89  void set_infit (bool flag = true)
90  {
91  fit = flag;
92  }
93 
94  // ///////////////////////////////////////////////////////////////////
95  //
96  // Function implementation
97  //
98  // ///////////////////////////////////////////////////////////////////
99 
101  unsigned get_nparam () const
102  {
103  return 1;
104  }
105 
107  std::string get_name (unsigned index) const
108  {
109  range_check (index, "MEAL::OneParameter::get_name");
110  return name;
111  }
112 
114  void set_name (unsigned index, const std::string& _name)
115  {
116  range_check (index, "MEAL::OneParameter::set_name");
117  name = _name;
118  }
119 
121  std::string get_description (unsigned index) const
122  {
123  range_check (index, "MEAL::OneParameter::get_description");
124  return description;
125  }
126 
128  void set_description (unsigned index, const std::string& _description)
129  {
130  range_check (index, "MEAL::OneParameter::set_description");
131  description = _description;
132  }
133 
135  double get_param (unsigned index) const
136  {
137  range_check (index, "MEAL::OneParameter::get_param");
138  return get_param ();
139  }
140 
142  void set_param (unsigned index, double value)
143  {
144  range_check (index, "MEAL::OneParameter::set_param");
145  set_param (value);
146  }
147 
149  double get_variance (unsigned index) const
150  {
151  range_check (index, "MEAL::OneParameter::get_variance");
152  return param.var;
153  }
154 
156  void set_variance (unsigned index, double value)
157  {
158  range_check (index, "MEAL::OneParameter::set_variance");
159  param.var = value;
160  }
161 
163  bool get_infit (unsigned index) const
164  {
165  range_check (index, "MEAL::OneParameter::get_infit");
166  return fit;
167  }
168 
170  void set_infit (unsigned index, bool flag)
171  {
172  range_check (index, "MEAL::OneParameter::set_infit");
173  fit = flag;
174  }
175 
176  protected:
177 
179  void range_check (unsigned index, const char* method) const
180  {
181  if (index != 0)
182  throw Error (InvalidRange, method, "index=%d != 0", index);
183  }
184 
185  private:
186 
188  Estimate<double> param;
189 
191  bool fit;
192 
194  std::string name;
195 
197  std::string description;
198 
199  };
200 
201 }
202 
203 #endif
void range_check(unsigned index, const char *method) const
Ensure that index <= get_nparam.
Definition: OneParameter.h:189
Abstract base class implements parameter storage and access.
Definition: OneParameter.h:26
void set_description(const std::string &_description)
Set the description of the parameter.
Definition: OneParameter.h:66
std::string get_description() const
Return the description of the parameter.
Definition: OneParameter.h:60
void set_infit(bool flag=true)
Set flag for parameter to be fitted.
Definition: OneParameter.h:99
virtual void set_param(double value)
Set the value of the parameter.
Definition: OneParameter.C:51
bool get_infit() const
Return true if parameter is to be fitted.
Definition: OneParameter.h:93
void set_name(const std::string &_name)
Set the name of the parameter.
Definition: OneParameter.h:54
OneParameter & operator=(const OneParameter &np)
Assignment operator.
Definition: OneParameter.C:33
OneParameter * clone(Function *context) const
Clone operator.
Definition: OneParameter.C:25
virtual double get_param() const
Return the value of the parameter.
Definition: OneParameter.h:72
Namespace in which all modeling and calibration related code is declared.
Definition: ExampleComplex2.h:16
double get_variance() const
Return the variance of the parameter.
Definition: OneParameter.h:81
static bool very_verbose
Low-level verbosity flag.
Definition: Function.h:57
unsigned get_nparam() const
Return the number of parameters.
Definition: OneParameter.h:111
OneParameter(Function *context=0)
Default constructor.
Definition: OneParameter.C:12
std::string get_name() const
Return the name of the parameter.
Definition: OneParameter.h:48
Managers of Function parameters.
Definition: ParameterPolicy.h:24
Pure virtual base class of all functions.
Definition: Function.h:49
void set_variance(double value)
Set the variance of the parameter.
Definition: OneParameter.h:87

Generated using doxygen 1.8.17