Changeset 10489 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSquaredExponentialArd.cs
- Timestamp:
- 02/20/14 17:45:06 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSquaredExponentialArd.cs
r9456 r10489 40 40 get { return (IValueParameter<DoubleArray>)Parameters["InverseLength"]; } 41 41 } 42 private bool HasFixedInverseLengthParameter { 43 get { return InverseLengthParameter.Value != null; } 44 } 45 private bool HasFixedScaleParameter { 46 get { return ScaleParameter.Value != null; } 47 } 42 48 43 49 [StorableConstructor] … … 61 67 public int GetNumberOfParameters(int numberOfVariables) { 62 68 return 63 ( ScaleParameter.Value != null? 0 : 1) +64 ( InverseLengthParameter.Value != null? 0 : numberOfVariables);69 (HasFixedScaleParameter ? 0 : 1) + 70 (HasFixedInverseLengthParameter ? 0 : numberOfVariables); 65 71 } 66 72 … … 76 82 int c = 0; 77 83 // gather parameter values 78 if ( InverseLengthParameter.Value != null) {84 if (HasFixedInverseLengthParameter) { 79 85 inverseLength = InverseLengthParameter.Value.ToArray(); 80 86 } else { 81 87 int length = p.Length; 82 if ( ScaleParameter.Value == null) length--;88 if (HasFixedScaleParameter) length--; 83 89 inverseLength = p.Select(e => 1.0 / Math.Exp(e)).Take(length).ToArray(); 84 90 c += inverseLength.Length; 85 91 } 86 if ( ScaleParameter.Value != null) {92 if (HasFixedScaleParameter) { 87 93 scale = ScaleParameter.Value.Value; 88 94 } else { … … 97 103 double[] inverseLength; 98 104 GetParameterValues(p, out scale, out inverseLength); 105 var fixedInverseLength = HasFixedInverseLengthParameter; 106 var fixedScale = HasFixedScaleParameter; 99 107 // create functions 100 108 var cov = new ParameterizedCovarianceFunction(); … … 109 117 return scale * Math.Exp(-d / 2.0); 110 118 }; 111 cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, columnIndices, scale, inverseLength );119 cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, columnIndices, scale, inverseLength, fixedInverseLength, fixedScale); 112 120 return cov; 113 121 } 114 122 115 123 // order of returned gradients must match the order in GetParameterValues! 116 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, IEnumerable<int> columnIndices, double scale, double[] inverseLength, 125 bool fixedInverseLength, bool fixedScale) { 117 126 double d = i == j 118 127 ? 0.0 … … 120 129 121 130 int k = 0; 122 foreach (var columnIndex in columnIndices) { 123 double sqrDist = Util.SqrDist(x[i, columnIndex] * inverseLength[k], x[j, columnIndex] * inverseLength[k]); 124 yield return scale * Math.Exp(-d / 2.0) * sqrDist; 125 k++; 131 if (!fixedInverseLength) { 132 foreach (var columnIndex in columnIndices) { 133 double sqrDist = Util.SqrDist(x[i, columnIndex] * inverseLength[k], x[j, columnIndex] * inverseLength[k]); 134 yield return scale * Math.Exp(-d / 2.0) * sqrDist; 135 k++; 136 } 126 137 } 127 yield return 2.0 * scale * Math.Exp(-d / 2.0);138 if (!fixedScale) yield return 2.0 * scale * Math.Exp(-d / 2.0); 128 139 } 129 140 }
Note: See TracChangeset
for help on using the changeset viewer.