Index: branches/MathNetNumerics-Exploration-2789/HeuristicLab.Algorithms.DataAnalysis.Experimental/Splines.cs
===================================================================
--- branches/MathNetNumerics-Exploration-2789/HeuristicLab.Algorithms.DataAnalysis.Experimental/Splines.cs	(revision 15465)
+++ branches/MathNetNumerics-Exploration-2789/HeuristicLab.Algorithms.DataAnalysis.Experimental/Splines.cs	(revision 15468)
@@ -148,11 +148,4 @@
       var validTypes = new ItemSet<StringValue>(
         new[] {
-        "Monotone", "Akima", "Catmull-Rom", "Cubic", "Linear",
-          "Cubic - Natural (Math.NET)",
-          "Polynomial (Math.NET)",
-          "Rational (Math.NET)",
-          "LogLinear (Math.NET)",
-          "Common (Math.NET)",
-          "Smoothing Spline (Mine)",
           "Smoothing Spline (Reinsch)",
           "Smoothing Spline (Reinsch with automatic tolerance determination using LOOCV)",
@@ -185,52 +178,4 @@
         var type = ((StringValue)Parameters["Type"].ActualValue).Value;
         switch (type) {
-          case "Monotone":
-            alglib.spline1dbuildmonotone(x, y, out c);
-            AddAlglibSplineResult(c, inputVars);
-            break;
-          case "Akima":
-            alglib.spline1dbuildakima(x, y, out c); AddAlglibSplineResult(c, inputVars);
-            break;
-            ;
-          case "Catmull-Rom":
-            alglib.spline1dbuildcatmullrom(x, y, out c); AddAlglibSplineResult(c, inputVars);
-            break;
-
-          case "Cubic":
-            alglib.spline1dbuildcubic(x, y, out c); AddAlglibSplineResult(c, inputVars);
-            break;
-
-          case "Linear":
-            alglib.spline1dbuildlinear(x, y, out c); AddAlglibSplineResult(c, inputVars);
-            break;
-          case "Cubic - Natural (Math.NET)": {
-              var spline = MathNet.Numerics.Interpolation.CubicSpline.InterpolateNatural(x, y);
-              AddMathNetSplineResult(spline, inputVars);
-              break;
-            }
-          case "Common (Math.NET)": {
-              var spline = MathNet.Numerics.Interpolate.Common(x, y);
-              AddMathNetSplineResult(spline, inputVars);
-              break;
-            }
-          case "LogLinear (Math.NET)": {
-              var spline = MathNet.Numerics.Interpolate.LogLinear(x, y);
-              AddMathNetSplineResult(spline, inputVars);
-              break;
-            }
-          case "Polynomial (Math.NET)": {
-              var spline = MathNet.Numerics.Interpolate.Polynomial(x, y);
-              AddMathNetSplineResult(spline, inputVars);
-              break;
-            }
-          case "Rational (Math.NET)": {
-              var spline = MathNet.Numerics.Interpolate.RationalWithoutPoles(x, y);
-              AddMathNetSplineResult(spline, inputVars);
-              break;
-            }
-          case "Smoothing Spline (Mine)": {
-              CalculateSmoothingSpline(x, y, inputVars);
-              break;
-            }
           case "Smoothing Spline (Reinsch)": {
               CalculateSmoothingSplineReinsch(x, y, inputVars);
@@ -264,8 +209,8 @@
           case "Finnbar O'Sullivan (sbart)": {
               SBART.SBART_Report report;
-              var lambda = ((IValueParameter<DoubleValue>)Parameters["Lambda"]).Value.Value; // controls extent of smoothing
+           
               var model =
                 SBART.CalculateSBART(x, y,
-                Problem.ProblemData.TargetVariable, inputVars, (float)lambda, out report);
+                Problem.ProblemData.TargetVariable, inputVars, out report);
               var targetVar = Problem.ProblemData.TargetVariable;
               var problemData = (IRegressionProblemData)Problem.ProblemData.Clone();
@@ -275,8 +220,4 @@
               break;
 
-            }
-          case "B-Spline Smoothing": {
-              BSplineSmoothing(x, y, inputVars);
-              break;
             }
           case "Penalized Regression Spline (alglib)": {
@@ -371,9 +312,4 @@
 
       return new RegressionEnsembleModel(models);
-    }
-
-    public void BSplineSmoothing(double[] x, double[] y, string[] inputVars) {
-      Array.Sort(x, y);
-      CubicSpline2(x, y, inputVars);
     }
 
@@ -414,64 +350,4 @@
     }
 
-    public void CubicSpline2(double[] x, double[] y, string[] inputVars) {
-      // see Pollock: Smoothing Splines
-      int n = x.Length;
-      double lambda = 1.0;
-      double[] sigma = Enumerable.Repeat(1.0, n).ToArray();
-      SplineData[] S = new SplineData[x.Length + 1];
-      for (int i = 0; i < x.Length; i++) {
-        S[i].x = x[i];
-        S[i].y = y[i];
-      }
-      S[x.Length].x = S[x.Length - 1].x;
-      S[x.Length].y = S[x.Length - 1].y;
-
-      // var
-      double[] h = new double[n],
-        r = new double[n],
-        f = new double[n],
-        p = new double[n];
-      var q = new MyArray<double>(-1, n + 3);
-      var u = new MyArray<double>(-1, n + 3);
-      var v = new MyArray<double>(-1, n + 3);
-      var w = new MyArray<double>(-1, n + 3);
-      double mu;
-
-      mu = 2 * (1 - lambda) / (3 * lambda);
-      h[0] = S[1].x - S[0].x;
-      r[0] = 3 / h[0];
-      for (int i = 1; i < n - 1; i++) {
-        h[i] = S[i + 1].x - S[i].x;
-        r[i] = 3 / h[i];
-        f[i] = -(r[i - 1] + r[i]);
-        p[i] = 2 * (S[i + 1].x - S[i - 1].x);
-        q[i] = 3 * (S[i + 1].y - S[i].y) / h[i] - 3 * (S[i].y - S[i - 1].y) / h[i - 1];
-      }
-      for (int i = 1; i < n; i++) {
-        u[i] = Math.Pow(r[i - 1], 2) * sigma[i - 1] + Math.Pow(f[i], 2) * sigma[i] + Math.Pow(r[i], 2) * sigma[i + 1];    // TODO Sigma 1..n
-        u[i] = mu * u[i] + p[i];
-        v[i] = f[i] * r[i] * sigma[i] + r[i] * f[i + 1] * sigma[i + 1];
-        v[i] = mu * v[i] + h[i];
-        w[i] = mu * r[i] * r[i + 1] * sigma[i + 1];
-      }
-      Quincunx(n, u, v, w, q);
-      // { Spline P arameters}
-      S[0].d = S[0].y - mu * r[0] * q[1] * sigma[0];
-      S[1].d = S[1].y - mu * (f[1] * q[1] + r[1] * q[2]) * sigma[0];
-      S[0].a = q[1] / (3 * h[0]);
-      S[0].b = 0;
-      S[0].c = (S[1].d - S[0].d) / h[0] - q[1] * h[0] / 3;
-      r[0] = 0;
-      for (int j = 1; j < n; j++) {
-        S[j].a = (q[j + 1] - q[j]) / (3 * h[j]);
-        S[j].b = q[j];
-        S[j].c = (q[j] + q[j - 1]) * h[j - 1] + S[j - 1].c;
-        S[j].d = r[j - 1] * q[j - 1] + f[j] * q[j] + r[j] * q[j + 1];
-        S[j].d = y[j] - mu * S[j].d * sigma[j];
-      }
-
-      //   { SmoothingSpline}
-    }
-
     public void CalculateSmoothingSplineReinsch(double[] x, double[] y, string[] inputVars) {
       double s = x.Length + 1;
@@ -541,5 +417,5 @@
 
 
-    // automatically determines tolerance using loo cv, SLOW!
+    // automatically determines tolerance using cv, SLOW!
     public static IRegressionModel CalculateSmoothingSplineReinsch(double[] x, double[] y, string[] inputVars, string targetVar,
       out double optTolerance, out double cvRMSE) {
@@ -665,62 +541,4 @@
 
       return new ReinschSmoothingSplineModel(a, b, c, d, x, targetVar, inputVars);
-    }
-
-    private void CalculateSmoothingSpline(double[] x, double[] y, string[] inputVars) {
-      // see Smoothing and Non-Parametric Regression, Germán Rodríguez, 2001 2.3.1
-      double[] w = Enumerable.Repeat(1.0, x.Length).ToArray();  // weights necessary for sortAndBin but are ignored below (TODO)
-      SortAndBin(x, y, w, out x, out y, out w, scaling: false);
-      int n = x.Length;
-
-      SparseMatrix delta = new SparseMatrix(n - 2, n);
-      // double[,] delta = new double[n - 2, n];
-      //double[,] W = new double[n - 2, n - 2];
-      SparseMatrix W = new SparseMatrix(n - 2, n - 2);
-      Matrix WInvD = new DenseMatrix(n - 2, n);
-
-      // double[,] W_inv_D = new double[n - 2, n];
-      // double[,] K = new double[n, n];
-
-      // go over successive knots to determine distances and fill Delta and W
-      for (int i = 0; i < n - 2; i++) {
-        double h = x[i + 1] - x[i];
-        double h_next = x[i + 2] - x[i + 1];
-        delta[i, i] = 1.0 / h;
-        delta[i, i + 1] = -1.0 / h - 1.0 / h_next;
-        delta[i, i + 2] = 1.0 / h_next;
-        W[i, i] = (h + h_next) / 3;
-        if (i > 0) {
-          W[i - 1, i] =
-           W[i, i - 1] = h / 6.0;
-        }
-      }
-
-      // WInvD = W.Cholesky().Solve(delta);
-      var solvResult = W.TrySolveIterative(delta, WInvD, new MlkBiCgStab());
-
-      // alglib.ablas.rmatrixgemm(n - 2, n, n - 2, 1.0, W, 0, 0, 0, delta, 0, 0, 0, 1.0, W_inv_D, 0, 0); // W^-1(M = n-2, K = n-2) D(K = n-2, N=n)   
-      // alglib.ablas.rmatrixgemm(n, n, n - 2, 1.0, delta, 0, 0, 1, W_inv_D, 0, 0, 0, 1.0, K, 0, 0); // D(M=n-2, K=n)^T * W^-1D (K=n, N=n-2)
-
-      var K = delta.TransposeThisAndMultiply(WInvD);
-
-      double lambda = ((IValueParameter<DoubleValue>)Parameters["Lambda"]).Value.Value;
-
-      for (int i = 0; i < n; i++) {
-        for (int j = 0; j < n; j++) {
-          K[i, j] *= lambda;
-          if (i == j) K[i, j] += 1;
-        }
-      }
-
-      // solve for y
-      // double[] s;
-      // int solverInfo;
-      // alglib.densesolverreport solverRep;
-      // alglib.rmatrixsolve(K, n, y, out solverInfo, out solverRep, out s);
-
-      var s = K.Solve(new DenseVector(y)).ToArray();
-
-      Results.Add(new Result("Solution", new RegressionSolution(new SmoothingSplineModel(s, x, Problem.ProblemData.TargetVariable, inputVars),
-  (IRegressionProblemData)Problem.ProblemData.Clone())));
     }
 
@@ -766,14 +584,4 @@
       w2 = wl.ToArray();
     }
-
-    private void AddAlglibSplineResult(alglib.spline1dinterpolant c, string[] inputVars) {
-      Results.Add(new Result("Solution", new RegressionSolution(new Spline1dModel(c, Problem.ProblemData.TargetVariable, inputVars),
-        (IRegressionProblemData)Problem.ProblemData.Clone())));
-
-    }
-    private void AddMathNetSplineResult(IInterpolation c, string[] inputVars) {
-      Results.Add(new Result("Solution", new RegressionSolution(new MathNetSplineModel(c, Problem.ProblemData.TargetVariable, inputVars),
-        (IRegressionProblemData)Problem.ProblemData.Clone())));
-    }
   }
 
@@ -905,47 +713,6 @@
 
   // UNFINISHED
-  public class SmoothingSplineModel : NamedItem, IRegressionModel {
-    private double[] s;
-    private IInterpolation interpolation;
-
-    public string TargetVariable { get; set; }
-
-    public IEnumerable<string> VariablesUsedForPrediction { get; private set; }
-
-    public event EventHandler TargetVariableChanged;
-
-    public SmoothingSplineModel(SmoothingSplineModel orig, Cloner cloner) : base(orig, cloner) {
-      this.TargetVariable = orig.TargetVariable;
-      this.VariablesUsedForPrediction = orig.VariablesUsedForPrediction.ToArray();
-      this.s = orig.s; // TODO
-      this.interpolation = orig.interpolation;
-    }
-    public SmoothingSplineModel(double[] s, double[] x, string targetVar, string[] inputs) : base("SplineModel", "SplineModel") {
-      this.s = s;
-      this.TargetVariable = targetVar;
-      this.VariablesUsedForPrediction = inputs;
-      this.interpolation = MathNet.Numerics.Interpolate.CubicSpline(x, s);
-    }
-
-    public override IDeepCloneable Clone(Cloner cloner) {
-      return new SmoothingSplineModel(this, cloner);
-    }
-
-    public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
-      return new RegressionSolution(this, (IRegressionProblemData)problemData.Clone());
-    }
-
-    public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
-      foreach (var x in dataset.GetDoubleValues(VariablesUsedForPrediction.First(), rows)) {
-
-        yield return interpolation.Interpolate(x);
-
-      }
-    }
-  }
-
-  // UNFINISHED
   public class Spline1dModel : NamedItem, IRegressionModel {
-    private alglib.spline1dinterpolant interpolant;
+    alglib.spline1dinterpolant interpolant;
 
     public string TargetVariable { get; set; }
@@ -958,8 +725,11 @@
       this.TargetVariable = orig.TargetVariable;
       this.VariablesUsedForPrediction = orig.VariablesUsedForPrediction.ToArray();
+
       this.interpolant = (alglib.spline1dinterpolant)orig.interpolant.make_copy();
     }
