Index: src/FunctionApproximation/Makefile.am
===================================================================
--- src/FunctionApproximation/Makefile.am	(revision 8aa597d50a9e1a99021b44a4fc01ec923c06490d)
+++ src/FunctionApproximation/Makefile.am	(revision 68172a73ac43709c67c953143f10961113ce423e)
@@ -4,10 +4,12 @@
 FUNCTIONAPPROXIMATIONSOURCE = \
 	FunctionApproximation/Extractors.cpp \
-	FunctionApproximation/FunctionArgument.cpp
+	FunctionApproximation/FunctionArgument.cpp \
+	FunctionApproximation/TrainingData.cpp
 	
 FUNCTIONAPPROXIMATIONHEADER = \
 	FunctionApproximation/Extractors.hpp \
 	FunctionApproximation/FunctionArgument.hpp \
-	FunctionApproximation/FunctionModel.hpp
+	FunctionApproximation/FunctionModel.hpp \
+	FunctionApproximation/TrainingData.hpp
 	
 if CONDLEVMAR
Index: src/FunctionApproximation/TrainingData.cpp
===================================================================
--- src/FunctionApproximation/TrainingData.cpp	(revision 68172a73ac43709c67c953143f10961113ce423e)
+++ src/FunctionApproximation/TrainingData.cpp	(revision 68172a73ac43709c67c953143f10961113ce423e)
@@ -0,0 +1,112 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C)  2012 University of Bonn. All rights reserved.
+ * Please see the COPYING file or "Copyright notice" in builder.cpp for details.
+ *
+ *
+ *   This file is part of MoleCuilder.
+ *
+ *    MoleCuilder is free software: you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation, either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    MoleCuilder is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * TrainingData.cpp
+ *
+ *  Created on: 15.10.2012
+ *      Author: heber
+ */
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "CodePatterns/MemDebug.hpp"
+
+#include "TrainingData.hpp"
+
+#include <iostream>
+
+#include "CodePatterns/toString.hpp"
+
+#include "Fragmentation/SetValues/Fragment.hpp"
+#include "FunctionApproximation/FunctionModel.hpp"
+
+void TrainingData::operator()(const range_t &range) {
+  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) );
+  }
+}
+
+const double TrainingData::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;
+}
+
+const double TrainingData::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;
+}
+
+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: " << std::endl;
+  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 ";
+    out << (*outiter);
+    out << std::endl;
+  }
+  return out;
+}
Index: src/FunctionApproximation/TrainingData.hpp
===================================================================
--- src/FunctionApproximation/TrainingData.hpp	(revision 68172a73ac43709c67c953143f10961113ce423e)
+++ src/FunctionApproximation/TrainingData.hpp	(revision 68172a73ac43709c67c953143f10961113ce423e)
@@ -0,0 +1,110 @@
+/*
+ * TrainingData.hpp
+ *
+ *  Created on: 15.10.2012
+ *      Author: heber
+ */
+
+#ifndef TRAININGDATA_HPP_
+#define TRAININGDATA_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <iosfwd>
+#include <boost/function.hpp>
+
+#include "Fragmentation/Homology/HomologyContainer.hpp"
+#include "FunctionApproximation/FunctionApproximation.hpp"
+
+class Fragment;
+
+/** 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);
+
+  /** 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;
+
+  /** 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;
+
+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);
+
+#endif /* TRAININGDATA_HPP_ */
