COPASI API  4.16.103
CFitProblem.h
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2014 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2005 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #ifndef COPASI_CFitProblem
16 #define COPASI_CFitProblem
17 
19 #include "utilities/CMatrix.h"
20 
21 class CExperimentSet;
23 class CTrajectoryProblem;
24 class CState;
25 class CFitConstraint;
26 class CArrayAnnotation;
27 template < class CMatrixType > class CCopasiMatrixInterface;
28 
29 class CFitProblem : public COptProblem
30 {
31 public:
32  // Operations
33  /**
34  * Default constructor
35  * @param const CCopasiTask::Type & type (default: parameterFitting)
36  * @param const CCopasiContainer * pParent (default: NULL)
37  */
39  const CCopasiContainer * pParent = NULL);
40 
41  /**
42  * Copy constructor.
43  * @param const CFitProblem & src
44  * @param const CCopasiContainer * pParent (default: NULL)
45  */
46  CFitProblem(const CFitProblem & src,
47  const CCopasiContainer * pParent = NULL);
48 
49  /**
50  * Destructor
51  */
52  virtual ~CFitProblem();
53 
54  /**
55  * This methods must be called to elevate subgroups to
56  * derived objects. The default implementation does nothing.
57  * @return bool success
58  */
59  virtual bool elevateChildren();
60 
61  /**
62  * Set the model of the problem
63  * @param CModel * pModel
64  * @result bool success
65  */
66  virtual bool setModel(CModel * pModel);
67 
68  /**
69  * Set the call back of the problem
70  * @param CProcessReport * pCallBack
71  * @result bool success
72  */
73  virtual bool setCallBack(CProcessReport * pCallBack);
74 
75  /**
76  * Do all necessary initialization so that calls to calculate will
77  * be successful. This is called once from CCopasiTask::process()
78  * @result bool success
79  */
80  virtual bool initialize();
81 
82  /**
83  * Do the calculation based on CalculateVariables and fill
84  * CalculateResults with the results.
85  * @result bool continue
86  */
87  virtual bool calculate();
88 
89  /**
90  * Do all necessary restore procedures so that the
91  * model is in the same state as before
92  * @param const bool & updateModel
93  * @result bool success
94  */
95  virtual bool restore(const bool & updateModel);
96 
97  /**
98  * Check whether all functional constraints are fulfilled.
99  * @result bool fulfilled
100  */
101  virtual bool checkFunctionalConstraints();
102 
103  /**
104  * This is the output method for any object. The default implementation
105  * provided with CCopasiObject uses the ostream operator<< of the object
106  * to print the object.To override this default behavior one needs to
107  * reimplement the virtual print function.
108  * @param std::ostream * ostream
109  */
110  virtual void print(std::ostream * ostream) const;
111 
112  /**
113  * Output stream operator
114  * @param ostream & os
115  * @param const CFitProblem & A
116  * @return ostream & os
117  */
118  friend std::ostream &operator<<(std::ostream &os, const CFitProblem & o);
119 
120  /**
121  * This is the output method for any result of a problem. The default implementation
122  * provided with CCopasiProblem. Does only print "Not implemented." To override this
123  * default behavior one needs to reimplement the virtual printResult function.
124  * @param std::ostream * ostream
125  */
126  virtual void printResult(std::ostream * ostream) const;
127 
128  /**
129  * Fetch a new initial state from the model.
130  */
131  void updateInitialState();
132 
133  /**
134  * Set residual required
135  * @param const bool & required
136  * @return bool success
137  */
138  bool setResidualsRequired(const bool & required);
139 
140  /**
141  * Retrieve the vector of residuals
142  * @return const CVector< C_FLOAT64 > & residuals
143  */
144  const CVector< C_FLOAT64 > & getResiduals() const;
145 
146  /**
147  * Calculate the statistics for the problem
148  * @param const C_FLOAT64 & factor (Default: 1.0e-003)
149  * @param const C_FLOAT64 & resolution (Default: 1.0e-009)
150  */
151  virtual bool calculateStatistics(const C_FLOAT64 & factor = 1.0e-003,
152  const C_FLOAT64 & resolution = 1.0e-009);
153 
154  /**
155  * Retrieve the root mean square of the objective value.
156  * @return const C_FLOAT64 & RMS
157  */
158  const C_FLOAT64 & getRMS() const;
159 
160  /**
161  * Retrieve the std. deviation of the objective value.
162  * @return const C_FLOAT64 & stdDeviation
163  */
164  const C_FLOAT64 & getStdDeviation() const;
165 
166  /**
167  * Retrieve the std. deviation for each solution variable.
168  * @return const CVector< C_FLOAT64 > & variableStdDeviations
169  */
171 
172  /**
173  * Retrieve the Fisher Information Matrix of the solution variables.
174  * @return CArrayAnnotation & fisherInformationMatrix
175  */
177 
178  /**
179  * Retrieve the Eigenvalues of the Fisher Information Matrix of the solution variables.
180  * @return CArrayAnnotation & fimEigenvalues
181  */
183 
184  /**
185  * Retrieve the Eigenvectors corresponding to the Eigenvalues of the Fisher Information Matrix of the solution variables.
186  * @return CArrayAnnotation & fimEigenvectors
187  */
189 
190  /**
191  * Retrieve the scaled Fisher Information Matrix of the solution variables.
192  * @return CArrayAnnotation & fisherInformationMatrix
193  */
195 
196  /**
197  * Retrieve the Eigenvalues of the scaled Fisher Information Matrix of the solution variables.
198  * @return CArrayAnnotation & fimEigenvalues
199  */
201 
202  /**
203  * Retrieve the Eigenvectors corresponding to the Eigenvalues of the scaled Fisher Information Matrix of the solution variables.
204  * @return CArrayAnnotation & fimEigenvectors
205  */
207 
208  /**
209  * Retrieve the correlations of the solution variables.
210  * @return CArrayAnnotation & variableCorrelations
211  */
213 
214  /**
215  * Retrieve the experiment set.
216  * @return const CExperimentSet & experiementSet
217  */
218  const CExperimentSet & getExperiementSet() const;
219 
220  /**
221  * Retrieve the cross validation set.
222  * @return const CCrossValidationSet & crossValidationSet
223  */
225 
226  /**
227  * Set the solution.
228  * @param const C_FLOAT64 & value
229  * @param const CVector< C_FLOAT64 > & variables
230  * @return bool continue;
231  */
232  virtual bool setSolution(const C_FLOAT64 & value,
233  const CVector< C_FLOAT64 > & variables);
234 
235  /**
236  * Retrieve the result for the cross validation solution
237  */
239 
240  /**
241  * Retrieve the root mean square of the cross validation solution
242  * @return const C_FLOAT64 & RMS
243  */
244  const C_FLOAT64 & getCrossValidationRMS() const;
245 
246  /**
247  * Retrieve the standard deviation of the cross validation solution
248  * @return const C_FLOAT64 & RMS
249  */
250  const C_FLOAT64 & getCrossValidationSD() const;
251 
252  /**
253  * Fix files written with Version 4.10.55, which wrote the square root of user defined weights for the
254  * parameter fitting task
255  */
256  void fixBuild55();
257 
258  /**
259  * Sets the 'Create Parameter Sets' parameter. When set it will create new model parameter
260  * sets for each experiment after a run.
261  */
262  void setCreateParameterSets(const bool & create);
263 
264  /**
265  * @return the value of the 'Create Parameter Sets' parameter that controls whether parameter
266  * sets should be created automatically.
267  */
268  const bool & getCreateParameterSets() const;
269 
270 private:
271  /**
272  * Allocates all group parameters and assures that they are
273  * properly initialized.
274  */
275  void initializeParameter();
276 
277  virtual bool createObjectiveFunction();
278 
279  /**
280  * Initialize objects
281  */
282  void initObjects();
283 
284  /**
285  * Do the calculation for the cross validation based on the solution variables
286  * and determine whether to continue parameter fitting
287  * @result bool continue
288  */
290 
291 private:
292  // Attributes
293  /**
294  * A pointer to the value of the CCopasiParameter holding the Steady-State CN
295  */
296  std::string * mpParmSteadyStateCN;
297 
298  /**
299  * A pointer to the value of the CCopasiParameter holding the Time Course CN
300  */
301  std::string * mpParmTimeCourseCN;
302 
303  /**
304  * The experiment set to which the model is fitted.
305  */
307 
308  /**
309  * Pointer to CSteadyStateTask. To be used in calculate() to select between
310  * trajectory and steady state method
311  */
313 
314  /**
315  * Pointer to CTrajectory. To be used in calculate() to select between
316  * trajectory and steady state method
317  */
319 
320  /**
321  * Matrix of update methods for items for each experiment.
322  */
324 
325  /**
326  * Matrix of update methods for undoing items which are not used in all experiment.
327  */
329 
330  /**
331  * A vector of refresh methods which contains the sequence of refresh methods
332  * to update the initial values for each experiment.
333  * */
335 
336  /**
337  * Matrix of constraints for each experiment.
338  */
340 
341  /**
342  * A vector of refresh methods which contains the sequence of refresh methods
343  * to update the constraint values for each experiment.
344  * */
346 
347  /**
348  * The simulation values for the experiments.
349  */
351 
352  /**
353  * The experiment set to which the model is fitted.
354  */
356 
357  /**
358  * Matrix of update methods for items for each cross validation.
359  */
361 
362  /**
363  * Matrix of update methods for undoing items which are not used in all cross validations.
364  */
366 
367  /**
368  * A vector of refresh methods which contains the sequence of refresh methods
369  * to update the initial values for each cross validation.
370  * */
372 
373  /**
374  * Matrix of constraints for each experiment.
375  */
377 
378  /**
379  * A vector of refresh methods which contains the sequence of refresh methods
380  * to update the constraint values for each cross validation.
381  * */
383 
384  /**
385  * The simulation values for the experiments.
386  */
388 
389  /**
390  * The objective value of the cross validation set.
391  */
393 
394  /**
395  * The RMS of the cross validation set.
396  */
398 
399  /**
400  * The standard deviation of the cross validation set.
401  */
403 
404  /**
405  * The objective value of the cross validation used to determine when to stop
406  * parameter estimation due to overfitting
407  */
409 
410  /**
411  * A counter to determine whether the threshold is reached.
412  */
414 
415  /**
416  * Copy of the trajectory problem so that we can restore the defaults
417  */
419 
420  /**
421  * Copy of the initial state needed for calculate
422  */
424 
425  /**
426  * Matrix of the residuals.
427  */
429 
430  /**
431  * The root mean square of the solution
432  */
434 
435  /**
436  * The standard deviation of the solution
437  */
439 
440  /**
441  * The vector of standard deviations of the parameters
442  */
444 
445  /**
446  * The Fisher information or parameter correlation matrix
447  */
451 
452  /**
453  * The Fisher information Matrix Eigenvalues and corresponding Eigenvectors
454  */
458 
462 
463  /**
464  * The Fisher information or parameter correlation matrix scaled to parameter values
465  */
469 
470  /**
471  * The scaled Fisher information Matrix Eigenvalues and corresponding Eigenvectors
472  */
476 
480 
481  /**
482  * The parameter correlation matrix
483  */
487 
488  /**
489  * A pointer to the value of the CCopasiParameter holding Create Parameter Sets
490  */
492 
493  /**
494  * The original value of the trajectory update flag
495  */
497 };
498 
499 #endif // COPASI_CFitProblem
CMatrix< C_FLOAT64 > mFisherEigenvectors
Definition: CFitProblem.h:459
CArrayAnnotation * mpFisherMatrix
Definition: CFitProblem.h:450
virtual bool calculate()
CFitProblem(const CCopasiTask::Type &type=CCopasiTask::parameterFitting, const CCopasiContainer *pParent=NULL)
Definition: CFitProblem.cpp:42
C_FLOAT64 mRMS
Definition: CFitProblem.h:433
CCopasiMatrixInterface< CMatrix< C_FLOAT64 > > * mpFisherScaledMatrixInterface
Definition: CFitProblem.h:467
virtual void printResult(std::ostream *ostream) const
bool * mpCreateParameterSets
Definition: CFitProblem.h:491
CVector< std::vector< Refresh * > > mCrossValidationInitialRefreshes
Definition: CFitProblem.h:371
CArrayAnnotation * mpFisherEigenvectorsMatrix
Definition: CFitProblem.h:461
std::string * mpParmSteadyStateCN
Definition: CFitProblem.h:296
C_FLOAT64 mCrossValidationObjective
Definition: CFitProblem.h:408
CMatrix< C_FLOAT64 > mFisher
Definition: CFitProblem.h:448
bool setResidualsRequired(const bool &required)
const C_FLOAT64 & getCrossValidationSolutionValue() const
void updateInitialState()
CMatrix< UpdateMethod * > mExperimentUpdateMethods
Definition: CFitProblem.h:323
C_FLOAT64 mCrossValidationSolutionValue
Definition: CFitProblem.h:392
CCopasiMatrixInterface< CMatrix< C_FLOAT64 > > * mpFisherScaledEigenvectorsMatrixInterface
Definition: CFitProblem.h:478
CArrayAnnotation & getScaledFisherInformationEigenvectors() const
CMatrix< C_FLOAT64 > mCorrelation
Definition: CFitProblem.h:484
const CVector< C_FLOAT64 > & getVariableStdDeviations() const
const bool & getCreateParameterSets() const
Definition: CState.h:305
CTrajectoryProblem * mpTrajectoryProblem
Definition: CFitProblem.h:418
std::string * mpParmTimeCourseCN
Definition: CFitProblem.h:301
bool calculateCrossValidation()
virtual bool calculateStatistics(const C_FLOAT64 &factor=1.0e-003, const C_FLOAT64 &resolution=1.0e-009)
CState * mpInitialState
Definition: CFitProblem.h:423
CVector< C_FLOAT64 > mCrossValidationDependentValues
Definition: CFitProblem.h:387
const CVector< C_FLOAT64 > & getResiduals() const
const CExperimentSet & getExperiementSet() const
CMatrix< CFitConstraint * > mExperimentConstraints
Definition: CFitProblem.h:339
CArrayAnnotation * mpFisherEigenvaluesMatrix
Definition: CFitProblem.h:457
#define C_INT32
Definition: copasi.h:90
CTrajectoryTask * mpTrajectory
Definition: CFitProblem.h:318
CVector< C_FLOAT64 > mExperimentDependentValues
Definition: CFitProblem.h:350
CArrayAnnotation * mpCorrelationMatrix
Definition: CFitProblem.h:486
CArrayAnnotation & getCorrelations() const
const C_FLOAT64 & getCrossValidationRMS() const
virtual bool elevateChildren()
virtual bool setSolution(const C_FLOAT64 &value, const CVector< C_FLOAT64 > &variables)
unsigned C_INT32 mThresholdCounter
Definition: CFitProblem.h:413
CArrayAnnotation * mpFisherScaledEigenvaluesMatrix
Definition: CFitProblem.h:475
virtual bool restore(const bool &updateModel)
CMatrix< C_FLOAT64 > mFisherEigenvalues
Definition: CFitProblem.h:455
virtual ~CFitProblem()
CCopasiMatrixInterface< CMatrix< C_FLOAT64 > > * mpFisherMatrixInterface
Definition: CFitProblem.h:449
CArrayAnnotation & getFisherInformation() const
CVector< std::vector< Refresh * > > mExperimentInitialRefreshes
Definition: CFitProblem.h:334
C_FLOAT64 mSD
Definition: CFitProblem.h:438
void initObjects()
CVector< C_FLOAT64 > mParameterSD
Definition: CFitProblem.h:443
CCopasiMatrixInterface< CMatrix< C_FLOAT64 > > * mpFisherEigenvaluesMatrixInterface
Definition: CFitProblem.h:456
CArrayAnnotation & getScaledFisherInformation() const
virtual bool setModel(CModel *pModel)
CSteadyStateTask * mpSteadyState
Definition: CFitProblem.h:312
CMatrix< C_FLOAT64 > mFisherScaledEigenvalues
Definition: CFitProblem.h:473
CArrayAnnotation & getFisherInformationEigenvalues() const
CArrayAnnotation * mpFisherScaledEigenvectorsMatrix
Definition: CFitProblem.h:479
CArrayAnnotation & getFisherInformationEigenvectors() const
const CCrossValidationSet & getCrossValidationSet() const
CCopasiMatrixInterface< CMatrix< C_FLOAT64 > > * mpFisherScaledEigenvaluesMatrixInterface
Definition: CFitProblem.h:474
CArrayAnnotation & getScaledFisherInformationEigenvalues() const
CCopasiMatrixInterface< CMatrix< C_FLOAT64 > > * mpCorrelationMatrixInterface
Definition: CFitProblem.h:485
CMatrix< UpdateMethod * > mExperimentUndoMethods
Definition: CFitProblem.h:328
CMatrix< C_FLOAT64 > mFisherScaledEigenvectors
Definition: CFitProblem.h:477
CMatrix< CFitConstraint * > mCrossValidationConstraints
Definition: CFitProblem.h:376
virtual bool initialize()
void fixBuild55()
virtual bool setCallBack(CProcessReport *pCallBack)
C_FLOAT64 mCrossValidationRMS
Definition: CFitProblem.h:397
virtual bool createObjectiveFunction()
const C_FLOAT64 & getStdDeviation() const
virtual bool checkFunctionalConstraints()
#define C_FLOAT64
Definition: copasi.h:92
CCrossValidationSet * mpCrossValidationSet
Definition: CFitProblem.h:355
virtual void print(std::ostream *ostream) const
const C_FLOAT64 & getCrossValidationSD() const
CMatrix< C_FLOAT64 > mFisherScaled
Definition: CFitProblem.h:466
void initializeParameter()
CVector< std::vector< Refresh * > > mCrossValidationConstraintRefreshes
Definition: CFitProblem.h:382
Definition: CModel.h:50
CCopasiMatrixInterface< CMatrix< C_FLOAT64 > > * mpFisherEigenvectorsMatrixInterface
Definition: CFitProblem.h:460
void setCreateParameterSets(const bool &create)
CExperimentSet * mpExperimentSet
Definition: CFitProblem.h:306
CArrayAnnotation * mpFisherScaledMatrix
Definition: CFitProblem.h:468
const C_FLOAT64 & getRMS() const
CMatrix< UpdateMethod * > mCrossValidationUndoMethods
Definition: CFitProblem.h:365
bool mTrajectoryUpdate
Definition: CFitProblem.h:496
friend std::ostream & operator<<(std::ostream &os, const CFitProblem &o)
CMatrix< UpdateMethod * > mCrossValidationUpdateMethods
Definition: CFitProblem.h:360
C_FLOAT64 mCrossValidationSD
Definition: CFitProblem.h:402
CVector< C_FLOAT64 > mResiduals
Definition: CFitProblem.h:428
CVector< std::vector< Refresh * > > mExperimentConstraintRefreshes
Definition: CFitProblem.h:345