| 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 | #include "FunctionApproximation/FunctionModel.hpp"
|
|---|
| 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 | * In TrainingData::operator() we construct first all pair-wise distances as
|
|---|
| 30 | * list of all arguments. Then, these are filtered depending on the specific
|
|---|
| 31 | * FunctionModel's Filter and only these are handed to down to evaluate it.
|
|---|
| 32 | *
|
|---|
| 33 | */
|
|---|
| 34 | class TrainingData
|
|---|
| 35 | {
|
|---|
| 36 | public:
|
|---|
| 37 | //!> typedef for a range within the HomologyContainer at which fragments to look at
|
|---|
| 38 | typedef std::pair<
|
|---|
| 39 | HomologyContainer::const_iterator,
|
|---|
| 40 | HomologyContainer::const_iterator> range_t;
|
|---|
| 41 | //!> Training tuple input vector pair
|
|---|
| 42 | typedef FunctionApproximation::inputs_t InputVector_t;
|
|---|
| 43 | //!> Training tuple output vector pair
|
|---|
| 44 | typedef FunctionApproximation::outputs_t OutputVector_t;
|
|---|
| 45 | //!> Typedef for a table with columns of all distances and the energy
|
|---|
| 46 | typedef std::vector< std::vector<double> > DistanceEnergyTable_t;
|
|---|
| 47 | //!> Typedef for a map of each fragment with error.
|
|---|
| 48 | typedef std::multimap< double, size_t > L2ErrorConfigurationIndexMap_t;
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 | public:
|
|---|
| 52 | /** Constructor for class TrainingData.
|
|---|
| 53 | *
|
|---|
| 54 | */
|
|---|
| 55 | explicit TrainingData(const FunctionModel::filter_t &_filter) :
|
|---|
| 56 | filter(_filter)
|
|---|
| 57 | {}
|
|---|
| 58 |
|
|---|
| 59 | /** Destructor for class TrainingData.
|
|---|
| 60 | *
|
|---|
| 61 | */
|
|---|
| 62 | ~TrainingData()
|
|---|
| 63 | {}
|
|---|
| 64 |
|
|---|
| 65 | /** We go through the given \a range of homologous fragments and call
|
|---|
| 66 | * TrainingData::filter on them in order to gather the distance and
|
|---|
| 67 | * the energy value, stored internally.
|
|---|
| 68 | *
|
|---|
| 69 | * \param range given range within a HomologyContainer of homologous fragments
|
|---|
| 70 | */
|
|---|
| 71 | void operator()(const range_t &range);
|
|---|
| 72 |
|
|---|
| 73 | /** Getter for const access to internal training data inputs.
|
|---|
| 74 | *
|
|---|
| 75 | * \return const ref to training tuple of input vector
|
|---|
| 76 | */
|
|---|
| 77 | const InputVector_t& getTrainingInputs() const {
|
|---|
| 78 | return ArgumentVector;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | /** Getter for const access to internal list of all pair-wise distances.
|
|---|
| 82 | *
|
|---|
| 83 | * \return const ref to all arguments
|
|---|
| 84 | */
|
|---|
| 85 | const InputVector_t& getAllArguments() const {
|
|---|
| 86 | return DistanceVector;
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | /** Getter for const access to internal training data outputs.
|
|---|
| 90 | *
|
|---|
| 91 | * \return const ref to training tuple of output vector
|
|---|
| 92 | */
|
|---|
| 93 | const OutputVector_t& getTrainingOutputs() const {
|
|---|
| 94 | return EnergyVector;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | /** Returns the average of each component over all OutputVectors.
|
|---|
| 98 | *
|
|---|
| 99 | * This is useful for initializing the offset of the potential.
|
|---|
| 100 | *
|
|---|
| 101 | * @return average output vector
|
|---|
| 102 | */
|
|---|
| 103 | const FunctionModel::results_t getTrainingOutputAverage() const;
|
|---|
| 104 |
|
|---|
| 105 | /** Calculate the L2 error of a given \a model against the stored training data.
|
|---|
| 106 | *
|
|---|
| 107 | * \param model model whose L2 error to calculate
|
|---|
| 108 | * \return sum of squared differences at training tuples
|
|---|
| 109 | */
|
|---|
| 110 | const double getL2Error(const FunctionModel &model) const;
|
|---|
| 111 |
|
|---|
| 112 | /** Calculate the Lmax error of a given \a model against the stored training data.
|
|---|
| 113 | *
|
|---|
| 114 | * \param model model whose Lmax error to calculate
|
|---|
| 115 | * \return maximum difference over all training tuples
|
|---|
| 116 | */
|
|---|
| 117 | const double getLMaxError(const FunctionModel &model) const;
|
|---|
| 118 |
|
|---|
| 119 | /** Calculate the Lmax error of a given \a model against the stored training data.
|
|---|
| 120 | *
|
|---|
| 121 | * \param model model whose Lmax error to calculate
|
|---|
| 122 | * \param range given range within a HomologyContainer of homologous fragments
|
|---|
| 123 | * \return map with L2 error per configuration
|
|---|
| 124 | */
|
|---|
| 125 | const L2ErrorConfigurationIndexMap_t getWorstFragmentMap(
|
|---|
| 126 | const FunctionModel &model,
|
|---|
| 127 | const range_t &range) const;
|
|---|
| 128 |
|
|---|
| 129 | /** Creates a table of columns with all distances and the energy.
|
|---|
| 130 | *
|
|---|
| 131 | * \return array with first columns containing distances, last column energy
|
|---|
| 132 | */
|
|---|
| 133 | const DistanceEnergyTable_t getDistanceEnergyTable() const;
|
|---|
| 134 |
|
|---|
| 135 | private:
|
|---|
| 136 | // prohibit use of default constructor, as we always require extraction functor.
|
|---|
| 137 | TrainingData();
|
|---|
| 138 |
|
|---|
| 139 | private:
|
|---|
| 140 | //!> private training data vector
|
|---|
| 141 | InputVector_t DistanceVector;
|
|---|
| 142 | OutputVector_t EnergyVector;
|
|---|
| 143 | //!> list of all filtered arguments over all tuples
|
|---|
| 144 | InputVector_t ArgumentVector;
|
|---|
| 145 | //!> function to be used for training input data extraction from a fragment
|
|---|
| 146 | const FunctionModel::filter_t filter;
|
|---|
| 147 | };
|
|---|
| 148 |
|
|---|
| 149 | // print training data for debugging
|
|---|
| 150 | std::ostream &operator<<(std::ostream &out, const TrainingData &data);
|
|---|
| 151 |
|
|---|
| 152 | #endif /* TRAININGDATA_HPP_ */
|
|---|