Index: /trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovariancePeriodic.cs
===================================================================
--- /trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovariancePeriodic.cs	(revision 9107)
+++ /trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovariancePeriodic.cs	(revision 9108)
@@ -82,5 +82,6 @@
 
 
-    private void GetParameterValues(double[] p, out double scale, out double period, out double inverseLength) {
+    private void GetParameterValues(double[] 
+      p, out double scale, out double period, out double inverseLength) {
       // gather parameter values
       int c = 0;
Index: /trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceRationalQuadraticArd.cs
===================================================================
--- /trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceRationalQuadraticArd.cs	(revision 9107)
+++ /trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceRationalQuadraticArd.cs	(revision 9108)
@@ -88,4 +88,13 @@
       int c = 0;
       // gather parameter values
+      if (InverseLengthParameter.Value != null) {
+        inverseLength = InverseLengthParameter.Value.ToArray();
+      } else {
+        int length = p.Length;
+        if (ScaleParameter.Value == null) length--;
+        if (ShapeParameter.Value == null) length--;
+        inverseLength = p.Select(e => 1.0 / Math.Exp(e)).Take(length).ToArray();
+        c += inverseLength.Length;
+      }
       if (ScaleParameter.Value != null) {
         scale = ScaleParameter.Value.Value;
@@ -99,10 +108,4 @@
         shape = Math.Exp(p[c]);
         c++;
-      }
-      if (InverseLengthParameter.Value != null) {
-        inverseLength = InverseLengthParameter.Value.ToArray();
-      } else {
-        inverseLength = p.Skip(c).Select(e => 1.0 / Math.Exp(e)).ToArray();
-        c += inverseLength.Length;
       }
       if (p.Length != c) throw new ArgumentException("The length of the parameter vector does not match the number of free parameters for CovarianceRationalQuadraticArd", "p");
Index: /trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceRationalQuadraticIso.cs
===================================================================
--- /trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceRationalQuadraticIso.cs	(revision 9107)
+++ /trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceRationalQuadraticIso.cs	(revision 9108)
@@ -84,4 +84,10 @@
       int c = 0;
       // gather parameter values
+      if (InverseLengthParameter.Value != null) {
+        inverseLength = InverseLengthParameter.Value.Value;
+      } else {
+        inverseLength = 1.0 / Math.Exp(p[c]);
+        c++;
+      }
       if (ScaleParameter.Value != null) {
         scale = ScaleParameter.Value.Value;
@@ -94,10 +100,4 @@
       } else {
         shape = Math.Exp(p[c]);
-        c++;
-      }
-      if (InverseLengthParameter.Value != null) {
-        inverseLength = InverseLengthParameter.Value.Value;
-      } else {
-        inverseLength = 1.0 / Math.Exp(p[c]);
         c++;
       }
Index: /trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSquaredExponentialArd.cs
===================================================================
--- /trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSquaredExponentialArd.cs	(revision 9107)
+++ /trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSquaredExponentialArd.cs	(revision 9108)
@@ -76,4 +76,12 @@
       int c = 0;
       // gather parameter values
+      if (InverseLengthParameter.Value != null) {
+        inverseLength = InverseLengthParameter.Value.ToArray();
+      } else {
+        int length = p.Length;
+        if (ScaleParameter.Value == null) length--;
+        inverseLength = p.Select(e => 1.0 / Math.Exp(e)).Take(length).ToArray();
+        c += inverseLength.Length;
+      }
       if (ScaleParameter.Value != null) {
         scale = ScaleParameter.Value.Value;
@@ -81,10 +89,4 @@
         scale = Math.Exp(2 * p[c]);
         c++;
-      }
-      if (InverseLengthParameter.Value != null) {
-        inverseLength = InverseLengthParameter.Value.ToArray();
-      } else {
-        inverseLength = p.Skip(c).Select(e => 1.0 / Math.Exp(e)).ToArray();
-        c += inverseLength.Length;
       }
       if (p.Length != c) throw new ArgumentException("The length of the parameter vector does not match the number of free parameters for CovarianceSquaredExponentialArd", "p");
@@ -111,5 +113,5 @@
     }
 
-
+    // order of returned gradients must match the order in GetParameterValues!
     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices, double scale, double[] inverseLength) {
       if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1));
@@ -117,4 +119,5 @@
                    ? 0.0
                    : Util.SqrDist(x, i, j, inverseLength, columnIndices);
+
       int k = 0;
       foreach (var columnIndex in columnIndices) {
@@ -123,5 +126,4 @@
         k++;
       }
-
       yield return 2.0 * scale * Math.Exp(-d / 2.0);
     }
Index: /trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSquaredExponentialIso.cs
===================================================================
--- /trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSquaredExponentialIso.cs	(revision 9107)
+++ /trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSquaredExponentialIso.cs	(revision 9108)
@@ -116,4 +116,5 @@
     }
 
+    // order of returned gradients must match the order in GetParameterValues!
     private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double sf2, double inverseLength, IEnumerable<int> columnIndices) {
       double d = i == j
