Index: trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovariancePeriodic.cs
===================================================================
--- trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovariancePeriodic.cs	(revision 8489)
+++ trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovariancePeriodic.cs	(revision 8491)
@@ -34,6 +34,6 @@
     public double Scale { get { return sf2; } }
     [Storable]
-    private double l;
-    public double Length { get { return l; } }
+    private double inverseLength;
+    public double InverseLength { get { return inverseLength; } }
     [Storable]
     private double p;
@@ -48,5 +48,5 @@
       : base(original, cloner) {
       sf2 = original.sf2;
-      l = original.l;
+      inverseLength = original.inverseLength;
       p = original.p;
     }
@@ -61,5 +61,5 @@
     public void SetParameter(double[] hyp) {
       if (hyp.Length != 3) throw new ArgumentException();
-      this.l = Math.Exp(hyp[0]);
+      this.inverseLength = 1.0 / Math.Exp(hyp[0]);
       this.p = Math.Exp(hyp[1]);
       this.sf2 = Math.Exp(2 * hyp[2]);
@@ -69,5 +69,5 @@
       double k = i == j ? 0.0 : GetDistance(x, x, i, j);
       k = Math.PI * k / p;
-      k = Math.Sin(k) / l;
+      k = Math.Sin(k) * inverseLength;
       k = k * k;
 
@@ -77,9 +77,9 @@
     public IEnumerable<double> GetGradient(double[,] x, int i, int j) {
       double v = i == j ? 0.0 : Math.PI * GetDistance(x, x, i, j) / p;
-      double gradient = Math.Sin(v) / l;
+      double gradient = Math.Sin(v) * inverseLength;
       gradient *= gradient;
       yield return 4.0 * sf2 * Math.Exp(-2.0 * gradient) * gradient;
-      double r = Math.Sin(v) / l;
-      yield return 4.0 * sf2 / l * Math.Exp(-2 * r * r) * r * Math.Cos(v) * v;
+      double r = Math.Sin(v) * inverseLength;
+      yield return 4.0 * sf2 * inverseLength * Math.Exp(-2 * r * r) * r * Math.Cos(v) * v;
       yield return 2.0 * sf2 * Math.Exp(-2 * gradient);
     }
@@ -88,5 +88,5 @@
       double k = GetDistance(x, xt, i, j);
       k = Math.PI * k / p;
-      k = Math.Sin(k) / l;
+      k = Math.Sin(k) * inverseLength;
       k = k * k;
 
@@ -95,5 +95,5 @@
 
     private double GetDistance(double[,] x, double[,] xt, int i, int j) {
-      return Math.Sqrt(Util.SqrDist(Util.GetRow(x, i), Util.GetRow(xt, j)));
+      return Math.Sqrt(Util.SqrDist(x, i, xt, j));
     }
   }
Index: trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceRQiso.cs
===================================================================
--- trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceRQiso.cs	(revision 8489)
+++ trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceRQiso.cs	(revision 8491)
@@ -22,5 +22,4 @@
 using System;
 using System.Collections.Generic;
-using System.Linq;
 using HeuristicLab.Common;
 using HeuristicLab.Core;
@@ -36,6 +35,6 @@
     public double Scale { get { return sf2; } }
     [Storable]
-    private double l;
-    public double Length { get { return l; } }
+    private double inverseLength;
+    public double InverseLength { get { return inverseLength; } }
     [Storable]
     private double alpha;
@@ -50,5 +49,5 @@
       : base(original, cloner) {
       this.sf2 = original.sf2;
-      this.l = original.l;
+      this.inverseLength = original.inverseLength;
       this.alpha = original.alpha;
     }
