Changeset 10489 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovariancePiecewisePolynomial.cs
- Timestamp:
- 02/20/14 17:45:06 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovariancePiecewisePolynomial.cs
r9543 r10489 45 45 get { return (IConstrainedValueParameter<IntValue>)Parameters["V"]; } 46 46 } 47 private bool HasFixedLengthParameter { 48 get { return LengthParameter.Value != null; } 49 } 50 private bool HasFixedScaleParameter { 51 get { return ScaleParameter.Value != null; } 52 } 47 53 48 54 [StorableConstructor] … … 77 83 public int GetNumberOfParameters(int numberOfVariables) { 78 84 return 79 ( LengthParameter.Value != null? 0 : 1) +80 ( ScaleParameter.Value != null? 0 : 1);85 (HasFixedLengthParameter ? 0 : 1) + 86 (HasFixedScaleParameter ? 0 : 1); 81 87 } 82 88 … … 91 97 // gather parameter values 92 98 int n = 0; 93 if ( LengthParameter.Value != null) {99 if (HasFixedLengthParameter) { 94 100 length = LengthParameter.Value.Value; 95 101 } else { … … 98 104 } 99 105 100 if ( ScaleParameter.Value != null) {106 if (HasFixedScaleParameter) { 101 107 scale = ScaleParameter.Value.Value; 102 108 } else { … … 111 117 int v = VParameter.Value.Value; 112 118 GetParameterValues(p, out length, out scale); 119 var fixedLength = HasFixedLengthParameter; 120 var fixedScale = HasFixedScaleParameter; 113 121 int exp = (int)Math.Floor(columnIndices.Count() / 2.0) + v + 1; 114 122 … … 147 155 return scale * Math.Pow(Math.Max(1 - k, 0), exp + v) * f(k); 148 156 }; 149 cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, length, scale, v, exp, f, df, columnIndices );157 cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, length, scale, v, exp, f, df, columnIndices, fixedLength, fixedScale); 150 158 return cov; 151 159 } 152 160 153 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, IEnumerable<int> columnIndices, 162 bool fixedLength, bool fixedScale) { 154 163 double k = Math.Sqrt(Util.SqrDist(x, i, x, j, 1.0 / length, columnIndices)); 155 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));156 yield return 2.0 * scale * Math.Pow(Math.Max(1 - k, 0), exp + v) * f(k);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 if (!fixedScale) yield return 2.0 * scale * Math.Pow(Math.Max(1 - k, 0), exp + v) * f(k); 157 166 } 158 167 }
Note: See TracChangeset
for help on using the changeset viewer.