| [68172a] | 1 | /*
 | 
|---|
 | 2 |  * TrainingData.hpp
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  *  Created on: 15.10.2012
 | 
|---|
 | 5 |  *      Author: heber
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | #ifndef TRAININGDATA_HPP_
 | 
|---|
 | 9 | #define TRAININGDATA_HPP_
 | 
|---|
 | 10 | 
 | 
|---|
 | 11 | // include config.h
 | 
|---|
 | 12 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 13 | #include <config.h>
 | 
|---|
 | 14 | #endif
 | 
|---|
 | 15 | 
 | 
|---|
 | 16 | #include <iosfwd>
 | 
|---|
 | 17 | #include <boost/function.hpp>
 | 
|---|
 | 18 | 
 | 
|---|
 | 19 | #include "Fragmentation/Homology/HomologyContainer.hpp"
 | 
|---|
 | 20 | #include "FunctionApproximation/FunctionApproximation.hpp"
 | 
|---|
| [7b019a] | 21 | #include "FunctionApproximation/FunctionModel.hpp"
 | 
|---|
| [68172a] | 22 | 
 | 
|---|
 | 23 | /** This class encapsulates the training data for a given potential function
 | 
|---|
 | 24 |  * to learn.
 | 
|---|
 | 25 |  *
 | 
|---|
 | 26 |  * The data is added piece-wise by calling the operator() with a specific
 | 
|---|
 | 27 |  * Fragment.
 | 
|---|
 | 28 |  */
 | 
|---|
 | 29 | class TrainingData
 | 
