GPLIB++
GeneralObjective.h
Go to the documentation of this file.
1 #ifndef CGENERALOBJECTIVE_H
2 #define CGENERALOBJECTIVE_H
3 #include "gentypes.h"
4 #include <string>
5 
6 namespace gplib
7  {
8  /** \addtogroup gainv Genetic algorithm optimization */
9  /* @{ */
10  //! The basic object for any objective function, mainly an interface class and some storage
11  /*! All objective functions should be derived from this class to be usable with the genetic algorithms.
12  * Also the linearized classes use this base class to access objective functions.
13  * The main functionality is implemented in the three functions PreParallel, SafeParallel and PostParallel.
14  * This division is ncessary to account for various types of computations in a parallel environment.
15  * In addition derived classes have to implement the clone function and a copy constructor and operator.
16  */
18  {
19  private:
20  //! when calculating the misfit the difference is taken to the power of this exponent (d_i - s_i)^FitExponent
21  int FitExponent;
22  //! the single RMS value
23  double RMS;
24  //! The levmar library wants the whole misfit vector
25  tmisfit Misfit;
26  //! The current synthetic data for the levmar algorithm
27  tdata SynthData;
28  //! Some forward calculations involve writing files, we use ParallelId as a unique identifier for parallel calculations
29  std::string ParallelId;
30  protected:
31  double CalcMisfit(const double measured, const double predicted,
32  const double measerror, const double errorlevel, const int index);
33  void SetRMS(const double x)
34  {
35  RMS = x;
36  }
37  //! Only derived classes can write access the Misfit
39  {
40  return Misfit;
41  }
42  void SetMisfit(const tmisfit &LocalMisfit)
43  {
44  Misfit = LocalMisfit;
45  }
46  //! Only derived classes can write access the Synthetic data
48  {
49  return SynthData;
50  }
51  ;
52  void SetSynthData(const tdata &LocalSynthData)
53  {
54  SynthData = LocalSynthData;
55  }
56  public:
57  //! Set the Fit exponent
58  void SetFitExponent(const int x)
59  {
60  FitExponent = x;
61  }
62  //! Get the Fit exponent
64  {
65  return FitExponent;
66  }
67  //! Get the current RMS
68  double GetRMS()
69  {
70  return RMS;
71  }
72  //! Derived classes need to read the ParallelId for their forward calculations
73  const std::string &GetParallelID()
74  {
75  return ParallelId;
76  }
77  //! We need to set the parallel ID outside the Objective function object
78  void SetParallelID(const std::string &s)
79  {
80  ParallelId = s;
81  }
82  //! Return the misfit vector
83  const tmisfit &GetMisfit()
84  {
85  return Misfit;
86  }
87  //! Return the current synthetic data
89  {
90  return SynthData;
91  }
92  //! We need clone and create for building an array of derived objects, see FAQ lite 20.8, the return type depends on the derived class
93  virtual GeneralObjective *clone() const = 0;
94  //! Some operations cannot be done in parallel, these are done before
95  virtual void PreParallel(const ttranscribed &member);
96  //! Some operations cannot be done in parallel, these are done after, returns the misfit value
97  virtual double PostParallel(const ttranscribed &member) = 0;
98  //! The core performance calculation, has to be safe to be done in parallel
99  virtual void SafeParallel(const ttranscribed &member);
100  //! For serial execution CalcPerformance calls the three Parallel functions for more convenient use
101  double CalcPerformance(const ttranscribed &member);
105  virtual ~GeneralObjective();
106  };
107  /* @} */
108  }
109 #endif // CGENERALOBJECTIVE_H
ublas::vector< double > ttranscribed
Definition: gentypes.h:21
virtual void SafeParallel(const ttranscribed &member)
The core performance calculation, has to be safe to be done in parallel.
double CalcPerformance(const ttranscribed &member)
For serial execution CalcPerformance calls the three Parallel functions for more convenient use...
GeneralObjective & operator=(const GeneralObjective &source)
void SetSynthData(const tdata &LocalSynthData)
virtual double PostParallel(const ttranscribed &member)=0
Some operations cannot be done in parallel, these are done after, returns the misfit value...
virtual void PreParallel(const ttranscribed &member)
Some operations cannot be done in parallel, these are done before.
virtual GeneralObjective * clone() const =0
We need clone and create for building an array of derived objects, see FAQ lite 20.8, the return type depends on the derived class.
int GetFitExponent()
Get the Fit exponent.
const tdata & GetSynthData()
Return the current synthetic data.
void SetMisfit(const tmisfit &LocalMisfit)
double CalcMisfit(const double measured, const double predicted, const double measerror, const double errorlevel, const int index)
void SetParallelID(const std::string &s)
We need to set the parallel ID outside the Objective function object.
const std::string & GetParallelID()
Derived classes need to read the ParallelId for their forward calculations.
double GetRMS()
Get the current RMS.
The basic object for any objective function, mainly an interface class and some storage.
ublas::vector< double > tmisfit
Definition: gentypes.h:18
const tmisfit & GetMisfit()
Return the misfit vector.
tdata & SetSynthData()
Only derived classes can write access the Synthetic data.
tmisfit & SetMisfit()
Only derived classes can write access the Misfit.
ublas::vector< double > tdata
Definition: gentypes.h:19
void SetRMS(const double x)
void SetFitExponent(const int x)
Set the Fit exponent.