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/stomachcontent.h
[mareframe] / trunk / gadget / stomachcontent.h Repository:
ViewVC logotype

Annotation of /trunk/gadget/stomachcontent.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : agomez 1 #ifndef stomachcontent_h
2 :     #define stomachcontent_h
3 :    
4 :     #include "commentstream.h"
5 :     #include "lengthgroup.h"
6 :     #include "predatorptrvector.h"
7 :     #include "preyptrvector.h"
8 :     #include "doublematrixptrmatrix.h"
9 :     #include "intmatrix.h"
10 :     #include "formulamatrix.h"
11 :     #include "actionattimes.h"
12 :     #include "charptrmatrix.h"
13 :     #include "predatoraggregator.h"
14 :     #include "multinomial.h"
15 :    
16 :     /**
17 :     * \class SC
18 :     * \brief This is the base class used to calculate the stomach content likelihood score based on the consumption of the preys in the model and the stomach content data specified in the input files
19 :     * \note This will always be overridden by the derived classes that actually calculate the stomach content likelihood score
20 :     */
21 :     class SC : public HasName {
22 :     public:
23 :     /**
24 :     * \brief This is the SC constructor
25 :     * \param infile is the CommentStream to read the SC data from
26 :     * \param Area is the AreaClass for the current model
27 :     * \param TimeInfo is the TimeClass for the current model
28 :     * \param keeper is the Keeper for the current model
29 :     * \param datafilename is the name of the file containing the SC data
30 :     * \param givenname is the name for the likelihood component
31 :     */
32 :     SC(CommentStream& infile, const AreaClass* const Area, const TimeClass* const TimeInfo,
33 :     Keeper* const keeper, const char* datafilename, const char* givenname);
34 :     /**
35 :     * \brief This is the default SC destructor
36 :     */
37 :     virtual ~SC();
38 :     /**
39 :     * \brief This function will calculate the likelihood score from the SC information
40 :     * \param TimeInfo is the TimeClass for the current model
41 :     * \return likelihood score
42 :     */
43 :     virtual double calcLikelihood(const TimeClass* const TimeInfo);
44 :     /**
45 :     * \brief This function will reset the SC information
46 :     */
47 :     virtual void Reset();
48 :     /**
49 :     * \brief This function will print the summary SC information
50 :     * \param outfile is the ofstream that all the model information gets sent to
51 :     */
52 :     virtual void Print(ofstream& outfile) const;
53 :     /**
54 :     * \brief This will select the predators and preys required to calculate the SC likelihood score
55 :     * \param Predators is the PredatorPtrVector of all the available predators
56 :     * \param Preys is the PreyPtrVector of all the available preys
57 :     */
58 :     virtual void setPredatorsAndPreys(PredatorPtrVector& Predators, PreyPtrVector& Preys);
59 :     /**
60 :     * \brief This function will print summary information from each StomachContent likelihood calculation
61 :     * \param outfile is the ofstream that all the model likelihood information gets sent to
62 :     * \param weight is the weight for the likelihood component
63 :     */
64 :     virtual void printSummary(ofstream& outfile, double weight);
65 :     /**
66 :     * \brief This function will print information from each StomachContent calculation
67 :     * \param outfile is the ofstream that all the model likelihood information gets sent to
68 :     * \param TimeInfo is the TimeClass for the current model
69 :     */
70 :     virtual void printLikelihood(ofstream& outfile, const TimeClass* const TimeInfo);
71 :     /**
72 :     * \brief This function will aggregate consumption information for each StomachContent calculation
73 :     * \param i is the index of the prey that is being consumed
74 :     */
75 :     virtual void aggregate(int i);
76 :     protected:
77 :     /**
78 :     * \brief This function will calculate the likelihood score from the SC information
79 :     * \return 0 (will be overridden in derived classes)
80 :     */
81 :     virtual double calcLikelihood() = 0;
82 :     /**
83 :     * \brief This is the DoubleMatrixPtrMatrix used to store stomach content (consumption) information specified in the input file
84 :     * \note The indices for this object are [time][area][predator][prey]
85 :     */
86 :     DoubleMatrixPtrMatrix obsConsumption;
87 :     /**
88 :     * \brief This is the DoubleMatrixPtrMatrix used to store consumption (stomach content) information calculated in the model
89 :     * \note The indices for this object are [time][area][predator][prey]
90 :     */
91 :     DoubleMatrixPtrMatrix modelConsumption;
92 :     /**
93 :     * \brief This is the DoubleMatrix used to store the calculated likelihood information
94 :     * \note The indices for this object are [time][area]
95 :     */
96 :     DoubleMatrix likelihoodValues;
97 :     /**
98 :     * \brief This is the CharPtrVector of the names of the predators that will be used to calculate the likelihood score
99 :     */
100 :     CharPtrVector predatornames;
101 :     /**
102 :     * \brief This is the CharPtrMatrix of the names of the preys that will be used to calculate the likelihood score
103 :     */
104 :     CharPtrMatrix preynames;
105 :     /**
106 :     * \brief This is the CharPtrVector of the names of the areas
107 :     */
108 :     CharPtrVector areaindex;
109 :     /**
110 :     * \brief This is the CharPtrVector of the names of the predator aggregation units (either age or length) that will be read in from the input file
111 :     */
112 :     CharPtrVector predindex;
113 :     /**
114 :     * \brief This is the CharPtrVector of the names of the prey aggregation units that will be read in from the input file
115 :     */
116 :     CharPtrVector preyindex;
117 :     /**
118 :     * \brief This is the IntVector used to store information about the years when the likelihood score should be calculated
119 :     */
120 :     IntVector Years;
121 :     /**
122 :     * \brief This is the IntVector used to store information about the steps when the likelihood score should be calculated
123 :     */
124 :     IntVector Steps;
125 :     /**
126 :     * \brief This is the DoubleVector used to store predator length information
127 :     */
128 :     DoubleVector predatorlengths;
129 :     /**
130 :     * \brief This is the IntMatrix used to store predator age information
131 :     */
132 :     IntMatrix predatorages;
133 :     /**
134 :     * \brief This is the DoubleMatrix used to store prey length information
135 :     * \note The indices for this object are [prey number][prey length]
136 :     */
137 :     DoubleMatrix preylengths;
138 :     /**
139 :     * \brief This is the IntMatrix used to store area information
140 :     */
141 :     IntMatrix areas;
142 :     /**
143 :     * \brief This is the flag used to denote whether the predators are specified using age groups or length groups
144 :     */
145 :     int usepredages;
146 :     /**
147 :     * \brief This is the PredatorAggregator used to collect information about the predation
148 :     */
149 :     PredatorAggregator** aggregator;
150 :     /**
151 :     * \brief This is the LengthGroupDivision used to store predator length information
152 :     */
153 :     LengthGroupDivision** preyLgrpDiv;
154 :     /**
155 :     * \brief This is the LengthGroupDivision used to store prey length information
156 :     */
157 :     LengthGroupDivision* predLgrpDiv;
158 :     /**
159 :     * \brief This is the index of the timesteps for the likelihood component data
160 :     */
161 :     int timeindex;
162 :     /**
163 :     * \brief This ActionAtTimes stores information about when the likelihood score should be calculated
164 :     */
165 :     ActionAtTimes AAT;
166 :     /**
167 :     * \brief This is the FormulaMatrix used to store the digestion parameters for the various predator prey pairs
168 :     */
169 :     FormulaMatrix digestioncoeff;
170 :     /**
171 :     * \brief This is the DoubleMatrix used to store the calculated digestion coefficiants for the various predator prey pairs
172 :     */
173 :     DoubleMatrix digestion;
174 :     /**
175 :     * \brief This is the value of epsilon used when calculating the likelihood score
176 :     */
177 :     double epsilon;
178 :     /**
179 :     * \brief This is the DoubleMatrix used to temporarily store the information returned from the aggregatation function
180 :     */
181 :     const DoubleMatrix* dptr;
182 :     };
183 :    
184 :     /**
185 :     * \class SCNumbers
186 :     * \brief This is the class used to calculate the stomach content likelihood score based on a function of the numbers of prey consumed
187 :     */
188 :     class SCNumbers : public SC {
189 :     public:
190 :     /**
191 :     * \brief This is the SCNumbers constructor
192 :     * \param infile is the CommentStream to read the SCNumbers data from
193 :     * \param Area is the AreaClass for the current model
194 :     * \param TimeInfo is the TimeClass for the current model
195 :     * \param keeper is the Keeper for the current model
196 :     * \param datafilename is the name of the file containing the SCNumbers data
197 :     * \param givenname is the name for the likelihood component
198 :     */
199 :     SCNumbers(CommentStream& infile, const AreaClass* const Area, const TimeClass* const TimeInfo,
200 :     Keeper* const keeper, const char* datafilename, const char* givenname);
201 :     /**
202 :     * \brief This is the default SCNumbers destructor
203 :     */
204 :     virtual ~SCNumbers() {};
205 :     /**
206 :     * \brief This function will aggregate consumption information for each StomachContent calculation
207 :     * \param i is the index of the prey that is being consumed
208 :     */
209 :     virtual void aggregate(int i);
210 :     protected:
211 :     /**
212 :     * \brief This function will read the StomachContent numbers data from the input file
213 :     * \param infile is the CommentStream to read the StomachContent data from
214 :     * \param TimeInfo is the TimeClass for the current model
215 :     */
216 :     void readStomachNumberContent(CommentStream& infile, const TimeClass* const TimeInfo);
217 :     /**
218 :     * \brief This function will calculate the likelihood score from the SCNumbers information
219 :     * \return likelihood score
220 :     */
221 :     virtual double calcLikelihood();
222 :     /**
223 :     * \brief This is the Multinomial that is used when calculating the likelihood score
224 :     */
225 :     Multinomial MN;
226 :     /**
227 :     * \brief This is the DoubleVector used to temporarily store the observed consumption when calculating the likelihood score
228 :     */
229 :     DoubleVector mndata;
230 :     /**
231 :     * \brief This is the DoubleVector used to temporarily store the modelled consumption when calculating the likelihood score
232 :     */
233 :     DoubleVector mndist;
234 :     };
235 :    
236 :     /**
237 :     * \class SCAmounts
238 :     * \brief This is the class used to calculate the stomach content likelihood score based on a function of the amount of prey consumed, the standard deviation of this amount and the number of stomachs sampled
239 :     */
240 :     class SCAmounts : public SC {
241 :     public:
242 :     /**
243 :     * \brief This is the SCAmounts constructor
244 :     * \param infile is the CommentStream to read the SCAmounts data from
245 :     * \param Area is the AreaClass for the current model
246 :     * \param TimeInfo is the TimeClass for the current model
247 :     * \param keeper is the Keeper for the current model
248 :     * \param datafilename is the name of the file containing the SCAmounts data
249 :     * \param numfilename is the name of the file containing the SCAmounts numbers data
250 :     * \param givenname is the name for the likelihood component
251 :     */
252 :     SCAmounts(CommentStream& infile, const AreaClass* const Area,
253 :     const TimeClass* const TimeInfo, Keeper* const keeper,
254 :     const char* datafilename, const char* numfilename, const char* givenname);
255 :     /**
256 :     * \brief This is the default SCAmounts destructor
257 :     */
258 :     virtual ~SCAmounts();
259 :     /**
260 :     * \brief This function will print information from each SCAmounts calculation
261 :     * \param outfile is the ofstream that all the model likelihood information gets sent to
262 :     * \param TimeInfo is the TimeClass for the current model
263 :     */
264 :     virtual void printLikelihood(ofstream& outfile, const TimeClass* const TimeInfo);
265 :     protected:
266 :     /**
267 :     * \brief This function will read the StomachContent amount data from the input file
268 :     * \param infile is the CommentStream to read the StomachContent data from
269 :     * \param TimeInfo is the TimeClass for the current model
270 :     */
271 :     void readStomachAmountContent(CommentStream& infile, const TimeClass* const TimeInfo);
272 :     /**
273 :     * \brief This function will read the StomachContent sample data from the input file
274 :     * \param infile is the CommentStream to read the StomachContent data from
275 :     * \param TimeInfo is the TimeClass for the current model
276 :     */
277 :     void readStomachSampleContent(CommentStream& infile, const TimeClass* const TimeInfo);
278 :     /**
279 :     * \brief This function will calculate the likelihood score from the SCAmounts information
280 :     * \return likelihood score
281 :     */
282 :     virtual double calcLikelihood();
283 :     /**
284 :     * \brief This is the DoubleMatrixPtrMatrix used to store the standard deviation values for the consumption information specified in the input file
285 :     * \note The indices for this object are [time][area][predator][prey]
286 :     */
287 :     DoubleMatrixPtrMatrix stddev;
288 :     /**
289 :     * \brief This is the DoubleMatrixPtrVector used to store the number of stomach samples specified in the input file
290 :     * \note The indices for this object are [time][area][predator]
291 :     */
292 :     DoubleMatrixPtrVector number;
293 :     };
294 :    
295 :     /**
296 :     * \class SCRatios
297 :     * \brief This is the class used to calculate the stomach content likelihood score based on a function of the ratios of the prey consumed, the standard deviation of this ratio and the number of stomachs sampled
298 :     */
299 :     class SCRatios : public SCAmounts {
300 :     public:
301 :     /**
302 :     * \brief This is the SCRatios constructor
303 :     * \param infile is the CommentStream to read the SCRatios data from
304 :     * \param Area is the AreaClass for the current model
305 :     * \param TimeInfo is the TimeClass for the current model
306 :     * \param keeper is the Keeper for the current model
307 :     * \param datafilename is the name of the file containing the SCRatios data
308 :     * \param numfilename is the name of the file containing the SCRatios numbers data
309 :     * \param givenname is the name for the likelihood component
310 :     */
311 :     SCRatios(CommentStream& infile, const AreaClass* const Area,
312 :     const TimeClass* const TimeInfo, Keeper* const keeper,
313 :     const char* datafilename, const char* numfilename, const char* givenname)
314 :     : SCAmounts(infile, Area, TimeInfo, keeper, datafilename, numfilename, givenname) {};
315 :     /**
316 :     * \brief This is the default SCRatios destructor
317 :     */
318 :     virtual ~SCRatios() {};
319 :     /**
320 :     * \brief This will select the predators and preys required to calculate the SCRatios likelihood score
321 :     * \param Predators is the PredatorPtrVector of all the available predators
322 :     * \param Preys is the PreyPtrVector of all the available preys
323 :     */
324 :     virtual void setPredatorsAndPreys(PredatorPtrVector& Predators, PreyPtrVector& Preys);
325 :     protected:
326 :     /**
327 :     * \brief This function will calculate the likelihood score from the SCRatios information
328 :     * \return likelihood score
329 :     */
330 :     virtual double calcLikelihood();
331 :     };
332 :    
333 :     /**
334 :     * \class SCSimple
335 :     * \brief This is the class used to calculate the stomach content likelihood score based on a simple function of the ratios of the prey consumed
336 :     */
337 :     class SCSimple : public SC {
338 :     public:
339 :     /**
340 :     * \brief This is the SCSimple constructor
341 :     * \param infile is the CommentStream to read the SCNumbers data from
342 :     * \param Area is the AreaClass for the current model
343 :     * \param TimeInfo is the TimeClass for the current model
344 :     * \param keeper is the Keeper for the current model
345 :     * \param datafilename is the name of the file containing the SCSimple data
346 :     * \param givenname is the name for the likelihood component
347 :     */
348 :     SCSimple(CommentStream& infile, const AreaClass* const Area, const TimeClass* const TimeInfo,
349 :     Keeper* const keeper, const char* datafilename, const char* givenname);
350 :     /**
351 :     * \brief This is the default SCSimple destructor
352 :     */
353 :     virtual ~SCSimple() {};
354 :     /**
355 :     * \brief This will select the predators and preys required to calculate the SCSimple likelihood score
356 :     * \param Predators is the PredatorPtrVector of all the available predators
357 :     * \param Preys is the PreyPtrVector of all the available preys
358 :     */
359 :     virtual void setPredatorsAndPreys(PredatorPtrVector& Predators, PreyPtrVector& Preys);
360 :     protected:
361 :     /**
362 :     * \brief This function will read the StomachContent amount data from the input file
363 :     * \param infile is the CommentStream to read the StomachContent data from
364 :     * \param TimeInfo is the TimeClass for the current model
365 :     */
366 :     void readStomachSimpleContent(CommentStream& infile, const TimeClass* const TimeInfo);
367 :     /**
368 :     * \brief This function will calculate the likelihood score from the SCSimple information
369 :     * \return likelihood score
370 :     */
371 :     virtual double calcLikelihood();
372 :     };
373 :    
374 :     /**
375 :     * \class StomachContent
376 :     * \brief This is the class used to calculate a likelihood score based on data sampled from the stomach of stocks caught by fleets
377 :     *
378 :     * This class calculates a likelihood score based on the difference between stomach contents data sampled from stocks caught according to the model and that caught by fleets, according to the landings data. The stomach contents data can either be aggregated into length groups (giving a distribution of prey groups for each length) or into prey groups (giving a distribution of length groups for each prey). The model will calculate the stomach contents data for the predators that are caught according to the model parameters, and then compare this to the corresponding data calculated from the observed stomach contents data
379 :     *
380 :     * \note Care is needed when making this comparison, since the data will give information on the stomach content at the time of capture of the predator, where as the model can only give information about the modelled consumption of the prey by the predator.
381 :     */
382 :     class StomachContent : public Likelihood {
383 :     public:
384 :     /**
385 :     * \brief This is the StomachContent constructor
386 :     * \param infile is the CommentStream to read the StomachContent data from
387 :     * \param Area is the AreaClass for the current model
388 :     * \param TimeInfo is the TimeClass for the current model
389 :     * \param keeper is the Keeper for the current model
390 :     * \param weight is the weight for the likelihood component
391 :     * \param name is the name for the likelihood component
392 :     */
393 :     StomachContent(CommentStream& infile, const AreaClass* const Area,
394 :     const TimeClass* const TimeInfo, Keeper* const keeper, double weight, const char* name);
395 :     /**
396 :     * \brief This is the default StomachContent destructor
397 :     */
398 :     virtual ~StomachContent();
399 :     /**
400 :     * \brief This function will calculate the likelihood score for the StomachContent component
401 :     * \param TimeInfo is the TimeClass for the current model
402 :     */
403 :     virtual void addLikelihood(const TimeClass* const TimeInfo);
404 :     /**
405 :     * \brief This function will reset the StomachContent likelihood information
406 :     * \param keeper is the Keeper for the current model
407 :     */
408 :     virtual void Reset(const Keeper* const keeper);
409 :     /**
410 :     * \brief This function will print the summary StomachContent likelihood information
411 :     * \param outfile is the ofstream that all the model information gets sent to
412 :     */
413 :     virtual void Print(ofstream& outfile) const;
414 :     /**
415 :     * \brief This will select the predators and preys required to calculate the StomachContent likelihood score
416 :     * \param Predators is the PredatorPtrVector of all the available predators
417 :     * \param Preys is the PreyPtrVector of all the available preys
418 :     */
419 :     void setPredatorsAndPreys(PredatorPtrVector& Predators, PreyPtrVector& Preys)
420 :     { StomCont->setPredatorsAndPreys(Predators, Preys); };
421 :     /**
422 :     * \brief This function will print summary information from each StomachContent likelihood calculation
423 :     * \param outfile is the ofstream that all the model likelihood information gets sent to
424 :     */
425 :     virtual void printSummary(ofstream& outfile) {
426 :     StomCont->printSummary(outfile, weight); };
427 :     /**
428 :     * \brief This function will print information from each StomachContent calculation
429 :     * \param outfile is the ofstream that all the model likelihood information gets sent to
430 :     * \param TimeInfo is the TimeClass for the current model
431 :     */
432 :     virtual void printLikelihood(ofstream& outfile, const TimeClass* const TimeInfo) {
433 :     StomCont->printLikelihood(outfile, TimeInfo); };
434 :     private:
435 :     /**
436 :     * \brief This is the name of the function to be used to calculate the likelihood component
437 :     */
438 :     char* functionname;
439 :     /**
440 :     * \brief This is the SC used to calculate the likelihood score by calulating the consumption from the modelled data and comparing it to the stomach contents data specified in the input file
441 :     */
442 :     SC* StomCont;
443 :     };
444 :    
445 :     #endif
446 :    

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

Powered By FusionForge