|---|
 | 30 | {
 | 
|---|
 | 31 | public:
 | 
|---|
 | 32 |   //!> typedef for a range within the HomologyContainer at which fragments to look at
 | 
|---|
 | 33 |   typedef std::pair<
 | 
|---|
 | 34 |       HomologyContainer::const_iterator,
 | 
|---|
 | 35 |       HomologyContainer::const_iterator> range_t;
 | 
|---|
 | 36 |   //!> Training tuple input vector pair
 | 
|---|
 | 37 |   typedef FunctionApproximation::inputs_t InputVector_t;
 | 
|---|
 | 38 |   //!> Training tuple output vector pair
 | 
|---|
 | 39 |   typedef FunctionApproximation::outputs_t OutputVector_t;
 | 
|---|
| [04cc7e] | 40 |   //!> Typedef for a table with columns of all distances and the energy
 | 
|---|
 | 41 |   typedef std::vector< std::vector<double> > DistanceEnergyTable_t;
 | 
|---|
| [68172a] | 42 | 
 | 
|---|
 | 43 | public:
 | 
|---|
 | 44 |   /** Constructor for class TrainingData.
 | 
|---|
 | 45 |    *
 | 
|---|
 | 46 |    */
 | 
|---|
| [7b019a] | 47 |   explicit TrainingData(const FunctionModel::extractor_t &_extractor) :
 | 
|---|
| [68172a] | 48 |       extractor(_extractor)
 | 
|---|
 | 49 |   {}
 | 
|---|
 | 50 |   /** Destructor for class TrainingData.
 | 
|---|
 | 51 |    *
 | 
|---|
 | 52 |    */
 | 
|---|
 | 53 |   ~TrainingData()
 | 
|---|
 | 54 |   {}
 | 
|---|
 | 55 | 
 | 
|---|
 | 56 |   /** We go through the given \a range of homologous fragments and call
 | 
|---|
 | 57 |    * TrainingData::extractor on them in order to gather the distance and
 | 
|---|
 | 58 |    * the energy value, stored internally.
 | 
|---|
 | 59 |    *
 | 
|---|
 | 60 |    * \param range given range within a HomologyContainer of homologous fragments
 | 
|---|
 | 61 |    */
 | 
|---|
 | 62 |   void operator()(const range_t &range);
 | 
|---|
 | 63 | 
 | 
|---|
 | 64 |   /** Getter for const access to internal training data inputs.
 | 
|---|
 | 65 |    *
 | 
|---|
 | 66 |    * \return const ref to training tuple of input vector
 | 
|---|
 | 67 |    */
 | 
|---|
 | 68 |   const InputVector_t& getTrainingInputs() const {
 | 
|---|
 | 69 |     return DistanceVector;
 | 
|---|
 | 70 |   }
 | 
|---|
 | 71 | 
 | 
|---|
 | 72 |   /** Getter for const access to internal training data outputs.
 | 
|---|
 | 73 |    *
 | 
|---|
 | 74 |    * \return const ref to training tuple of output vector
 | 
|---|
 | 75 |    */
 | 
|---|
 | 76 |   const OutputVector_t& getTrainingOutputs() const {
 | 
|---|
 | 77 |     return EnergyVector;
 | 
|---|
 | 78 |   }
 | 
|---|
 | 79 | 
 | 
|---|
| [dd8094] | 80 |   /** Returns the average of each component over all OutputVectors.
 | 
|---|
 | 81 |    *
 | 
|---|
 | 82 |    * This is useful for initializing the offset of the potential.
 | 
|---|
 | 83 |    *
 | 
|---|
 | 84 |    * @return average output vector
 | 
|---|
 | 85 |    */
 | 
|---|
 | 86 |   const FunctionModel::results_t getTrainingOutputAverage() const;
 | 
|---|
 | 87 | 
 | 
|---|
| [68172a] | 88 |   /** Calculate the L2 error of a given \a model against the stored training data.
 | 
|---|
 | 89 |    *
 | 
|---|
 | 90 |    * \param model model whose L2 error to calculate
 | 
|---|
 | 91 |    * \return sum of squared differences at training tuples
 | 
|---|
 | 92 |    */
 | 
|---|
 | 93 |   const double getL2Error(const FunctionModel &model) const;
 | 
|---|
 | 94 | 
 | 
|---|
 | 95 |   /** Calculate the Lmax error of a given \a model against the stored training data.
 | 
|---|
 | 96 |    *
 | 
|---|
 | 97 |    * \param model model whose Lmax error to calculate
 | 
|---|
 | 98 |    * \return maximum difference over all training tuples
 | 
|---|
 | 99 |    */
 | 
|---|
 | 100 |   const double getLMaxError(const FunctionModel &model) const;
 | 
|---|
 | 101 | 
 | 
|---|
| [04cc7e] | 102 |   /** Creates a table of columns with all distances and the energy.
 | 
|---|
 | 103 |    *
 | 
|---|
 | 104 |    * \return array with first columns containing distances, last column energy
 | 
|---|
 | 105 |    */
 | 
|---|
 | 106 |   const DistanceEnergyTable_t getDistanceEnergyTable() const;
 | 
|---|
 | 107 | 
 | 
|---|
| [68172a] | 108 | private:
 | 
|---|
 | 109 |   // prohibit use of default constructor, as we always require extraction functor.
 | 
|---|
 | 110 |   TrainingData();
 | 
|---|
 | 111 | 
 | 
|---|
 | 112 | private:
 | 
|---|
 | 113 |   //!> private training data vector
 | 
|---|
 | 114 |   InputVector_t DistanceVector;
 | 
|---|
 | 115 |   OutputVector_t EnergyVector;
 | 
|---|
 | 116 |   //!> function to be used for training input data extraction from a fragment
 | 
|---|
| [7b019a] | 117 |   const FunctionModel::extractor_t extractor;
 | 
|---|
| [68172a] | 118 | };
 | 
|---|
 | 119 | 
 | 
|---|
 | 120 | // print training data for debugging
 | 
|---|
 | 121 | std::ostream &operator<<(std::ostream &out, const TrainingData &data);
 | 
|---|
 | 122 | 
 | 
|---|
 | 123 | #endif /* TRAININGDATA_HPP_ */
 | 
|---|