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
20namespace 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
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
Pure virtual base class of all functions.
Definition Function.h:49
ParameterPolicy(Function *context)
Default destructor.
Definition ParameterPolicy.C:14
double get_param(unsigned index) const
Return the value of the specified parameter.
Definition Parameters.h:80
unsigned get_nparam() const
Return the number of parameters.
Definition Parameters.h:46
void swap_param(unsigned index, double &value)
Swap the value of the specified parameter.
Definition Parameters.C:83
Parameters * clone(Function *) const
Clone construtor.
Definition Parameters.C:35
double get_variance(unsigned index) const
Return the variance of the specified parameter.
Definition Parameters.h:93
std::string get_name(unsigned index) const
Return the name of the specified parameter.
Definition Parameters.h:52
void set_infit(unsigned index, bool flag)
Set flag for parameter at index to be fitted.
Definition Parameters.h:114
std::string get_description(unsigned index) const
Return the description of the specified parameter.
Definition Parameters.h:66
void set_name(unsigned index, const std::string &name)
Return the name of the specified parameter.
Definition Parameters.h:59
void erase(unsigned iparam)
Erase the specified parameter.
Definition Parameters.C:108
Parameters(Function *context, unsigned nparam=0)
Default constructor.
Definition Parameters.C:13
void set_description(unsigned index, const std::string &description)
Return the description of the specified parameter.
Definition Parameters.h:73
Parameters & operator=(const Parameters &np)
Assignment operator.
Definition Parameters.C:43
void resize(unsigned nparam)
Resize arrays, setting fit=true for new parameters.
Definition Parameters.C:90
void range_check(unsigned index, const char *method) const
Ensure that index <= get_nparam.
Definition Parameters.h:129
bool get_infit(unsigned index) const
Return true if parameter at index is to be fitted.
Definition Parameters.h:107
void set_param(unsigned index, double value)
Set the value of the specified parameter.
Definition Parameters.C:69
void set_variance(unsigned index, double value)
Set the variance of the specified parameter.
Definition Parameters.h:100
Namespace in which all modeling and calibration related code is declared.
Definition ExampleComplex2.h:16

Generated using doxygen 1.14.0