Parameters.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2004 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/More/MEAL/MEAL/Parameters.h
10 
11 #ifndef __Parameters_H
12 #define __Parameters_H
13 
14 #include "MEAL/ParameterPolicy.h"
15 #include "Estimate.h"
16 #include "Error.h"
17 
18 #include <vector>
19 
20 namespace MEAL {
21 
23  class Parameters : public ParameterPolicy {
24 
25  public:
26 
28  Parameters (Function* context, unsigned nparam = 0);
29 
31  Parameters (const Parameters& np);
32 
34  Parameters& operator = (const Parameters& np);
35 
37  Parameters* clone (Function*) const;
38 
39  // ///////////////////////////////////////////////////////////////////
40  //
41  // Function implementation
42  //
43  // ///////////////////////////////////////////////////////////////////
44 
46  unsigned get_nparam () const
47  {
48  return params.size();
49  }
50 
52  std::string get_name (unsigned index) const
53  {
54  range_check (index, "MEAL::Parameters::get_name");
55  return names[index];
56  }
57 
59  void set_name (unsigned index, const std::string& name)
60  {
61  range_check (index, "MEAL::Parameters::set_name");
62  names[index] = name;
63  }
64 
66  std::string get_description (unsigned index) const
67  {
68  range_check (index, "MEAL::Parameters::get_description");
69  return descriptions[index];
70  }
71 
73  void set_description (unsigned index, const std::string& description)
74  {
75  range_check (index, "MEAL::Parameters::set_description");
76  descriptions[index] = description;
77  }
78 
80  double get_param (unsigned index) const
81  {
82  range_check (index, "MEAL::Parameters::get_param");
83  return params[index].val;
84  }
85 
87  void set_param (unsigned index, double value);
88 
90  void swap_param (unsigned index, double& value);
91 
93  double get_variance (unsigned index) const
94  {
95  range_check (index, "MEAL::Parameters::get_variance");
96  return params[index].var;
97  }
98 
100  void set_variance (unsigned index, double value)
101  {
102  range_check (index, "MEAL::Parameters::set_variance");
103  params[index].var = value;
104  }
105 
107  bool get_infit (unsigned index) const
108  {
109  range_check (index, "MEAL::Parameters::get_infit");
110  return fit[index];
111  }
112 
114  void set_infit (unsigned index, bool flag)
115  {
116  range_check (index, "MEAL::Parameters::set_infit");
117  fit[index] = flag;
118  }
119 
121  void resize (unsigned nparam);
122 
124  void erase (unsigned iparam);
125 
126  protected:
127 
129  void range_check (unsigned index, const char* method) const
130  {
131  if (index >= params.size())
132  throw Error (InvalidRange, method, "index=%d >= nparam=%d",
133  index, params.size());
134  }
135 
136  private:
137 
139  std::vector< Estimate<double> > params;
140 
142  std::vector<bool> fit;
143 
145  std::vector<std::string> names;
146 
148  std::vector<std::string> descriptions;
149 
150  };
151 
152 }
153 
154 #endif
Abstract base class implements parameter storage and access.
Definition: Parameters.h:28
unsigned get_nparam() const
Return the number of parameters.
Definition: Parameters.h:56
void set_description(unsigned index, const std::string &description)
Return the description of the specified parameter.
Definition: Parameters.h:83
Parameters & operator=(const Parameters &np)
Assignment operator.
Definition: Parameters.C:43
void set_param(unsigned index, double value)
Set the value of the specified parameter.
Definition: Parameters.C:69
double get_param(unsigned index) const
Return the value of the specified parameter.
Definition: Parameters.h:90
double get_variance(unsigned index) const
Return the variance of the specified parameter.
Definition: Parameters.h:103
bool get_infit(unsigned index) const
Return true if parameter at index is to be fitted.
Definition: Parameters.h:117
Parameters * clone(Function *) const
Clone construtor.
Definition: Parameters.C:35
std::string get_description(unsigned index) const
Return the description of the specified parameter.
Definition: Parameters.h:76
std::string get_name(unsigned index) const
Return the name of the specified parameter.
Definition: Parameters.h:62
Namespace in which all modeling and calibration related code is declared.
Definition: ExampleComplex2.h:16
void set_variance(unsigned index, double value)
Set the variance of the specified parameter.
Definition: Parameters.h:110
static bool very_verbose
Low-level verbosity flag.
Definition: Function.h:57
void range_check(unsigned index, const char *method) const
Ensure that index <= get_nparam.
Definition: Parameters.h:139
@ ParameterCount
Number of Function parameters, as returned by get_nparam.
Definition: Function.h:169
void erase(unsigned iparam)
Erase the specified parameter.
Definition: Parameters.C:108
Managers of Function parameters.
Definition: ParameterPolicy.h:24
Pure virtual base class of all functions.
Definition: Function.h:49
void resize(unsigned nparam)
Resize arrays, setting fit=true for new parameters.
Definition: Parameters.C:90
void set_infit(unsigned index, bool flag)
Set flag for parameter at index to be fitted.
Definition: Parameters.h:124
void set_name(unsigned index, const std::string &name)
Return the name of the specified parameter.
Definition: Parameters.h:69
Parameters(Function *context, unsigned nparam=0)
Default constructor.
Definition: Parameters.C:13
void swap_param(unsigned index, double &value)
Swap the value of the specified parameter.
Definition: Parameters.C:83

Generated using doxygen 1.8.17