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