Index: src/LevMartester.cpp
===================================================================
--- src/LevMartester.cpp	(revision f68c6845e5ea959313c49fc72cc3c3ee7de031e2)
+++ src/LevMartester.cpp	(revision 68172a73ac43709c67c953143f10961113ce423e)
@@ -65,4 +65,5 @@
 #include "FunctionApproximation/FunctionApproximation.hpp"
 #include "FunctionApproximation/FunctionModel.hpp"
+#include "FunctionApproximation/TrainingData.hpp"
 #include "Helpers/defs.hpp"
 #include "Potentials/Specifics/PairPotential_Morse.hpp"
@@ -197,157 +198,4 @@
   else
     return angle/divisor;
-}
-
-/** This class encapsulates the training data for a given potential function
- * to learn.
- *
- * The data is added piece-wise by calling the operator() with a specific
- * Fragment.
- */
-class TrainingData
-{
-public:
-  //!> typedef for a range within the HomologyContainer at which fragments to look at
-  typedef std::pair<
-      HomologyContainer::const_iterator,
-      HomologyContainer::const_iterator> range_t;
-  //!> Training tuple input vector pair
-  typedef FunctionApproximation::inputs_t InputVector_t;
-  //!> Training tuple output vector pair
-  typedef FunctionApproximation::outputs_t OutputVector_t;
-  //!> Typedef for a function containing how to extract required information from a Fragment.
-  typedef boost::function< FunctionModel::arguments_t (const Fragment &, const size_t)> extractor_t;
-
-public:
-  /** Constructor for class TrainingData.
-   *
-   */
-  explicit TrainingData(const extractor_t &_extractor) :
-      extractor(extractor)
-  {}
-  /** Destructor for class TrainingData.
-   *
-   */
-  ~TrainingData()
-  {}
-
-  /** We go through the given \a range of homologous fragments and call
-   * TrainingData::extractor on them in order to gather the distance and
-   * the energy value, stored internally.
-   *
-   * \param range given range within a HomologyContainer of homologous fragments
-   */
-  void operator()(const range_t &range) {
-    double EnergySum = 0.; //std::numeric_limits<double>::max();
-    size_t counter = 0.;
-    for (HomologyContainer::const_iterator iter = range.first; iter != range.second; ++iter) {
-      const double &energy = iter->second.second;
-//      if (energy <= EnergySum)
-//        EnergySum = energy;
-      EnergySum += energy;
-      ++counter;
-    }
-    EnergySum *= 1./(double)counter;
-    for (HomologyContainer::const_iterator iter = range.first; iter != range.second; ++iter) {
-      // get distance out of Fragment
-      const Fragment &fragment = iter->second.first;
-      FunctionModel::arguments_t args = extractor(
-            fragment,
-            DistanceVector.size()
-          );
-      DistanceVector.push_back( args );
-      const double &energy = iter->second.second;
-      EnergyVector.push_back( FunctionModel::results_t(1, energy-EnergySum) );
-    }
-  }
-
-  /** Getter for const access to internal training data inputs.
-   *
-   * \return const ref to training tuple of input vector
-   */
-  const InputVector_t& getTrainingInputs() const {
-    return DistanceVector;
-  }
-
-  /** Getter for const access to internal training data outputs.
-   *
-   * \return const ref to training tuple of output vector
-   */
-  const OutputVector_t& getTrainingOutputs() const {
-    return EnergyVector;
-  }
-
-  /** Calculate the L2 error of a given \a model against the stored training data.
-   *
-   * \param model model whose L2 error to calculate
-   * \return sum of squared differences at training tuples
-   */
-  const double getL2Error(const FunctionModel &model) const
-  {
-    double L2sum = 0.;
-
-    FunctionApproximation::inputs_t::const_iterator initer = DistanceVector.begin();
-    FunctionApproximation::outputs_t::const_iterator outiter = EnergyVector.begin();
-    for (; initer != DistanceVector.end(); ++initer, ++outiter) {
-      const FunctionModel::results_t result = model((*initer));
-      const double temp = fabs((*outiter)[0] - result[0]);
-      L2sum += temp*temp;
-    }
-    return L2sum;
-  }
-
-  /** Calculate the Lmax error of a given \a model against the stored training data.
-   *
-   * \param model model whose Lmax error to calculate
-   * \return maximum difference over all training tuples
-   */
-  const double getLMaxError(const FunctionModel &model) const
-  {
-    double Lmax = 0.;
-    size_t maxindex = -1;
-    FunctionApproximation::inputs_t::const_iterator initer = DistanceVector.begin();
-    FunctionApproximation::outputs_t::const_iterator outiter = EnergyVector.begin();
-    for (; initer != DistanceVector.end(); ++initer, ++outiter) {
-      const FunctionModel::results_t result = model((*initer));
-      const double temp = fabs((*outiter)[0] - result[0]);
-      if (temp > Lmax) {
-        Lmax = temp;
-        maxindex = std::distance(
-            const_cast<const FunctionApproximation::inputs_t &>(DistanceVector).begin(),
-            initer
-            );
-      }
-    }
-    return Lmax;
-  }
-
-private:
-  // prohibit use of default constructor, as we always require extraction functor.
-  TrainingData();
-
-private:
-  //!> private training data vector
-  InputVector_t DistanceVector;
-  OutputVector_t EnergyVector;
-  //!> function to be used for training input data extraction from a fragment
-  const extractor_t extractor;
-};
-
-// print training data for debugging
-std::ostream &operator<<(std::ostream &out, const TrainingData &data)
-{
-  const TrainingData::InputVector_t &DistanceVector = data.getTrainingInputs();
-  const TrainingData::OutputVector_t &EnergyVector = data.getTrainingOutputs();
-  out << "(" << DistanceVector.size()
-      << "," << EnergyVector.size() << ") data pairs: ";
-  FunctionApproximation::inputs_t::const_iterator initer = DistanceVector.begin();
-  FunctionApproximation::outputs_t::const_iterator outiter = EnergyVector.begin();
-  for (; initer != DistanceVector.end(); ++initer, ++outiter) {
-    for (size_t index = 0; index < (*initer).size(); ++index)
-       out << "(" << (*initer)[index].indices.first << "," << (*initer)[index].indices.second
-          << ") " << (*initer)[index].distance;
-    out << " with energy " << *outiter;
-  }
-  return out;
 }
 