@@ -68,5 +67,5 @@
     public void SetParameter(double[] hyp) {
       if (hyp.Length != 3) throw new ArgumentException("CovarianceRQiso has three hyperparameters", "k");
-      this.l = Math.Exp(hyp[0]);
+      this.inverseLength = 1.0 / Math.Exp(hyp[0]);
       this.sf2 = Math.Exp(2 * hyp[1]);
       this.alpha = Math.Exp(hyp[2]);
@@ -75,16 +74,14 @@
 
     public double GetCovariance(double[,] x, int i, int j) {
-      double lInv = 1.0 / l;
       double d = i == j
                    ? 0.0
-                   : Util.SqrDist(Util.GetRow(x, i).Select(e => e * lInv), Util.GetRow(x, j).Select(e => e * lInv));
+                   : Util.SqrDist(x, i, j, inverseLength);
       return sf2 * Math.Pow(1 + 0.5 * d / alpha, -alpha);
     }
 
     public IEnumerable<double> GetGradient(double[,] x, int i, int j) {
-      double lInv = 1.0 / l;
       double d = i == j
                    ? 0.0
-                   : Util.SqrDist(Util.GetRow(x, i).Select(e => e * lInv), Util.GetRow(x, j).Select(e => e * lInv));
+                   : Util.SqrDist(x, i, j, inverseLength);
 
       double b = 1 + 0.5 * d / alpha;
@@ -95,6 +92,5 @@
 
     public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {
-      double lInv = 1.0 / l;
-      double d = Util.SqrDist(Util.GetRow(x, i).Select(e => e * lInv), Util.GetRow(xt, j).Select(e => e * lInv));
+      double d = Util.SqrDist(x, i, xt, j, inverseLength);
       return sf2 * Math.Pow(1 + 0.5 * d / alpha, -alpha);
     }
Index: trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceSEard.cs
===================================================================
--- trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceSEard.cs	(revision 8489)
+++ trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceSEard.cs	(revision 8491)
@@ -36,10 +36,10 @@
 
     [Storable]
-    private double[] l;
+    private double[] inverseLength;
     public double[] Length {
       get {
-        if (l == null) return new double[0];
-        var copy = new double[l.Length];
-        Array.Copy(l, copy, copy.Length);
+        if (inverseLength == null) return new double[0];
+        var copy = new double[inverseLength.Length];
+        Array.Copy(inverseLength, copy, copy.Length);
         return copy;
       }
@@ -53,7 +53,7 @@
     protected CovarianceSEard(CovarianceSEard original, Cloner cloner)
       : base(original, cloner) {
-      if (original.l != null) {
-        this.l = new double[original.l.Length];
-        Array.Copy(original.l, this.l, l.Length);
+      if (original.inverseLength != null) {
+        this.inverseLength = new double[original.inverseLength.Length];
+        Array.Copy(original.inverseLength, this.inverseLength, inverseLength.Length);
       }
       this.sf2 = original.sf2;
@@ -68,5 +68,5 @@
 
     public void SetParameter(double[] hyp) {
-      this.l = hyp.Take(hyp.Length - 1).Select(Math.Exp).ToArray();
+      this.inverseLength = hyp.Take(hyp.Length - 1).Select(p => 1.0 / Math.Exp(p)).ToArray();
       this.sf2 = Math.Exp(2 * hyp[hyp.Length - 1]);
     }
@@ -75,6 +75,5 @@
       double d = i == j
                    ? 0.0
-                   : Util.SqrDist(Util.GetRow(x, i).Select((e, k) => e / l[k]),
-                                  Util.GetRow(x, j).Select((e, k) => e / l[k]));
+                   : Util.SqrDist(x, i, j, inverseLength);
       return sf2 * Math.Exp(-d / 2.0);
     }
@@ -83,9 +82,8 @@
       double d = i == j
                    ? 0.0
-                   : Util.SqrDist(Util.GetRow(x, i).Select((e, ii) => e / l[ii]),
-                                  Util.GetRow(x, j).Select((e, ii) => e / l[ii]));
+                   : Util.SqrDist(x, i, j, inverseLength);
 
-      for (int ii = 0; ii < l.Length; ii++) {
-        double sqrDist = Util.SqrDist(x[i, ii] / l[ii], x[j, ii] / l[ii]);
+      for (int ii = 0; ii < inverseLength.Length; ii++) {
+        double sqrDist = Util.SqrDist(x[i, ii] * inverseLength[ii], x[j, ii] * inverseLength[ii]);
         yield return sf2 * Math.Exp(-d / 2.0) * sqrDist;
       }
@@ -94,5 +92,5 @@
 
     public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {
-      double d = Util.SqrDist(Util.GetRow(x, i).Select((e, k) => e / l[k]), Util.GetRow(xt, j).Select((e, k) => e / l[k]));
+      double d = Util.SqrDist(x, i, xt, j, inverseLength);
       return sf2 * Math.Exp(-d / 2.0);
     }
Index: trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceSEiso.cs
===================================================================
--- trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceSEiso.cs	(revision 8489)
+++ trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceSEiso.cs	(revision 8491)
@@ -22,5 +22,4 @@
 using System;
 using System.Collections.Generic;
-using System.Linq;
 using HeuristicLab.Common;
 using HeuristicLab.Core;
@@ -36,6 +35,6 @@
     public double Scale { get { return sf2; } }
     [Storable]
-    private double l;
-    public double Length { get { return l; } }
+    private double inverseLength;
+    public double InverseLength { get { return inverseLength; } }
 
     [StorableConstructor]
@@ -47,5 +46,5 @@
       : base(original, cloner) {
       this.sf2 = original.sf2;
-      this.l = original.l;
+      this.inverseLength = original.inverseLength;
     }
 
@@ -64,5 +63,5 @@
     public void SetParameter(double[] hyp) {
       if (hyp.Length != 2) throw new ArgumentException("CovarianceSEiso has two hyperparameters", "k");
-      this.l = Math.Exp(hyp[0]);
+      this.inverseLength = 1.0 / Math.Exp(hyp[0]);
       this.sf2 = Math.Exp(2 * hyp[1]);
     }
@@ -70,16 +69,14 @@
 
     public double GetCovariance(double[,] x, int i, int j) {
-      double lInv = 1.0 / l;
       double d = i == j
                    ? 0.0
-                   : Util.SqrDist(Util.GetRow(x, i).Select(e => e * lInv), Util.GetRow(x, j).Select(e => e * lInv));
+                   : Util.SqrDist(x, i, j, inverseLength);
       return sf2 * Math.Exp(-d / 2.0);
     }
 
     public IEnumerable<double> GetGradient(double[,] x, int i, int j) {
-      double lInv = 1.0 / l;
       double d = i == j
                    ? 0.0
-                   : Util.SqrDist(Util.GetRow(x, i).Select(e => e * lInv), Util.GetRow(x, j).Select(e => e * lInv));
+                   : Util.SqrDist(x, i, j, inverseLength);
       double g = Math.Exp(-d / 2.0);
       yield return sf2 * g * d;
@@ -88,6 +85,5 @@
 
     public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {
-      double lInv = 1.0 / l;
-      double d = Util.SqrDist(Util.GetRow(x, i).Select(e => e * lInv), Util.GetRow(xt, j).Select(e => e * lInv));
+      double d = Util.SqrDist(x, i, xt, j, inverseLength);
       return sf2 * Math.Exp(-d / 2.0);
     }
Index: trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/Util.cs
===================================================================
--- trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/Util.cs	(revision 8489)
+++ trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/Util.cs	(revision 8491)
@@ -38,4 +38,29 @@
     }
 
+    public static double SqrDist(double[,] x, int i, int j, double scale = 1.0) {
+      return SqrDist(x, i, x, j, scale);
+    }
+
+    public static double SqrDist(double[,] x, int i, double[,] xt, int j, double scale = 1.0) {
+      double ss = 0.0;
+      for (int k = 0; k < x.GetLength(1); k++) {
+        double d = x[i, k] - xt[j, k];
+        ss += d * d;
+      }
+      return scale * scale * ss;
+    }
+    public static double SqrDist(double[,] x, int i, int j, double[] scale) {
+      return SqrDist(x, i, x, j, scale);
+    }
+
+    public static double SqrDist(double[,] x, int i, double[,] xt, int j, double[] scale) {
+      double ss = 0.0;
+      for (int k = 0; k < x.GetLength(1); k++) {
+        double d = x[i, k] - xt[j, k];
+        ss += d * d * scale[k] * scale[k];
+      }
+      return ss;
+    }
+
     public static IEnumerable<double> GetRow(double[,] x, int r) {
       int cols = x.GetLength(1);
