Index: branches/GBT-trunkintegration/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/LossFunctions/AbsoluteErrorLoss.cs
===================================================================
--- branches/GBT-trunkintegration/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/LossFunctions/AbsoluteErrorLoss.cs	(revision 12589)
+++ branches/GBT-trunkintegration/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/LossFunctions/AbsoluteErrorLoss.cs	(revision 12590)
@@ -1,12 +1,32 @@
-﻿using System;
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ * and the BEACON Center for the Study of Evolution in Action.
+ * 
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab 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 HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using HeuristicLab.Common;
-using HeuristicLab.Core;
 
-namespace GradientBoostedTrees {
+namespace HeuristicLab.Algorithms.DataAnalysis {
+  // loss function for the weighted absolute error
   public class AbsoluteErrorLoss : ILossFunction {
     public double GetLoss(IEnumerable<double> target, IEnumerable<double> pred, IEnumerable<double> weight) {
@@ -54,41 +74,14 @@
       // line search for abs error
       LineSearchFunc lineSearch = (idx, startIdx, endIdx) => {
+        // Median() is allocating an array anyway
+        // It would be possible to pre-allocated an array for the residuals if Median() would allow specification of a sub-range
         int nRows = endIdx - startIdx + 1;
-        var res = from offset in Enumerable.Range(0, nRows)
-                  let i = startIdx + offset
-                  let row = idx[i]
-                  select (targetArr[row] - predArr[row]);
+        var res = new double[nRows];
+        for (int offset = 0; offset < nRows; offset++) {
+          var i = startIdx + offset;
+          var row = idx[i];
+          res[offset] = targetArr[row] - predArr[row];
+        }
         return res.Median();
-
-        // old code for weighted median calculation
-        // int nRows = endIdx - startIdx + 1; // startIdx and endIdx are inclusive
-        // if (nRows == 1) return targetArr[idx[startIdx]] - predArr[idx[startIdx]];
-        // else if (nRows == 2) {
-        //   if (weightArr[idx[startIdx]] > weightArr[idx[endIdx]]) {
-        //     return targetArr[idx[startIdx]] - predArr[idx[startIdx]];
-        //   } else if (weightArr[idx[startIdx]] < weightArr[idx[endIdx]]) {
-        //     return targetArr[idx[endIdx]] - predArr[idx[endIdx]];
-        //   } else {
-        //     // same weight
-        //     return ((targetArr[idx[startIdx]] - predArr[idx[startIdx]]) +
-        //        (targetArr[idx[endIdx]] - predArr[idx[endIdx]])) / 2;
-        //   }
-        // } else {
-        //   var ts = from offset in Enumerable.Range(0, nRows)
-        //            let i = startIdx + offset
-        //            select new { res = targetArr[idx[i]] - predArr[idx[i]], weight = weightArr[idx[i]] };
-        //   ts = ts.OrderBy(t => t.res);
-        //   var totalWeight = ts.Sum(t => t.weight);
-        //   var tsEnumerator = ts.GetEnumerator();
-        //   tsEnumerator.MoveNext();
-        // 
-        //   double aggWeight = tsEnumerator.Current.weight; // weight of first
-        // 
-        //   while (aggWeight < totalWeight / 2) {
-        //     tsEnumerator.MoveNext();
-        //     aggWeight += tsEnumerator.Current.weight;
-        //   }
-        //   return tsEnumerator.Current.res;
-        // }
       };
       return lineSearch;
Index: branches/GBT-trunkintegration/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/LossFunctions/ILossFunction.cs
===================================================================
--- branches/GBT-trunkintegration/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/LossFunctions/ILossFunction.cs	(revision 12589)
+++ branches/GBT-trunkintegration/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/LossFunctions/ILossFunction.cs	(revision 12590)
@@ -1,15 +1,37 @@
-﻿using System;
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ * and the BEACON Center for the Study of Evolution in Action.
+ * 
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab 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 HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
 using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using HeuristicLab.Core;
 
-namespace GradientBoostedTrees {
+namespace HeuristicLab.Algorithms.DataAnalysis {
   public delegate double LineSearchFunc(int[] idx, int startIdx, int endIdx);
 
   public interface ILossFunction {
+    // returns the weighted loss
     double GetLoss(IEnumerable<double> target, IEnumerable<double> pred, IEnumerable<double> weight);
+
+    // returns an enumerable of the weighted loss gradient for each row
     IEnumerable<double> GetLossGradient(IEnumerable<double> target, IEnumerable<double> pred, IEnumerable<double> weight);
+
+    // returns a function that returns the optimal prediction value for a subset of rows from target and pred (see LineSearchFunc delegate above)
     LineSearchFunc GetLineSearchFunc(IEnumerable<double> target, IEnumerable<double> pred, IEnumerable<double> weight);
   }
Index: branches/GBT-trunkintegration/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/LossFunctions/LogisticRegressionLoss.cs
===================================================================
--- branches/GBT-trunkintegration/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/LossFunctions/LogisticRegressionLoss.cs	(revision 12589)
+++ branches/GBT-trunkintegration/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/LossFunctions/LogisticRegressionLoss.cs	(revision 12590)
@@ -1,12 +1,31 @@
-﻿using System;
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ * and the BEACON Center for the Study of Evolution in Action.
+ * 
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab 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 HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using HeuristicLab.Common;
-using HeuristicLab.Core;
 
-namespace GradientBoostedTrees {
+namespace HeuristicLab.Algorithms.DataAnalysis {
   public class LogisticRegressionLoss : ILossFunction {
     public double GetLoss(IEnumerable<double> target, IEnumerable<double> pred, IEnumerable<double> weight) {
Index: branches/GBT-trunkintegration/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/LossFunctions/RelativeErrorLoss.cs
===================================================================
--- branches/GBT-trunkintegration/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/LossFunctions/RelativeErrorLoss.cs	(revision 12589)
+++ branches/GBT-trunkintegration/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/LossFunctions/RelativeErrorLoss.cs	(revision 12590)
@@ -1,12 +1,32 @@
-﻿using System;
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ * and the BEACON Center for the Study of Evolution in Action.
+ * 
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab 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 HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using HeuristicLab.Common;
-using HeuristicLab.Core;
 
-namespace GradientBoostedTrees {
+namespace HeuristicLab.Algorithms.DataAnalysis {
+  // relative error loss is a special case of weighted absolute error loss
   public class RelativeErrorLoss : ILossFunction {
     public double GetLoss(IEnumerable<double> target, IEnumerable<double> pred, IEnumerable<double> weight) {
@@ -50,5 +70,6 @@
         throw new ArgumentException("target, pred and weight have differing lengths");
 
-      // line search for abs error
+      // line search for relative error
+      // TODO: check and improve?
       LineSearchFunc lineSearch = (idx, startIdx, endIdx) => {
         // weighted median calculation
Index: branches/GBT-trunkintegration/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/LossFunctions/SquaredErrorLoss.cs
===================================================================
--- branches/GBT-trunkintegration/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/LossFunctions/SquaredErrorLoss.cs	(revision 12589)
+++ branches/GBT-trunkintegration/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/LossFunctions/SquaredErrorLoss.cs	(revision 12590)
@@ -1,11 +1,29 @@
-﻿using System;
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ * and the BEACON Center for the Study of Evolution in Action.
+ * 
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab 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 HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
 using System.Collections.Generic;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using HeuristicLab.Common;
-using HeuristicLab.Core;
 
-namespace GradientBoostedTrees {
+namespace HeuristicLab.Algorithms.DataAnalysis {
   public class SquaredErrorLoss : ILossFunction {
     public double GetLoss(IEnumerable<double> target, IEnumerable<double> pred, IEnumerable<double> weight) {
@@ -44,5 +62,5 @@
         throw new ArgumentException("target, pred and weight have differing lengths");
 
-      // line search for 
+      // line search for squared error loss => return the average value
       LineSearchFunc lineSearch = (idx, startIdx, endIdx) => {
         double s = 0.0;
