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
18namespace MEAL {
19
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
Pure virtual base class of all functions.
Definition Function.h:49
double get_param(unsigned index) const
Return the value of the specified parameter.
Definition OneParameter.h:135
bool get_infit() const
Return true if parameter is to be fitted.
Definition OneParameter.h:83
void set_description(const std::string &_description)
Set the description of the parameter.
Definition OneParameter.h:56
double get_variance(unsigned index) const
Return the variance of the specified parameter.
Definition OneParameter.h:149
std::string get_description(unsigned index) const
Return the description of the specified parameter.
Definition OneParameter.h:121
void set_param(unsigned index, double value)
Set the value of the specified parameter.
Definition OneParameter.h:142
void set_description(unsigned index, const std::string &_description)
Set the description of the specified parameter.
Definition OneParameter.h:128
OneParameter & operator=(const OneParameter &np)
Assignment operator.
Definition OneParameter.C:34
void set_name(const std::string &_name)
Set the name of the parameter.
Definition OneParameter.h:44
void set_infit(bool flag=true)
Set flag for parameter to be fitted.
Definition OneParameter.h:89
OneParameter(Function *context=0)
Default constructor.
Definition OneParameter.C:12
std::string get_description() const
Return the description of the parameter.
Definition OneParameter.h:50
bool get_infit(unsigned index) const
Return true if parameter at index is to be fitted.
Definition OneParameter.h:163
void set_variance(double value)
Set the variance of the parameter.
Definition OneParameter.h:77
virtual void set_param(double value)
Set the value of the parameter.
Definition OneParameter.C:52
OneParameter * clone(Function *context) const
Clone operator.
Definition OneParameter.C:26
void set_infit(unsigned index, bool flag)
Set flag for parameter at index to be fitted.
Definition OneParameter.h:170
double get_variance() const
Return the variance of the parameter.
Definition OneParameter.h:71
unsigned get_nparam() const
Return the number of parameters.
Definition OneParameter.h:101
void set_variance(unsigned index, double value)
Set the variance of the specified parameter.
Definition OneParameter.h:156
void set_name(unsigned index, const std::string &_name)
Set the name of the specified parameter.
Definition OneParameter.h:114
std::string get_name() const
Return the name of the parameter.
Definition OneParameter.h:38
std::string get_name(unsigned index) const
Return the name of the specified parameter.
Definition OneParameter.h:107
void range_check(unsigned index, const char *method) const
Ensure that index <= get_nparam.
Definition OneParameter.h:179
virtual double get_param() const
Return the value of the parameter.
Definition OneParameter.h:62
ParameterPolicy(Function *context)
Default destructor.
Definition ParameterPolicy.C:14
Namespace in which all modeling and calibration related code is declared.
Definition ExampleComplex2.h:16

Generated using doxygen 1.14.0