Index: trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
===================================================================
--- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj (revision 8857)
+++ trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj (revision 8861)
@@ -164,6 +164,9 @@
+
+
+
+
-
@@ -207,7 +210,4 @@
-
-
-
Index: trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDependencyCalculator.cs
===================================================================
--- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDependencyCalculator.cs (revision 8857)
+++ trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDependencyCalculator.cs (revision 8861)
@@ -21,9 +21,9 @@
using System.Collections.Generic;
-using HeuristicLab.Data;
namespace HeuristicLab.Problems.DataAnalysis {
public interface IDependencyCalculator {
- DoubleRange Interval { get; }
+ double Maximum { get; }
+ double Minimum { get; }
string Name { get; }
Index: trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/HoeffdingsDependenceCalculator.cs
===================================================================
--- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/HoeffdingsDependenceCalculator.cs (revision 8861)
+++ trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/HoeffdingsDependenceCalculator.cs (revision 8861)
@@ -0,0 +1,139 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * 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 .
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace HeuristicLab.Problems.DataAnalysis {
+ public class HoeffdingsDependenceCalculator : IDependencyCalculator {
+
+ public double Maximum { get { return 1.0; } }
+
+ public double Minimum { get { return -0.5; } }
+
+ public string Name { get { return "Hoeffdings Dependence"; } }
+
+ public double Calculate(IEnumerable originalValues, IEnumerable estimatedValues, out OnlineCalculatorError errorState) {
+ return HoeffdingsDependenceCalculator.CalculateHoeffdings(originalValues, estimatedValues, out errorState);
+ }
+
+ public static double CalculateHoeffdings(IEnumerable originalValues, IEnumerable estimatedValues, out OnlineCalculatorError errorState) {
+ double d = HoeffD(originalValues, estimatedValues, out errorState);
+ if (errorState != OnlineCalculatorError.None) return double.NaN;
+ return d;
+ }
+
+ ///
+ /// computes Hoeffding's dependence coefficient.
+ /// Source: hoeffd.r from R package hmisc http://cran.r-project.org/web/packages/Hmisc/index.html
+ ///
+ private static double HoeffD(IEnumerable xs, IEnumerable ys, out OnlineCalculatorError errorState) {
+ double[] rx = TiedRank(xs);
+ double[] ry = TiedRank(ys);
+ if (rx.Length != ry.Length) throw new ArgumentException("The number of elements in xs and ys does not match");
+ double[] rxy = TiedRank(xs, ys);
+
+ int n = rx.Length;
+ double q = 0, r = 0, s = 0;
+ double scaling = 1.0 / (n * (n - 1));
+ for (int i = 0; i < n; i++) {
+ q += (rx[i] - 1) * (rx[i] - 2) * (ry[i] - 1) * (ry[i] - 2) * scaling;
+ r += (rx[i] - 2) * (ry[i] - 2) * rxy[i] * scaling;
+ s += rxy[i] * (rxy[i] - 1) * scaling;
+ }
+ errorState = OnlineCalculatorError.None;
+ // return 30.0 * (q - 2 * (n - 2) * r + (n - 2) * (n - 3) * s) / n / (n - 1) / (n - 2) / (n - 3) / (n - 4);
+ double t0 = q / (n - 2) / (n - 3) / (n - 4);
+ double t1 = 2 * r / (n - 3) / (n - 4);
+ double t2 = s / (n - 4);
+ return 30.0 * (t0 - t1 + t2);
+ }
+
+ private static double[] TiedRank(IEnumerable xs) {
+ var xsArr = xs.ToArray();
+ var idx = Enumerable.Range(1, xsArr.Length).ToArray();
+ Array.Sort(xsArr, idx);
+ CRank(xsArr);
+ Array.Sort(idx, xsArr);
+ return xsArr;
+ }
+
+ ///
+ /// Calculates the joint rank with midranks for ties. Source: hoeffd.r from R package hmisc http://cran.r-project.org/web/packages/Hmisc/index.html
+ ///
+ ///
+ ///
+ ///
+ private static double[] TiedRank(IEnumerable xs, IEnumerable ys) {
+ var xsArr = xs.ToArray();
+ var ysArr = ys.ToArray();
+ var r = new double[xsArr.Length];
+ int n = r.Length;
+ for (int i = 0; i < n; i++) {
+ var xi = xsArr[i];
+ var yi = ysArr[i];
+ double ri = 0.0;
+ for (int j = 0; j < n; j++) {
+ if (i != j) {
+ double cx;
+ if (xsArr[j] < xi) cx = 1.0;
+ else if (xsArr[j] > xi) cx = 0.0;
+ else cx = 0.5; // eq
+ double cy;
+ if (ysArr[j] < yi) cy = 1.0;
+ else if (ysArr[j] > yi) cy = 0.0;
+ else cy = 0.5; // eq
+ ri = ri + cx * cy;
+ }
+ }
+ r[i] = ri;
+ }
+ return r;
+ }
+
+ ///
+ /// Calculates midranks. Source: Numerical Recipes in C. p 642
+ ///
+ /// Sorted array of elements, replaces the elements by their rank, including midranking of ties
+ ///
+ private static void CRank(double[] w) {
+ int i = 0;
+ int n = w.Length;
+ while (i < n - 1) {
+ if (w[i + 1] > w[i]) { // w[i+1] must be larger or equal w[i] as w must be sorted
+ // not a tie
+ w[i] = i + 1;
+ i++;
+ } else {
+ int j;
+ for (j = i + 1; j < n && w[j] <= w[i]; j++) ; // how far does it go (<= effectively means == as w must be sorted, side-step equality for double values)
+ double rank = 1 + 0.5 * (i + j - 1);
+ int k;
+ for (k = i; k < j; k++) w[k] = rank; // set the rank for all tied entries
+ i = j;
+ }
+ }
+
+ if (i == n - 1) w[n - 1] = n; // if the last element was not tied, this is its rank
+ }
+ }
+}
Index: trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/PearsonsRDependenceCalculator.cs
===================================================================
--- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/PearsonsRDependenceCalculator.cs (revision 8861)
+++ trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/PearsonsRDependenceCalculator.cs (revision 8861)
@@ -0,0 +1,38 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * 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 .
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+
+namespace HeuristicLab.Problems.DataAnalysis {
+ public class PearsonsRDependenceCalculator : IDependencyCalculator {
+
+ public double Maximum { get { return 1.0; } }
+
+ public double Minimum { get { return -1.0; } }
+
+ public string Name { get { return "Pearsons R"; } }
+
+ public double Calculate(IEnumerable originalValues, IEnumerable estimatedValues, out OnlineCalculatorError errorState) {
+ return Math.Sqrt(OnlinePearsonsRSquaredCalculator.Calculate(originalValues, estimatedValues, out errorState));
+ }
+ }
+}
Index: trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/PearsonsRSquaredDependenceCalculator.cs
===================================================================
--- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/PearsonsRSquaredDependenceCalculator.cs (revision 8861)
+++ trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/PearsonsRSquaredDependenceCalculator.cs (revision 8861)
@@ -0,0 +1,37 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * 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 .
+ */
+#endregion
+
+using System.Collections.Generic;
+
+namespace HeuristicLab.Problems.DataAnalysis {
+ public class PearsonsRSquaredDependenceCalculator : IDependencyCalculator {
+
+ public double Maximum { get { return 1.0; } }
+
+ public double Minimum { get { return 0.0; } }
+
+ public string Name { get { return "Pearsons R Squared"; } }
+
+ public double Calculate(IEnumerable originalValues, IEnumerable estimatedValues, out OnlineCalculatorError errorState) {
+ return OnlinePearsonsRSquaredCalculator.Calculate(originalValues, estimatedValues, out errorState);
+ }
+ }
+}
Index: trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/SpearmansRankCorrelationCoefficientCalculator.cs
===================================================================
--- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/SpearmansRankCorrelationCoefficientCalculator.cs (revision 8861)
+++ trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/SpearmansRankCorrelationCoefficientCalculator.cs (revision 8861)
@@ -0,0 +1,53 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * 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 .
+ */
+#endregion
+
+using System.Collections.Generic;
+using System.Linq;
+
+namespace HeuristicLab.Problems.DataAnalysis {
+ public class SpearmansRankCorrelationCoefficientCalculator : IDependencyCalculator {
+
+ public double Maximum { get { return 1.0; } }
+
+ public double Minimum { get { return -1.0; } }
+
+ public string Name { get { return "Spearmans Rank"; } }
+
+ public double Calculate(IEnumerable originalValues, IEnumerable estimatedValues, out OnlineCalculatorError errorState) {
+ return SpearmansRankCorrelationCoefficientCalculator.CalculateSpearmansRank(originalValues, estimatedValues, out errorState);
+ }
+
+ public static double CalculateSpearmansRank(IEnumerable originalValues, IEnumerable estimatedValues, out OnlineCalculatorError errorState) {
+ double rs = double.NaN;
+ try {
+ var original = originalValues.ToArray();
+ var estimated = estimatedValues.ToArray();
+ rs = alglib.basestat.spearmancorr2(original, estimated, original.Length);
+ errorState = OnlineCalculatorError.None;
+ }
+ catch (alglib.alglibexception) {
+ errorState = OnlineCalculatorError.InvalidValueAdded;
+ }
+
+ return rs;
+ }
+ }
+}
Index: trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/HoeffdingsDependenceCalculator.cs
===================================================================
--- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/HoeffdingsDependenceCalculator.cs (revision 8857)
+++ (revision )
@@ -1,138 +1,0 @@
-#region License Information
-/* HeuristicLab
- * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
- *
- * 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 .
- */
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using HeuristicLab.Data;
-
-namespace HeuristicLab.Problems.DataAnalysis {
- public class HoeffdingsDependenceCalculator : IDependencyCalculator {
-
- public DoubleRange Interval { get { return new DoubleRange(1.0, -0.5); } }
-
- public string Name { get { return "Hoeffdings Dependence"; } }
-
- public double Calculate(IEnumerable originalValues, IEnumerable estimatedValues, out OnlineCalculatorError errorState) {
- return HoeffdingsDependenceCalculator.CalculateHoeffdings(originalValues, estimatedValues, out errorState);
- }
-
- public static double CalculateHoeffdings(IEnumerable originalValues, IEnumerable estimatedValues, out OnlineCalculatorError errorState) {
- double d = HoeffD(originalValues, estimatedValues, out errorState);
- if (errorState != OnlineCalculatorError.None) return double.NaN;
- return d;
- }
-
- ///
- /// computes Hoeffding's dependence coefficient.
- /// Source: hoeffd.r from R package hmisc http://cran.r-project.org/web/packages/Hmisc/index.html
- ///
- private static double HoeffD(IEnumerable xs, IEnumerable ys, out OnlineCalculatorError errorState) {
- double[] rx = TiedRank(xs);
- double[] ry = TiedRank(ys);
- if (rx.Length != ry.Length) throw new ArgumentException("The number of elements in xs and ys does not match");
- double[] rxy = TiedRank(xs, ys);
-
- int n = rx.Length;
- double q = 0, r = 0, s = 0;
- double scaling = 1.0 / (n * (n - 1));
- for (int i = 0; i < n; i++) {
- q += (rx[i] - 1) * (rx[i] - 2) * (ry[i] - 1) * (ry[i] - 2) * scaling;
- r += (rx[i] - 2) * (ry[i] - 2) * rxy[i] * scaling;
- s += rxy[i] * (rxy[i] - 1) * scaling;
- }
- errorState = OnlineCalculatorError.None;
- // return 30.0 * (q - 2 * (n - 2) * r + (n - 2) * (n - 3) * s) / n / (n - 1) / (n - 2) / (n - 3) / (n - 4);
- double t0 = q / (n - 2) / (n - 3) / (n - 4);
- double t1 = 2 * r / (n - 3) / (n - 4);
- double t2 = s / (n - 4);
- return 30.0 * (t0 - t1 + t2);
- }
-
- private static double[] TiedRank(IEnumerable xs) {
- var xsArr = xs.ToArray();
- var idx = Enumerable.Range(1, xsArr.Length).ToArray();
- Array.Sort(xsArr, idx);
- CRank(xsArr);
- Array.Sort(idx, xsArr);
- return xsArr;
- }
-
- ///
- /// Calculates the joint rank with midranks for ties. Source: hoeffd.r from R package hmisc http://cran.r-project.org/web/packages/Hmisc/index.html
- ///
- ///
- ///
- ///
- private static double[] TiedRank(IEnumerable xs, IEnumerable ys) {
- var xsArr = xs.ToArray();
- var ysArr = ys.ToArray();
- var r = new double[xsArr.Length];
- int n = r.Length;
- for (int i = 0; i < n; i++) {
- var xi = xsArr[i];
- var yi = ysArr[i];
- double ri = 0.0;
- for (int j = 0; j < n; j++) {
- if (i != j) {
- double cx;
- if (xsArr[j] < xi) cx = 1.0;
- else if (xsArr[j] > xi) cx = 0.0;
- else cx = 0.5; // eq
- double cy;
- if (ysArr[j] < yi) cy = 1.0;
- else if (ysArr[j] > yi) cy = 0.0;
- else cy = 0.5; // eq
- ri = ri + cx * cy;
- }
- }
- r[i] = ri;
- }
- return r;
- }
-
- ///
- /// Calculates midranks. Source: Numerical Recipes in C. p 642
- ///
- /// Sorted array of elements, replaces the elements by their rank, including midranking of ties
- ///
- private static void CRank(double[] w) {
- int i = 0;
- int n = w.Length;
- while (i < n - 1) {
- if (w[i + 1] > w[i]) { // w[i+1] must be larger or equal w[i] as w must be sorted
- // not a tie
- w[i] = i + 1;
- i++;
- } else {
- int j;
- for (j = i + 1; j < n && w[j] <= w[i]; j++) ; // how far does it go (<= effectively means == as w must be sorted, side-step equality for double values)
- double rank = 1 + 0.5 * (i + j - 1);
- int k;
- for (k = i; k < j; k++) w[k] = rank; // set the rank for all tied entries
- i = j;
- }
- }
-
- if (i == n - 1) w[n - 1] = n; // if the last element was not tied, this is its rank
- }
- }
-}
Index: trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/PearsonsRDependenceCalculator.cs
===================================================================
--- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/PearsonsRDependenceCalculator.cs (revision 8857)
+++ (revision )
@@ -1,37 +1,0 @@
-#region License Information
-/* HeuristicLab
- * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
- *
- * 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 .
- */
-#endregion
-
-using System;
-using System.Collections.Generic;
-using HeuristicLab.Data;
-
-namespace HeuristicLab.Problems.DataAnalysis {
- public class PearsonsRDependenceCalculator : IDependencyCalculator {
-
- public DoubleRange Interval { get { return new DoubleRange(1.0, -1.0); } }
-
- public string Name { get { return "Pearsons R"; } }
-
- public double Calculate(IEnumerable originalValues, IEnumerable estimatedValues, out OnlineCalculatorError errorState) {
- return Math.Sqrt(OnlinePearsonsRSquaredCalculator.Calculate(originalValues, estimatedValues, out errorState));
- }
- }
-}
Index: trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/PearsonsRSquaredDependenceCalculator.cs
===================================================================
--- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/PearsonsRSquaredDependenceCalculator.cs (revision 8857)
+++ (revision )
@@ -1,36 +1,0 @@
-#region License Information
-/* HeuristicLab
- * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
- *
- * 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 .
- */
-#endregion
-
-using System.Collections.Generic;
-using HeuristicLab.Data;
-
-namespace HeuristicLab.Problems.DataAnalysis {
- public class PearsonsRSquaredDependenceCalculator : IDependencyCalculator {
-
- public DoubleRange Interval { get { return new DoubleRange(1.0, 0.0); } }
-
- public string Name { get { return "Pearsons R Squared"; } }
-
- public double Calculate(IEnumerable originalValues, IEnumerable estimatedValues, out OnlineCalculatorError errorState) {
- return OnlinePearsonsRSquaredCalculator.Calculate(originalValues, estimatedValues, out errorState);
- }
- }
-}
Index: trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/SpearmansRankCorrelationCoefficientCalculator.cs
===================================================================
--- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/SpearmansRankCorrelationCoefficientCalculator.cs (revision 8857)
+++ (revision )
@@ -1,52 +1,0 @@
-#region License Information
-/* HeuristicLab
- * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
- *
- * 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 .
- */
-#endregion
-
-using System.Collections.Generic;
-using System.Linq;
-using HeuristicLab.Data;
-
-namespace HeuristicLab.Problems.DataAnalysis {
- public class SpearmansRankCorrelationCoefficientCalculator : IDependencyCalculator {
-
- public DoubleRange Interval { get { return new DoubleRange(1.0, -1.0); } }
-
- public string Name { get { return "Spearmans Rank"; } }
-
- public double Calculate(IEnumerable originalValues, IEnumerable estimatedValues, out OnlineCalculatorError errorState) {
- return SpearmansRankCorrelationCoefficientCalculator.CalculateSpearmansRank(originalValues, estimatedValues, out errorState);
- }
-
- public static double CalculateSpearmansRank(IEnumerable originalValues, IEnumerable estimatedValues, out OnlineCalculatorError errorState) {
- double rs = double.NaN;
- try {
- var original = originalValues.ToArray();
- var estimated = estimatedValues.ToArray();
- rs = alglib.basestat.spearmancorr2(original, estimated, original.Length);
- errorState = OnlineCalculatorError.None;
- }
- catch (alglib.alglibexception) {
- errorState = OnlineCalculatorError.InvalidValueAdded;
- }
-
- return rs;
- }
- }
-}