[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.
|
---|
[af2c7ec] | 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 | *
|
---|
[68172a] | 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;
|
---|
[04cc7e] | 45 | //!> Typedef for a table with columns of all distances and the energy
|
---|
| 46 | typedef std::vector< std::vector<double> > DistanceEnergyTable_t;
|
---|
[68172a] | 47 |
|
---|
| 48 | public:
|
---|
| 49 | /** Constructor for class TrainingData.
|
---|
| 50 | *
|
---|
| 51 | */
|
---|
[af2c7ec] | 52 | explicit TrainingData(const FunctionModel::filter_t &_filter) :
|
---|
| 53 | filter(_filter)
|
---|
[68172a] | 54 | {}
|
---|
[af2c7ec] | 55 |
|
---|
[68172a] | 56 | /** Destructor for class TrainingData.
|
---|
| 57 | *
|
---|
| 58 | */
|
---|
| 59 | ~TrainingData()
|
---|
| 60 | {}
|
---|
| 61 |
|
---|
| 62 | /** We go through the given \a range of homologous fragments and call
|
---|
[af2c7ec] | 63 | * TrainingData::filter on them in order to gather the distance and
|
---|
[68172a] | 64 | * the energy value, stored internally.
|
---|
| 65 | *
|
---|
| 66 | * \param range given range within a HomologyContainer of homologous fragments
|
---|
| 67 | */
|
---|
| 68 | void operator()(const range_t &range);
|
---|
| 69 |
|
---|
| 70 | /** Getter for const access to internal training data inputs.
|
---|
| 71 | *
|
---|
| 72 | * \return const ref to training tuple of input vector
|
---|
| 73 | */
|
---|
| 74 | const InputVector_t& getTrainingInputs() const {
|
---|
[af2c7ec] | 75 | return ArgumentVector;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | /** Getter for const access to internal list of all pair-wise distances.
|
---|
| 79 | *
|
---|
| 80 | * \return const ref to all arguments
|
---|
| 81 | */
|
---|
| 82 | const InputVector_t& getAllArguments() const {
|
---|
[68172a] | 83 | return DistanceVector;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | /** Getter for const access to internal training data outputs.
|
---|
| 87 | *
|
---|
| 88 | * \return const ref to training tuple of output vector
|
---|
| 89 | */
|
---|
| 90 | const OutputVector_t& getTrainingOutputs() const {
|
---|
| 91 | return EnergyVector;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[dd8094] | 94 | /** Returns the average of each component over all OutputVectors.
|
---|
| 95 | *
|
---|
| 96 | * This is useful for initializing the offset of the potential.
|
---|
| 97 | *
|
---|
| 98 | * @return average output vector
|
---|
| 99 | */
|
---|
| 100 | const FunctionModel::results_t getTrainingOutputAverage() const;
|
---|
| 101 |
|
---|
[68172a] | 102 | /** Calculate the L2 error of a given \a model against the stored training data.
|
---|
| 103 | *
|
---|
| 104 | * \param model model whose L2 error to calculate
|
---|
| 105 | * \return sum of squared differences at training tuples
|
---|
| 106 | */
|
---|
| 107 | const double getL2Error(const FunctionModel &model) const;
|
---|
| 108 |
|
---|
| 109 | /** Calculate the Lmax error of a given \a model against the stored training data.
|
---|
| 110 | *
|
---|
| 111 | * \param model model whose Lmax error to calculate
|
---|
| 112 | * \return maximum difference over all training tuples
|
---|
| 113 | */
|
---|
| 114 | const double getLMaxError(const FunctionModel &model) const;
|
---|
| 115 |
|
---|
[04cc7e] | 116 | /** Creates a table of columns with all distances and the energy.
|
---|
| 117 | *
|
---|
| 118 | * \return array with first columns containing distances, last column energy
|
---|
| 119 | */
|
---|
| 120 | const DistanceEnergyTable_t getDistanceEnergyTable() const;
|
---|
| 121 |
|
---|
[68172a] | 122 | private:
|
---|
| 123 | // prohibit use of default constructor, as we always require extraction functor.
|
---|
| 124 | TrainingData();
|
---|
| 125 |
|
---|
| 126 | private:
|
---|
| 127 | //!> private training data vector
|
---|
| 128 | InputVector_t DistanceVector;
|
---|
| 129 | OutputVector_t EnergyVector;
|
---|
[af2c7ec] | 130 | //!> list of all filtered arguments over all tuples
|
---|
| 131 | InputVector_t ArgumentVector;
|
---|
[68172a] | 132 | //!> function to be used for training input data extraction from a fragment
|
---|
[af2c7ec] | 133 | const FunctionModel::filter_t filter;
|
---|
[68172a] | 134 | };
|
---|
| 135 |
|
---|
| 136 | // print training data for debugging
|
---|
| 137 | std::ostream &operator<<(std::ostream &out, const TrainingData &data);
|
---|
| 138 |
|
---|
| 139 | #endif /* TRAININGDATA_HPP_ */
|
---|