Function.h
1//-*-C++-*-
2/***************************************************************************
3 *
4 * Copyright (C) 2004-2009 by Willem van Straten
5 * Licensed under the Academic Free License version 2.1
6 *
7 ***************************************************************************/
8
9// psrchive/More/MEAL/MEAL/Function.h
10
25
26#ifndef __MEAL_Function_H
27#define __MEAL_Function_H
28
29#include "MEAL/Argument.h"
30#include "MEAL/ArgumentPolicy.h"
31#include "MEAL/ParameterPolicy.h"
32#include "Callback.h"
33#include "Estimate.h"
34
35#include <string>
36
37// forward declaration of text interface
38namespace TextInterface { class Parser; };
39
41
42namespace MEAL {
43
45
49 class Function : public Reference::Able {
50
51 public:
52
54 static bool verbose;
55
57 static bool very_verbose;
58
60 static bool check_zero;
61
63 static bool check_variance;
64
66 static bool cache_results;
67
69 template<class Model>
70 static Model* load (const std::string& filename);
71
73 static Function* load_Function (const std::string& filename);
74
76 static Function* factory (const std::string& text);
77
79 Function ();
80
82 Function (const Function& model);
83
85 Function& operator = (const Function& model);
86
88 virtual ~Function ();
89
91 virtual Function* clone () const;
92
94 virtual void copy (const Function* model);
95
97 template<class T> class Interface;
98
101
103 virtual void parse (const std::string& text);
104
106 virtual void print (std::string& text) const;
107
109 virtual std::string get_name () const = 0;
110
112 virtual std::string get_description () const { return ""; }
113
115 unsigned get_nparam () const
116 { if (parameter_policy) return parameter_policy->get_nparam (); return 0; }
117
119 std::string get_param_name (unsigned index) const
120 { return parameter_policy->get_name (index); }
121
123 std::string get_param_description (unsigned index) const
124 { return parameter_policy->get_description (index); }
125
127 double get_param (unsigned index) const
128 { return parameter_policy->get_param (index); }
129
131 void set_param (unsigned index, double value)
132 { parameter_policy->set_param (index,value); }
133
135 double get_variance (unsigned index) const
136 { return parameter_policy->get_variance (index); }
137
139 void set_variance (unsigned index, double value)
140 { parameter_policy->set_variance (index,value); }
141
143 bool get_infit (unsigned index) const
144 { return parameter_policy->get_infit (index); }
145
147 void set_infit (unsigned index, bool flag)
148 { parameter_policy->set_infit (index,flag); }
149
151 void set_argument (unsigned dimension, Argument* axis)
152 { if (argument_policy) argument_policy->set_argument (dimension, axis); }
153
155 Estimate<double> get_Estimate (unsigned index) const;
156
158 void set_Estimate (unsigned index, const Estimate<double>& param);
159
161 void set_verbose (bool);
162
164 bool get_verbose () const;
165
173
176
178 void set_evaluation_changed (bool _changed = true);
179
181 bool get_evaluation_changed () const { return evaluation_changed; }
182
184 const ParameterPolicy* get_parameter_policy () const
185 { return parameter_policy; }
186
188 ParameterPolicy* get_parameter_policy ()
189 { return parameter_policy; }
190
192 bool has_parameter_policy () const { return parameter_policy; }
193
195 virtual void print_parameters (std::string& text,
196 const std::string& separator) const;
197
198 protected:
199
200 friend class ParameterPolicy;
201
204
205 friend class ArgumentPolicy;
206
209
213
215 void copy_parameter_policy (const Function*);
216
219
222
225
226 private:
227
229 bool evaluation_changed;
230
232 void init ();
233
234 };
235
236}
237
238template<class Model>
239Model* MEAL::Function::load (const std::string& filename)
240{
241 Function* function = load_Function (filename);
242
243 Model* model = dynamic_cast<Model*> (function);
244 if (!model)
245 throw Error (InvalidState, "MEAL::Function::load",
246 "function is not a %s", Model::Name);
247
248 return model;
249}
250
251#endif
Pure virtual base class of function arguments.
Definition Argument.h:25
Textual interface to Function attributes.
Definition FunctionInterface.h:25
Pure virtual base class of all functions.
Definition Function.h:49
void set_param(unsigned index, double value)
Set the value of the specified parameter.
Definition Function.h:131
bool get_infit(unsigned index) const
Return true if parameter at index is to be fitted.
Definition Function.h:143
void set_parameter_policy(ParameterPolicy *policy)
Set the parameter policy.
Definition Function.C:97
static bool cache_results
When set, use the Cached evaluation policy and callbacks.
Definition Function.h:66
virtual void print_parameters(std::string &text, const std::string &separator) const
Prints the values of model parameters and fit flags to a string.
Definition Function_print.C:22
static bool check_variance
When set, some Functions will throw an Error if input variance <= 0.
Definition Function.h:63
virtual void parse(const std::string &text)
Parses the values of model parameters and fit flags from a string.
Definition Function_parse.C:16
virtual void copy(const Function *model)
Does the work for operator =.
Definition Function.C:58
void copy_evaluation_changed(const Function &model)
Copy the evaluation changed state of another model instance.
Definition Function.h:211
virtual std::string get_description() const
Return the description of the class.
Definition Function.h:112
virtual ~Function()
Virtual destructor.
Definition Function.C:45
Function & operator=(const Function &model)
Assignment operator.
Definition Function.C:52
Reference::To< ArgumentPolicy > argument_policy
The policy for managing function arguments.
Definition Function.h:208
Reference::To< ParameterPolicy > parameter_policy
The policy for managing function parameters.
Definition Function.h:203
static bool very_verbose
Low-level verbosity flag.
Definition Function.h:57
Function()
Default constructor.
Definition Function.C:24
bool get_evaluation_changed() const
Return true if the Function evaluation has changed.
Definition Function.h:181
void set_argument(unsigned dimension, Argument *axis)
Set the independent variable of the specified dimension.
Definition Function.h:151
bool set_parameter_policy_context
Set the parameter policy context.
Definition Function.h:221
std::string get_param_description(unsigned index) const
Return the description of the specified parameter.
Definition Function.h:123
bool get_verbose() const
Get the verbosity of this instance.
Definition Function.C:123
void set_Estimate(unsigned index, const Estimate< double > &param)
Set the Estimate of the specified parameter.
Definition Function.C:109
const ParameterPolicy * get_parameter_policy() const
Provide access to the parameter_policy attribute.
Definition Function.h:184
void copy_parameter_policy(const Function *)
Copy the parameter policy of another instance.
Definition Function.C:91
void set_verbose(bool)
Set the verbosity of this instance.
Definition Function.C:117
virtual Function * clone() const
Clone.
Definition Function.C:86
Estimate< double > get_Estimate(unsigned index) const
Return an Estimate of the specified parameter.
Definition Function.C:104
double get_param(unsigned index) const
Return the value of the specified parameter.
Definition Function.h:127
static Function * factory(const std::string &text)
Construct a new Function instance from a string.
Definition Function_factory.C:41
bool has_parameter_policy() const
Some wrappers may not have a parameter policy.
Definition Function.h:192
bool this_verbose
The verbosity of this instance.
Definition Function.h:224
virtual void print(std::string &text) const
Prints the values of model parameters and fit flags to a string.
Definition Function_print.C:14
void set_variance(unsigned index, double value)
Set the variance of the specified parameter.
Definition Function.h:139
void set_infit(unsigned index, bool flag)
Set flag for parameter at index to be fitted.
Definition Function.h:147
ParameterPolicy * get_parameter_policy()
Provide access to the parameter_policy attribute.
Definition Function.h:188
static Model * load(const std::string &filename)
Construct a new Model instance from a file.
Definition Function.h:239
virtual std::string get_name() const =0
Return the name of the class.
unsigned get_nparam() const
Return the number of parameters.
Definition Function.h:115
void set_evaluation_changed(bool _changed=true)
Set true if the Function evaluation has changed.
Definition Function.C:129
static bool verbose
Verbosity flag.
Definition Function.h:54
Attribute
Function attributes that require the attention of Composite models.
Definition Function.h:167
@ ParameterCount
Number of Function parameters, as returned by get_nparam.
Definition Function.h:169
@ Evaluation
Function evaluation, as returned by the evaluate method.
Definition Function.h:171
static Function * load_Function(const std::string &filename)
Construct a new Function instance from a file.
Definition Function_load.C:12
virtual TextInterface::Parser * get_interface()
Return a text interface that can be used to access this instance.
Definition Function.C:148
Callback< Attribute > changed
Callback executed when a Function Attribute has been changed.
Definition Function.h:175
static bool check_zero
When set, some Functions will throw an Error if they evaluate to zero.
Definition Function.h:60
double get_variance(unsigned index) const
Return the variance of the specified parameter.
Definition Function.h:135
std::string get_param_name(unsigned index) const
Return the name of the specified parameter.
Definition Function.h:119
Managers of Function parameters.
Definition ParameterPolicy.h:19
Namespace in which all modeling and calibration related code is declared.
Definition ExampleComplex2.h:16

Generated using doxygen 1.14.0