Changeset 10553 for branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSquaredExponentialIso.cs
- Timestamp:
- 03/05/14 17:30:38 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSquaredExponentialIso.cs
r8982 r10553 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 42 42 } 43 43 44 private bool HasFixedInverseLengthParameter { 45 get { return InverseLengthParameter.Value != null; } 46 } 47 private bool HasFixedScaleParameter { 48 get { return ScaleParameter.Value != null; } 49 } 50 44 51 [StorableConstructor] 45 52 private CovarianceSquaredExponentialIso(bool deserializing) … … 66 73 public int GetNumberOfParameters(int numberOfVariables) { 67 74 return 68 ( ScaleParameter.Value != null? 0 : 1) +69 ( InverseLengthParameter.Value != null? 0 : 1);75 (HasFixedScaleParameter ? 0 : 1) + 76 (HasFixedInverseLengthParameter ? 0 : 1); 70 77 } 71 78 … … 81 88 // gather parameter values 82 89 int c = 0; 83 if ( InverseLengthParameter.Value != null) {90 if (HasFixedInverseLengthParameter) { 84 91 inverseLength = InverseLengthParameter.Value.Value; 85 92 } else { … … 88 95 } 89 96 90 if ( ScaleParameter.Value != null) {97 if (HasFixedScaleParameter) { 91 98 scale = ScaleParameter.Value.Value; 92 99 } else { … … 100 107 double inverseLength, scale; 101 108 GetParameterValues(p, out scale, out inverseLength); 109 var fixedInverseLength = HasFixedInverseLengthParameter; 110 var fixedScale = HasFixedScaleParameter; 102 111 // create functions 103 112 var cov = new ParameterizedCovarianceFunction(); … … 112 121 return scale * Math.Exp(-d / 2.0); 113 122 }; 114 cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, scale, inverseLength, columnIndices); 123 cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, scale, inverseLength, columnIndices, 124 fixedInverseLength, fixedScale); 115 125 return cov; 116 126 } 117 127 118 private static IEnumerable<double> GetGradient(double[,] x, int i, int j, double sf2, double inverseLength, IEnumerable<int> columnIndices) { 128 // 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, 130 bool fixedInverseLength, bool fixedScale) { 119 131 double d = i == j 120 132 ? 0.0 121 133 : Util.SqrDist(x, i, j, inverseLength, columnIndices); 122 134 double g = Math.Exp(-d / 2.0); 123 yield return sf2 * g * d;124 yield return 2.0 * sf2 * g;135 if (!fixedInverseLength) yield return sf2 * g * d; 136 if (!fixedScale) yield return 2.0 * sf2 * g; 125 137 } 126 138 }
Note: See TracChangeset
for help on using the changeset viewer.