-    public Spline1dModel(alglib.spline1dinterpolant interpolant, string targetVar, string[] inputs) : base("SplineModel", "SplineModel") {
-      this.interpolant = interpolant;
+    internal Spline1dModel(
+      alglib.spline1dinterpolant interpolant,
+      string targetVar, string[] inputs, double offset = 0, double scale = 1) : base("SplineModel", "SplineModel") {
+      this.interpolant = (alglib.spline1dinterpolant)interpolant.make_copy();
       this.TargetVariable = targetVar;
       this.VariablesUsedForPrediction = inputs;
@@ -972,4 +742,8 @@
     public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
       return new RegressionSolution(this, (IRegressionProblemData)problemData.Clone());
+    }
+
+    public double GetEstimatedValue(double xx) {
+      return alglib.spline1dcalc(interpolant, xx);
     }
 
@@ -979,44 +753,6 @@
         product = product.Zip(dataset.GetDoubleValues(factor, rows), (pi, fi) => pi * fi).ToArray();
       }
-
-      foreach (var x in product) {
-        yield return alglib.spline1dcalc(interpolant, x);
-      }
-    }
-  }
-
-
-  // UNFINISHED
-  public class MathNetSplineModel : NamedItem, IRegressionModel {
-    private IInterpolation interpolant;
-
-    public string TargetVariable { get; set; }
-
-    public IEnumerable<string> VariablesUsedForPrediction { get; private set; }
-
-    public event EventHandler TargetVariableChanged;
-
-    public MathNetSplineModel(MathNetSplineModel orig, Cloner cloner) : base(orig, cloner) {
-      this.TargetVariable = orig.TargetVariable;
-      this.VariablesUsedForPrediction = orig.VariablesUsedForPrediction.ToArray();
-      this.interpolant = orig.interpolant; // TODO COPY!
-    }
-    public MathNetSplineModel(IInterpolation interpolant, string targetVar, string[] inputs) : base("SplineModel", "SplineModel") {
-      this.interpolant = interpolant;
-      this.TargetVariable = targetVar;
-      this.VariablesUsedForPrediction = inputs;
-    }
-
-    public override IDeepCloneable Clone(Cloner cloner) {
-      return new MathNetSplineModel(this, cloner);
-    }
-
-    public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
-      return new RegressionSolution(this, (IRegressionProblemData)problemData.Clone());
-    }
-
-    public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
-      foreach (var x in dataset.GetDoubleValues(VariablesUsedForPrediction.First(), rows)) {
-        yield return interpolant.Interpolate(x);
+      foreach (var xx in product) {
+        yield return GetEstimatedValue(xx);
       }
     }
