Changeset 13721 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions
- Timestamp:
- 03/23/16 16:19:04 (9 years ago)
- Location:
- trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceConst.cs
r12012 r13721 83 83 } 84 84 85 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int>columnIndices) {85 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) { 86 86 double scale; 87 87 GetParameterValues(p, out scale); … … 98 98 } 99 99 100 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double scale, IEnumerable<int>columnIndices) {100 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double scale, int[] columnIndices) { 101 101 yield return 2.0 * scale; 102 102 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceLinear.cs
r12012 r13721 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using System.Linq; 25 24 using HeuristicLab.Common; … … 52 51 } 53 52 54 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int>columnIndices) {53 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) { 55 54 if (p.Length > 0) throw new ArgumentException("No parameters are allowed for the linear covariance function."); 56 55 // create functions 57 56 var cov = new ParameterizedCovarianceFunction(); 58 cov.Covariance = (x, i, j) => Util.ScalarProd(x, i, j, 1, columnIndices);59 cov.CrossCovariance = (x, xt, i, j) => Util.ScalarProd(x, i, xt, j, 1.0 , columnIndices);57 cov.Covariance = (x, i, j) => Util.ScalarProd(x, i, j, columnIndices, 1.0); 58 cov.CrossCovariance = (x, xt, i, j) => Util.ScalarProd(x, i, xt, j, columnIndices, 1.0); 60 59 cov.CovarianceGradient = (x, i, j) => Enumerable.Empty<double>(); 61 60 return cov; -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceLinearArd.cs
r12012 r13721 81 81 } 82 82 83 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int>columnIndices) {83 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) { 84 84 double[] inverseLength; 85 85 GetParameterValues(p, out inverseLength); … … 96 96 } 97 97 98 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double[] inverseLength, IEnumerable<int>columnIndices) {98 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double[] inverseLength, int[] columnIndices) { 99 99 int k = 0; 100 foreach (int columnIndex in columnIndices) { 100 for (int c = 0; c < columnIndices.Length; c++) { 101 var columnIndex = columnIndices[c]; 101 102 yield return -2.0 * x[i, columnIndex] * x[j, columnIndex] * inverseLength[k] * inverseLength[k]; 102 103 k++; -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceMask.cs
r12012 r13721 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 22 using System.Linq; 25 using System.Linq.Expressions;26 23 using HeuristicLab.Common; 27 24 using HeuristicLab.Core; … … 73 70 } 74 71 75 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int>columnIndices) {72 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) { 76 73 var cov = CovarianceFunctionParameter.Value; 77 74 var selectedDimensions = SelectedDimensionsParameter.Value; 78 75 79 return cov.GetParameterizedCovarianceFunction(p, selectedDimensions.Intersect(columnIndices) );76 return cov.GetParameterizedCovarianceFunction(p, selectedDimensions.Intersect(columnIndices).ToArray()); 80 77 } 81 78 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceMaternIso.cs
r12012 r13721 111 111 } 112 112 113 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int>columnIndices) {113 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) { 114 114 double inverseLength, scale; 115 115 int d = DParameter.Value.Value; … … 122 122 double dist = i == j 123 123 ? 0.0 124 : Math.Sqrt(Util.SqrDist(x, i, j, Math.Sqrt(d) * inverseLength, columnIndices));124 : Math.Sqrt(Util.SqrDist(x, i, j, columnIndices, Math.Sqrt(d) * inverseLength)); 125 125 return scale * m(d, dist); 126 126 }; 127 127 cov.CrossCovariance = (x, xt, i, j) => { 128 double dist = Math.Sqrt(Util.SqrDist(x, i, xt, j, Math.Sqrt(d) * inverseLength, columnIndices));128 double dist = Math.Sqrt(Util.SqrDist(x, i, xt, j, columnIndices, Math.Sqrt(d) * inverseLength)); 129 129 return scale * m(d, dist); 130 130 }; … … 156 156 157 157 158 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, int d, double scale, double inverseLength, IEnumerable<int>columnIndices,158 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, int d, double scale, double inverseLength, int[] columnIndices, 159 159 bool fixedInverseLength, bool fixedScale) { 160 160 double dist = i == j 161 161 ? 0.0 162 : Math.Sqrt(Util.SqrDist(x, i, j, Math.Sqrt(d) * inverseLength, columnIndices));162 : Math.Sqrt(Util.SqrDist(x, i, j, columnIndices, Math.Sqrt(d) * inverseLength)); 163 163 164 164 if (!fixedInverseLength) yield return scale * dm(d, dist); -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceNeuralNetwork.cs
r12012 r13721 102 102 } 103 103 104 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int>columnIndices) {104 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) { 105 105 double length, scale; 106 106 GetParameterValues(p, out scale, out length); … … 113 113 double s1 = 1.0; 114 114 double s2 = 1.0; 115 foreach (var col in columnIndices) { 115 for (int c = 0; c < columnIndices.Length; c++) { 116 var col = columnIndices[c]; 116 117 sx += x[i, col] * x[j, col]; 117 118 s1 += x[i, col] * x[i, col]; … … 125 126 double s1 = 1.0; 126 127 double s2 = 1.0; 127 foreach (var col in columnIndices) { 128 for (int c = 0; c < columnIndices.Length; c++) { 129 var col = columnIndices[c]; 128 130 sx += x[i, col] * xt[j, col]; 129 131 s1 += x[i, col] * x[i, col]; … … 138 140 139 141 // order of returned gradients must match the order in GetParameterValues! 140 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double length, double scale, IEnumerable<int>columnIndices,142 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double length, double scale, int[] columnIndices, 141 143 bool fixedLength, bool fixedScale) { 142 144 { … … 144 146 double s1 = 1.0; 145 147 double s2 = 1.0; 146 foreach (var col in columnIndices) { 148 for (int c = 0; c < columnIndices.Length; c++) { 149 var col = columnIndices[c]; 147 150 sx += x[i, col] * x[j, col]; 148 151 s1 += x[i, col] * x[i, col]; -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceNoise.cs
r12012 r13721 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using System.Linq; 25 24 using HeuristicLab.Common; … … 84 83 } 85 84 86 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int>columnIndices) {85 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) { 87 86 double scale; 88 87 GetParameterValues(p, out scale); … … 91 90 var cov = new ParameterizedCovarianceFunction(); 92 91 cov.Covariance = (x, i, j) => i == j ? scale : 0.0; 93 cov.CrossCovariance = (x, xt, i, j) => Util.SqrDist(x, i, xt, j, 1.0, columnIndices) < 1e-9 ? scale : 0.0;92 cov.CrossCovariance = (x, xt, i, j) => Util.SqrDist(x, i, xt, j, columnIndices, 1.0) < 1e-9 ? scale : 0.0; 94 93 if (fixedScale) 95 94 cov.CovarianceGradient = (x, i, j) => Enumerable.Empty<double>(); -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovariancePeriodic.cs
r12012 r13721 117 117 } 118 118 119 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int>columnIndices) {119 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[]columnIndices) { 120 120 double inverseLength, period, scale; 121 121 GetParameterValues(p, out scale, out period, out inverseLength); … … 146 146 147 147 148 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int>columnIndices, double scale, double period, double inverseLength,148 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, int[] columnIndices, double scale, double period, double inverseLength, 149 149 bool fixedInverseLength, bool fixedPeriod, bool fixedScale) { 150 150 double k = i == j ? 0.0 : Math.PI * GetDistance(x, x, i, j, columnIndices) / period; … … 161 161 } 162 162 163 private static double GetDistance(double[,] x, double[,] xt, int i, int j, IEnumerable<int>columnIndices) {164 return Math.Sqrt(Util.SqrDist(x, i, xt, j, 1, columnIndices));163 private static double GetDistance(double[,] x, double[,] xt, int i, int j, int[] columnIndices) { 164 return Math.Sqrt(Util.SqrDist(x, i, xt, j, columnIndices, 1)); 165 165 } 166 166 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovariancePiecewisePolynomial.cs
r12012 r13721 113 113 } 114 114 115 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int>columnIndices) {115 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) { 116 116 double length, scale; 117 117 int v = VParameter.Value.Value; … … 148 148 var cov = new ParameterizedCovarianceFunction(); 149 149 cov.Covariance = (x, i, j) => { 150 double k = Math.Sqrt(Util.SqrDist(x, i, x, j, 1.0 / length, columnIndices));150 double k = Math.Sqrt(Util.SqrDist(x, i, x, j, columnIndices, 1.0 / length)); 151 151 return scale * Math.Pow(Math.Max(1 - k, 0), exp + v) * f(k); 152 152 }; 153 153 cov.CrossCovariance = (x, xt, i, j) => { 154 double k = Math.Sqrt(Util.SqrDist(x, i, xt, j, 1.0 / length, columnIndices));154 double k = Math.Sqrt(Util.SqrDist(x, i, xt, j, columnIndices, 1.0 / length)); 155 155 return scale * Math.Pow(Math.Max(1 - k, 0), exp + v) * f(k); 156 156 }; … … 159 159 } 160 160 161 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double length, double scale, int v, double exp, Func<double, double> f, Func<double, double> df, IEnumerable<int>columnIndices,161 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double length, double scale, int v, double exp, Func<double, double> f, Func<double, double> df, int[] columnIndices, 162 162 bool fixedLength, bool fixedScale) { 163 double k = Math.Sqrt(Util.SqrDist(x, i, x, j, 1.0 / length, columnIndices));163 double k = Math.Sqrt(Util.SqrDist(x, i, x, j, columnIndices, 1.0 / length)); 164 164 if (!fixedLength) yield return scale * Math.Pow(Math.Max(1.0 - k, 0), exp + v - 1) * k * ((exp + v) * f(k) - Math.Max(1 - k, 0) * df(k)); 165 165 if (!fixedScale) yield return 2.0 * scale * Math.Pow(Math.Max(1 - k, 0), exp + v) * f(k); -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovariancePolynomial.cs
r12012 r13721 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq;25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Core; … … 107 106 } 108 107 109 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int>columnIndices) {108 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) { 110 109 double @const, scale; 111 110 int degree = DegreeParameter.Value.Value; … … 116 115 // create functions 117 116 var cov = new ParameterizedCovarianceFunction(); 118 cov.Covariance = (x, i, j) => scale * Math.Pow(@const + Util.ScalarProd(x, i, j, 1.0, columnIndices), degree);119 cov.CrossCovariance = (x, xt, i, j) => scale * Math.Pow(@const + Util.ScalarProd(x, i, xt, j, 1.0, columnIndices), degree);117 cov.Covariance = (x, i, j) => scale * Math.Pow(@const + Util.ScalarProd(x, i, j, columnIndices, 1.0), degree); 118 cov.CrossCovariance = (x, xt, i, j) => scale * Math.Pow(@const + Util.ScalarProd(x, i, xt, j, columnIndices, 1.0), degree); 120 119 cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, @const, scale, degree, columnIndices, fixedConst, fixedScale); 121 120 return cov; 122 121 } 123 122 124 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double c, double scale, int degree, IEnumerable<int>columnIndices,123 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double c, double scale, int degree, int[] columnIndices, 125 124 bool fixedConst, bool fixedScale) { 126 double s = Util.ScalarProd(x, i, j, 1.0, columnIndices);125 double s = Util.ScalarProd(x, i, j, columnIndices, 1.0); 127 126 if (!fixedConst) yield return c * degree * scale * Math.Pow(c + s, degree - 1); 128 127 if (!fixedScale) yield return 2 * scale * Math.Pow(c + s, degree); -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceProduct.cs
r12012 r13721 76 76 } 77 77 78 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int>columnIndices) {78 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) { 79 79 if (factors.Count == 0) throw new ArgumentException("at least one factor is necessary for the product covariance function."); 80 80 var functions = new List<ParameterizedCovarianceFunction>(); -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceRationalQuadraticArd.cs
r12012 r13721 121 121 } 122 122 123 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int>columnIndices) {123 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) { 124 124 double scale, shape; 125 125 double[] inverseLength; … … 144 144 } 145 145 146 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int>columnIndices, double scale, double shape, double[] inverseLength,146 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, int[] columnIndices, double scale, double shape, double[] inverseLength, 147 147 bool fixedInverseLength, bool fixedScale, bool fixedShape) { 148 148 double d = i == j -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceRationalQuadraticIso.cs
r12012 r13721 117 117 } 118 118 119 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int>columnIndices) {119 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) { 120 120 double scale, shape, inverseLength; 121 121 GetParameterValues(p, out scale, out shape, out inverseLength); … … 128 128 double d = i == j 129 129 ? 0.0 130 : Util.SqrDist(x, i, j, inverseLength, columnIndices);130 : Util.SqrDist(x, i, j, columnIndices, inverseLength); 131 131 return scale * Math.Pow(1 + 0.5 * d / shape, -shape); 132 132 }; 133 133 cov.CrossCovariance = (x, xt, i, j) => { 134 double d = Util.SqrDist(x, i, xt, j, inverseLength, columnIndices);134 double d = Util.SqrDist(x, i, xt, j, columnIndices, inverseLength); 135 135 return scale * Math.Pow(1 + 0.5 * d / shape, -shape); 136 136 }; … … 139 139 } 140 140 141 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int>columnIndices, double scale, double shape, double inverseLength,141 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, int[] columnIndices, double scale, double shape, double inverseLength, 142 142 bool fixedInverseLength, bool fixedScale, bool fixedShape) { 143 143 double d = i == j 144 144 ? 0.0 145 : Util.SqrDist(x, i, j, inverseLength, columnIndices);145 : Util.SqrDist(x, i, j, columnIndices, inverseLength); 146 146 147 147 double b = 1 + 0.5 * d / shape; -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceScale.cs
r12012 r13721 87 87 } 88 88 89 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int>columnIndices) {89 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) { 90 90 double scale; 91 91 GetParameterValues(p, out scale); … … 100 100 } 101 101 102 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int>columnIndices, double scale, ParameterizedCovarianceFunction cov,102 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, int[] columnIndices, double scale, ParameterizedCovarianceFunction cov, 103 103 bool fixedScale) { 104 104 if (!fixedScale) { -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSpectralMixture.cs
r12012 r13721 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Linq.Expressions;26 25 using HeuristicLab.Common; 27 26 using HeuristicLab.Core; … … 131 130 } 132 131 133 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int>columnIndices) {132 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) { 134 133 double[] weight, frequency, lengthScale; 135 134 GetParameterValues(p, out weight, out frequency, out lengthScale); … … 152 151 } 153 152 154 private static double GetCovariance(double[,] x, double[,] xt, int i, int j, int maxQ, double[] weight, double[] frequency, double[] lengthScale, IEnumerable<int>columnIndices) {153 private static double GetCovariance(double[,] x, double[,] xt, int i, int j, int maxQ, double[] weight, double[] frequency, double[] lengthScale, int[] columnIndices) { 155 154 // tau = x - x' (only for selected variables) 156 155 double[] tau = … … 164 163 int idx = 0; // helper index for tau 165 164 // for each selected variable 166 foreach (var c in columnIndices) { 167 kc *= f1(tau[idx], lengthScale[q * numberOfVariables + c]) * f2(tau[idx], frequency[q * numberOfVariables + c]); 165 for (int c = 0; c < columnIndices.Length; c++) { 166 var col = columnIndices[c]; 167 kc *= f1(tau[idx], lengthScale[q * numberOfVariables + col]) * f2(tau[idx], frequency[q * numberOfVariables + col]); 168 168 idx++; 169 169 } … … 181 181 182 182 // order of returned gradients must match the order in GetParameterValues! 183 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, int maxQ, double[] weight, double[] frequency, double[] lengthScale, IEnumerable<int>columnIndices,183 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, int maxQ, double[] weight, double[] frequency, double[] lengthScale, int[] columnIndices, 184 184 bool fixedWeight, bool fixedFrequency, bool fixedLengthScale) { 185 185 double[] tau = Util.GetRow(x, i, columnIndices).Zip(Util.GetRow(x, j, columnIndices), (xi, xj) => xi - xj).ToArray(); … … 193 193 int idx = 0; // helper index for tau 194 194 // for each selected variable 195 foreach (var c in columnIndices) { 196 k *= f1(tau[idx], lengthScale[q * numberOfVariables + c]) * f2(tau[idx], frequency[q * numberOfVariables + c]); 195 for (int c = 0; c < columnIndices.Length; c++) { 196 var col = columnIndices[c]; 197 k *= f1(tau[idx], lengthScale[q * numberOfVariables + col]) * f2(tau[idx], frequency[q * numberOfVariables + col]); 197 198 idx++; 198 199 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSquaredExponentialArd.cs
r12012 r13721 99 99 } 100 100 101 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int>columnIndices) {101 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) { 102 102 double scale; 103 103 double[] inverseLength; … … 122 122 123 123 // order of returned gradients must match the order in GetParameterValues! 124 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int>columnIndices, double scale, double[] inverseLength,124 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, int[] columnIndices, double scale, double[] inverseLength, 125 125 bool fixedInverseLength, bool fixedScale) { 126 126 double d = i == j … … 130 130 int k = 0; 131 131 if (!fixedInverseLength) { 132 foreach (var columnIndex in columnIndices) { 132 for (int c = 0; c < columnIndices.Length; c++) { 133 var columnIndex = columnIndices[c]; 133 134 double sqrDist = Util.SqrDist(x[i, columnIndex] * inverseLength[k], x[j, columnIndex] * inverseLength[k]); 134 135 yield return scale * Math.Exp(-d / 2.0) * sqrDist; -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSquaredExponentialIso.cs
r12012 r13721 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq.Expressions;25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Core; … … 104 103 } 105 104 106 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int>columnIndices) {105 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) { 107 106 double inverseLength, scale; 108 107 GetParameterValues(p, out scale, out inverseLength); … … 114 113 double d = i == j 115 114 ? 0.0 116 : Util.SqrDist(x, i, j, inverseLength, columnIndices);115 : Util.SqrDist(x, i, j, columnIndices, inverseLength); 117 116 return scale * Math.Exp(-d / 2.0); 118 117 }; 119 118 cov.CrossCovariance = (x, xt, i, j) => { 120 double d = Util.SqrDist(x, i, xt, j, inverseLength, columnIndices);119 double d = Util.SqrDist(x, i, xt, j, columnIndices, inverseLength); 121 120 return scale * Math.Exp(-d / 2.0); 122 121 }; … … 127 126 128 127 // order of returned gradients must match the order in GetParameterValues! 129 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double sf2, double inverseLength, IEnumerable<int> columnIndices,128 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double sf2, double inverseLength, int[] columnIndices, 130 129 bool fixedInverseLength, bool fixedScale) { 131 130 double d = i == j 132 131 ? 0.0 133 : Util.SqrDist(x, i, j, inverseLength, columnIndices);132 : Util.SqrDist(x, i, j, columnIndices, inverseLength); 134 133 double g = Math.Exp(-d / 2.0); 135 134 if (!fixedInverseLength) yield return sf2 * g * d; -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSum.cs
r12012 r13721 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Linq.Expressions;26 25 using HeuristicLab.Common; 27 26 using HeuristicLab.Core; … … 76 75 } 77 76 78 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int>columnIndices) {77 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, int[] columnIndices) { 79 78 if (terms.Count == 0) throw new ArgumentException("at least one term is necessary for the product covariance function."); 80 79 var functions = new List<ParameterizedCovarianceFunction>();
Note: See TracChangeset
for help on using the changeset viewer.