Changeset 11202 for branches/HiveStatistics/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceRationalQuadraticArd.cs
- Timestamp:
- 07/18/14 12:01:13 (10 years ago)
- Location:
- branches/HiveStatistics/sources
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources
- Property svn:ignore
-
old new 8 8 FxCopResults.txt 9 9 Google.ProtocolBuffers-0.9.1.dll 10 Google.ProtocolBuffers-2.4.1.473.dll 10 11 HeuristicLab 3.3.5.1.ReSharper.user 11 12 HeuristicLab 3.3.6.0.ReSharper.user 12 13 HeuristicLab.4.5.resharper.user 13 14 HeuristicLab.ExtLibs.6.0.ReSharper.user 15 HeuristicLab.Scripting.Development 14 16 HeuristicLab.resharper.user 15 17 ProtoGen.exe … … 17 19 _ReSharper.HeuristicLab 18 20 _ReSharper.HeuristicLab 3.3 21 _ReSharper.HeuristicLab 3.3 Tests 19 22 _ReSharper.HeuristicLab.ExtLibs 20 23 bin 21 24 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests23 Google.ProtocolBuffers-2.4.1.473.dll
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/HiveStatistics/sources/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
-
branches/HiveStatistics/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceRationalQuadraticArd.cs
r9357 r11202 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 45 45 get { return (IValueParameter<DoubleValue>)Parameters["Shape"]; } 46 46 } 47 private bool HasFixedScaleParameter { 48 get { return ScaleParameter.Value != null; } 49 } 50 private bool HasFixedInverseLengthParameter { 51 get { return InverseLengthParameter.Value != null; } 52 } 53 private bool HasFixedShapeParameter { 54 get { return ShapeParameter.Value != null; } 55 } 47 56 48 57 [StorableConstructor] … … 71 80 public int GetNumberOfParameters(int numberOfVariables) { 72 81 return 73 ( ScaleParameter.Value != null? 0 : 1) +74 ( ShapeParameter.Value != null? 0 : 1) +75 ( InverseLengthParameter.Value != null? 0 : numberOfVariables);82 (HasFixedScaleParameter ? 0 : 1) + 83 (HasFixedShapeParameter ? 0 : 1) + 84 (HasFixedInverseLengthParameter ? 0 : numberOfVariables); 76 85 } 77 86 … … 88 97 int c = 0; 89 98 // gather parameter values 90 if ( InverseLengthParameter.Value != null) {99 if (HasFixedInverseLengthParameter) { 91 100 inverseLength = InverseLengthParameter.Value.ToArray(); 92 101 } else { 93 102 int length = p.Length; 94 if ( ScaleParameter.Value == null) length--;95 if ( ShapeParameter.Value == null) length--;103 if (!HasFixedScaleParameter) length--; 104 if (!HasFixedShapeParameter) length--; 96 105 inverseLength = p.Select(e => 1.0 / Math.Exp(e)).Take(length).ToArray(); 97 106 c += inverseLength.Length; 98 107 } 99 if ( ScaleParameter.Value != null) {108 if (HasFixedScaleParameter) { 100 109 scale = ScaleParameter.Value.Value; 101 110 } else { … … 103 112 c++; 104 113 } 105 if ( ShapeParameter.Value != null) {114 if (HasFixedShapeParameter) { 106 115 shape = ShapeParameter.Value.Value; 107 116 } else { … … 116 125 double[] inverseLength; 117 126 GetParameterValues(p, out scale, out shape, out inverseLength); 127 var fixedInverseLength = HasFixedInverseLengthParameter; 128 var fixedScale = HasFixedScaleParameter; 129 var fixedShape = HasFixedShapeParameter; 118 130 // create functions 119 131 var cov = new ParameterizedCovarianceFunction(); … … 128 140 return scale * Math.Pow(1 + 0.5 * d / shape, -shape); 129 141 }; 130 cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, columnIndices, scale, shape, inverseLength );142 cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, columnIndices, scale, shape, inverseLength, fixedInverseLength, fixedScale, fixedShape); 131 143 return cov; 132 144 } 133 145 134 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, IEnumerable<int> columnIndices, double scale, double shape, double[] inverseLength, 147 bool fixedInverseLength, bool fixedScale, bool fixedShape) { 135 148 double d = i == j 136 149 ? 0.0 … … 138 151 double b = 1 + 0.5 * d / shape; 139 152 int k = 0; 140 foreach (var columnIndex in columnIndices) { 141 yield return scale * Math.Pow(b, -shape - 1) * Util.SqrDist(x[i, columnIndex] * inverseLength[k], x[j, columnIndex] * inverseLength[k]); 142 k++; 153 if (!fixedInverseLength) { 154 foreach (var columnIndex in columnIndices) { 155 yield return 156 scale * Math.Pow(b, -shape - 1) * 157 Util.SqrDist(x[i, columnIndex] * inverseLength[k], x[j, columnIndex] * inverseLength[k]); 158 k++; 159 } 143 160 } 144 yield return 2 * scale * Math.Pow(b, -shape);145 yield return scale * Math.Pow(b, -shape) * (0.5 * d / b - shape * Math.Log(b));161 if (!fixedScale) yield return 2 * scale * Math.Pow(b, -shape); 162 if (!fixedShape) yield return scale * Math.Pow(b, -shape) * (0.5 * d / b - shape * Math.Log(b)); 146 163 } 147 164 }
Note: See TracChangeset
for help on using the changeset viewer.