GeneticAlgoithm
Implementation of the genetic algorithm
Chi2FitFigureOfMerit.h
1 #ifndef CHI2FITFIGUREOFMERIT_H
2 #define CHI2FITFIGUREOFMERIT_H
3 
4 #include "IFigureOfMerit.h"
5 
6 #include <vector>
7 
8 class IModel;
9 
10 /**
11  * @brief Class implementing a \f$\chi^2/ndf\f$ figure of merit.
12  *
13  * The \f$\chi^2/ndf\f$ is computed by comparing a model to a dataset:
14  * - The data consists of \f$(\vec{x_i}, y_i)\f$ pairs with associated errors \f$\sigma_{y_i}\f$ on \f$y_i\f$.
15  * - The model is a function of the form \f$y = f(\vec{x})\f$.
16  * - The figure of merit is then defined as:
17  * \f[
18  * \chi^2/ndf = \frac{1}{N}\sum_{i=0}^N \frac{(y_i - f(\vec{x_i}))^2}{\sigma_{y_i}^2}
19  * \f]
20  */
22 
23 public:
24 
25  /** Default Constructor */
27 
28  /** Destructor */
30 
31  /** Adds a data point */
32  void addData(const std::vector<double> &x, double y, double ey);
33 
34  /** Clear all data */
35  void clearData();
36 
37  /** Compute the score (\f$\chi^2/ndf\f$) for a given model relative to the data points. */
38  double evaluate(IModel *model) const;
39 
40  /** Compares two score values */
41  bool isBetterThan(double scoreToTest, double referenceScore) const;
42 
43 protected:
44 
45  std::vector<std::vector<double> > m_x; //!< Stores the \f$\vec{x_i}\f$ coordinates.
46  std::vector<double> m_y; //!< Stores the \f$y_i\f$ coordinates.
47  std::vector<double> m_ey; //!< Stores the \f$\sigma_{y_i}\f$ errors.
48 };
49 
50 #endif
std::vector< std::vector< double > > m_x
Stores the coordinates.
bool isBetterThan(double scoreToTest, double referenceScore) const
std::vector< double > m_ey
Stores the errors.
void addData(const std::vector< double > &x, double y, double ey)
Class implementing a figure of merit.
double evaluate(IModel *model) const
Abstract class representing a figure of merit.
std::vector< double > m_y
Stores the coordinates.
Abstract class describing the interface for a model.
Definition: IModel.h:13