Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Mareframe
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[mareframe] Annotation of /trunk/gadget/keeper.h
[mareframe] / trunk / gadget / keeper.h Repository:
ViewVC logotype

Annotation of /trunk/gadget/keeper.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (view) (download)

1 : agomez 1 #ifndef keeper_h
2 :     #define keeper_h
3 :    
4 :     #include "likelihood.h"
5 :     #include "likelihoodptrvector.h"
6 :     #include "optinfoptrvector.h"
7 :     #include "stochasticdata.h"
8 :     #include "addresskeepermatrix.h"
9 :     #include "strstack.h"
10 :    
11 :     /**
12 :     * \class Keeper
13 :     * \brief This is the class used to store information about the variables that are used in model simulation
14 :     *
15 :     * This class stores all the information about the variables that are used in the model simulation. This includes the current value, the initial value and best value found so far by any optimisation routines, the upper and lower bounds for the variables and a flag to denote whether the variable is to be optimised or not. This class also updates the model parameters with new values for the variables, either as a result of the optimisation routines or when new values for the parameters are received from the network if the simulation is part of a parallel optimisation, using paramin.
16 :     */
17 :     class Keeper {
18 :     public:
19 :     /**
20 :     * \brief This is the default Keeper constructor
21 :     */
22 :     Keeper();
23 :     /**
24 :     * \brief This is the default Keeper destructor
25 :     */
26 :     ~Keeper();
27 :     /**
28 :     * \brief This function will register a variable in the internal list, along with an initial value
29 :     * \param value is the value for the variable
30 :     * \param attr is the name of the Parameter for the variable
31 :     */
32 :     void keepVariable(double& value, Parameter& attr);
33 :     /**
34 :     * \brief This function will delete a variable from the internal list
35 :     * \param var is the value for the variable
36 :     */
37 :     void deleteParameter(const double& var);
38 :     /**
39 :     * \brief This function will replace the value of a variable with a new value
40 :     * \param pre is the old value for the variable
41 :     * \param post is the new value for the variable
42 :     */
43 :     void changeVariable(const double& pre, double& post);
44 :     /**
45 :     * \brief This function will set the text string that is used to describe a variable
46 :     * \param str is the text string to be stored
47 :     */
48 :     void setString(const char* str);
49 :     /**
50 :     * \brief This function will add a text string that is used to describe a variable
51 :     * \param str is the text string to be stored
52 :     */
53 :     void addString(const char* str);
54 :     /**
55 :     * \brief This function will add a text string that is used to describe a variable
56 :     * \param str is the text string to be stored
57 :     */
58 :     void addString(const string str);
59 :     /**
60 :     * \brief This function will remove the last text string from the list used to describe variables
61 :     */
62 :     void clearLast();
63 :     /**
64 :     * \brief This function will remove all of the text strings from the list used to describe variables
65 :     */
66 :     void clearAll();
67 :     /**
68 :     * \brief This function will store the current value of the variables from the optimisation process
69 :     * \param likvalue is the current likelihood value
70 :     * \param point is the DoubleVector of the current parameter values
71 :     */
72 :     void storeVariables(double likvalue, const DoubleVector& point);
73 :     /**
74 :     * \brief This function will reset the variables that have been scaled, to be optimised using the Simulated Annealing optimisation algorithm
75 :     */
76 :     void resetVariables();
77 :     /**
78 :     * \brief This function will scale the variables to be optimised, for the Hooke & Jeeves and BFGS optimisation algorithms
79 :     */
80 :     void scaleVariables();
81 :     /**
82 :     * \brief This function will return a copy of the flags to denote which variables will be optimsised
83 :     * \param opt is the IntVector that will contain a copy of the flags
84 :     */
85 :     void getOptFlags(IntVector& opt) const;
86 :     /**
87 :     * \brief This function will return a copy of the names of the variables
88 :     * \param sw is the ParameterVector that will contain a copy of the names
89 :     */
90 :     void getSwitches(ParameterVector& sw) const;
91 :     /**
92 :     * \brief This function will return a copy of the lower bounds of the variables
93 :     * \param lbs is the DoubleVector that will contain a copy of the lower bounds
94 :     */
95 :     void getLowerBounds(DoubleVector& lbs) const;
96 :     /**
97 :     * \brief This function will return a copy of the upper bounds of the variables
98 :     * \param ubs is the DoubleVector that will contain a copy of the upper bounds
99 :     */
100 :     void getUpperBounds(DoubleVector& ubs) const;
101 :     /**
102 :     * \brief This function will return a copy of the initial value of the variables
103 :     * \param val is the DoubleVector that will contain a copy of the initial values
104 :     */
105 :     void getInitialValues(DoubleVector& val) const;
106 :     /**
107 :     * \brief This function will return a copy of the scaled value of the variables
108 :     * \param val is the DoubleVector that will contain a copy of the scaled values
109 :     */
110 :     void getScaledValues(DoubleVector& val) const;
111 :     /**
112 :     * \brief This function will return a copy of the current value of the variables
113 :     * \param val is the DoubleVector that will contain a copy of the current values
114 :     */
115 :     void getCurrentValues(DoubleVector& val) const;
116 :     /**
117 :     * \brief This function will return a copy of the lower bounds of the variables to be optimised
118 :     * \param lbs is the DoubleVector that will contain a copy of the lower bounds
119 :     */
120 :     void getOptLowerBounds(DoubleVector& lbs) const;
121 :     /**
122 :     * \brief This function will return a copy of the upper bounds of the variables to be optimised
123 :     * \param ubs is the DoubleVector that will contain a copy of the upper bounds
124 :     */
125 :     void getOptUpperBounds(DoubleVector& ubs) const;
126 :     /**
127 :     * \brief This function will return a copy of the initial value of the variables to be optimised
128 :     * \param val is the DoubleVector that will contain a copy of the initial values
129 :     */
130 :     void getOptInitialValues(DoubleVector& val) const;
131 :     /**
132 :     * \brief This function will return a copy of the scaled value of the variables to be optimised
133 :     * \param val is the DoubleVector that will contain a copy of the scaled values
134 :     */
135 :     void getOptScaledValues(DoubleVector& val) const;
136 :     /**
137 :     * \brief This function will return the number of variables
138 :     * \return number of variables
139 :     */
140 :     int numVariables() const;
141 :     /**
142 :     * \brief This function will return the number of variables to be optimised
143 :     * \return number of variables to be optimised
144 :     */
145 :     int numOptVariables() const { return numoptvar; };
146 :     /**
147 :     * \brief This function will update one Keeper variable with a new value
148 :     * \param pos is the identifier of the variable to update
149 :     * \param value is the new value of the variable
150 :     */
151 :     void Update(int pos, double& value);
152 :     /**
153 :     * \brief This function will update the Keeper variables with new values from a vector
154 :     * \param val is the DoubleVector containing the new values of the variables
155 :     */
156 :     void Update(const DoubleVector& val);
157 :     /**
158 :     * \brief This function will update the Keeper variables with new values from StochasticData
159 :     * \param Stoch is the StochasticData containing the new values of the variables
160 :     */
161 :     void Update(const StochasticData* const Stoch);
162 :     /**
163 :     * \brief This function will open the output file and write header information
164 :     * \param filename is the name of the file to write the model information to
165 :     */
166 :     void openPrintFile(const char* const filename);
167 :     /**
168 :     * \brief This function will write header information about the model parameters to file
169 :     * \param likevec is the LikelihoodPtrVector containing the likelihood components for the current model
170 :     */
171 :     void writeInitialInformation(const LikelihoodPtrVector& likevec);
172 :     /**
173 :     * \brief This function will write current information about the model parameters to file
174 :     * \param likevec is the LikelihoodPtrVector containing the likelihood components for the current model
175 :     * \param prec is the precision to use in the output file
176 :     */
177 :     void writeValues(const LikelihoodPtrVector& likevec, int prec);
178 :     /**
179 :     * \brief This function will write final information about the model parameters to file in a column format (which can then be used as the starting point for a subsequent model run)
180 :     * \param optvec is the OptInfoPtrVector containing the optimisation algorithms used for the current model
181 :     * \param filename is the name of the file to write the model information to
182 :     * \param prec is the precision to use in the output file
183 :     * \param interrupt is the flag to denote whether the current run was interrupted by the user or not
184 :     */
185 :     void writeParams(const OptInfoPtrVector& optvec, const char* const filename, int prec, int interrupt);
186 :     /**
187 :     * \brief This function will display information about the best values of the parameters found so far during an optimisation run
188 :     */
189 :     void writeBestValues();
190 :     /**
191 :     * \brief This function will check that the values of the parameters are within the bounds specified in the input file
192 :     * \param likevec is the LikelihoodPtrVector containing the likelihood components for the current model
193 :     */
194 :     void checkBounds(const LikelihoodPtrVector& likevec) const;
195 :     /**
196 :     * \brief This function will return the flag used to denote whether the bounds of the parameters have been specified or not
197 :     * \return flag to denote whether the bounds have been given or not
198 :     */
199 :     int boundsGiven() const { return boundsgiven; };
200 :     /**
201 :     * \brief This function will return the best likelihood score found so far by the optimisation process
202 :     * \return bestlikelihood
203 :     */
204 :     double getBestLikelihoodScore() const { return bestlikelihood; };
205 : ulcessvp 11 //FIXME doc
206 :     DoubleVector getValues() {return values;}
207 : agomez 1 protected:
208 :     /**
209 :     * \brief This is the AddressKeeperMatrix used to store information about the value and name of the parameters
210 :     */
211 :     AddressKeeperMatrix address;
212 :     /**
213 :     * \brief This is the DoubleVector used to store the initial values of the parameters
214 :     */
215 :     DoubleVector initialvalues;
216 :     /**
217 :     * \brief This is the DoubleVector used to store the scaled values of the parameters
218 :     */
219 :     DoubleVector scaledvalues;
220 :     /**
221 :     * \brief This is the DoubleVector used to store the values of the parameters
222 :     */
223 :     DoubleVector values;
224 :     /**
225 :     * \brief This is the DoubleVector used to store the best values of the parameters that the optimisation process has found so far
226 :     */
227 :     DoubleVector bestvalues;
228 :     /**
229 :     * \brief This is the IntVector used to store information about whether the parameters are to be optimised
230 :     * \note If opt[i] is 1 then parameter i is to be optimised, else if opt[i] is 0 then parameter i is not to be optimised and its value is fixed throughout the optimisation process
231 :     */
232 :     IntVector opt;
233 :     /**
234 :     * \brief This is the StrStack used to store information about the use of the parameters
235 :     */
236 :     StrStack* stack;
237 :     /**
238 :     * \brief This is the ParameterVector used to store information about the names of the parameters
239 :     */
240 :     ParameterVector switches;
241 :     /**
242 :     * \brief This is the DoubleVector used to store information about the lower bounds of the parameters
243 :     */
244 :     DoubleVector lowerbds;
245 :     /**
246 :     * \brief This is the DoubleVector used to store information about the upper bounds of the parameters
247 :     */
248 :     DoubleVector upperbds;
249 :     /**
250 :     * \brief This is the number of parameters to be optimised
251 :     */
252 :     int numoptvar;
253 :     /**
254 :     * \brief This is the flag used to denote whether the bounds of the parameters have been specified or not
255 :     */
256 :     int boundsgiven;
257 :     /**
258 :     * \brief This is the best likelihood score found so far by the optimisation process
259 :     */
260 :     double bestlikelihood;
261 :     /**
262 :     * \brief This is the flag used to denote whether an output file has been specified or not
263 :     */
264 :     int fileopen;
265 :     /**
266 :     * \brief This ofstream is the file that all the parameter information gets sent to
267 :     */
268 :     ofstream outfile;
269 :     };
270 :    
271 :     #endif

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge