Changeset 8612 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceLinearArd.cs
- Timestamp:
- 09/10/12 13:28:55 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceLinearArd.cs
r8582 r8612 32 32 [Item(Name = "CovarianceLinearArd", 33 33 Description = "Linear covariance function with automatic relevance determination for Gaussian processes.")] 34 public class CovarianceLinearArd : CovarianceFunction { 34 public sealed class CovarianceLinearArd : ParameterizedNamedItem, ICovarianceFunction { 35 [Storable] 36 private double[] inverseLength; 37 [Storable] 38 private readonly HyperParameter<DoubleArray> inverseLengthParameter; 35 39 public IValueParameter<DoubleArray> InverseLengthParameter { 36 40 get { return inverseLengthParameter; } 37 41 } 38 42 39 [Storable]40 private HyperParameter<DoubleArray> inverseLengthParameter;41 42 [Storable]43 private double[] inverseLength;44 45 43 [StorableConstructor] 46 pr otectedCovarianceLinearArd(bool deserializing) : base(deserializing) { }47 pr otectedCovarianceLinearArd(CovarianceLinearArd original, Cloner cloner)44 private CovarianceLinearArd(bool deserializing) : base(deserializing) { } 45 private CovarianceLinearArd(CovarianceLinearArd original, Cloner cloner) 48 46 : base(original, cloner) { 49 47 inverseLengthParameter = cloner.Clone(original.inverseLengthParameter); … … 57 55 public CovarianceLinearArd() 58 56 : base() { 57 Name = ItemName; 58 Description = ItemDescription; 59 59 60 inverseLengthParameter = new HyperParameter<DoubleArray>("InverseLength", 60 61 "The inverse length parameter for ARD."); … … 74 75 // caching 75 76 private void RegisterEvents() { 76 AttachArrayChangeHandler<DoubleArray, double>(inverseLengthParameter, () => { inverseLength = inverseLengthParameter.Value.ToArray(); });77 Util.AttachArrayChangeHandler<DoubleArray, double>(inverseLengthParameter, () => { inverseLength = inverseLengthParameter.Value.ToArray(); }); 77 78 } 78 79 79 80 80 public overrideint GetNumberOfParameters(int numberOfVariables) {81 public int GetNumberOfParameters(int numberOfVariables) { 81 82 if (!inverseLengthParameter.Fixed) 82 83 return numberOfVariables; … … 85 86 } 86 87 87 public overridevoid SetParameter(double[] hyp) {88 public void SetParameter(double[] hyp) { 88 89 if (!inverseLengthParameter.Fixed && hyp.Length > 0) { 89 90 inverseLengthParameter.SetValue(new DoubleArray(hyp.Select(e => 1.0 / Math.Exp(e)).ToArray())); … … 91 92 } 92 93 93 public overridedouble GetCovariance(double[,] x, int i, int j) {94 public double GetCovariance(double[,] x, int i, int j) { 94 95 return Util.ScalarProd(x, i, j, inverseLength); 95 96 } 96 97 97 public overrideIEnumerable<double> GetGradient(double[,] x, int i, int j) {98 public IEnumerable<double> GetGradient(double[,] x, int i, int j) { 98 99 for (int k = 0; k < inverseLength.Length; k++) { 99 100 yield return -2.0 * x[i, k] * x[j, k] * inverseLength[k] * inverseLength[k]; … … 101 102 } 102 103 103 public overridedouble GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {104 public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) { 104 105 return Util.ScalarProd(x, i, xt, j, inverseLength); 105 106 }
Note: See TracChangeset
for help on using the changeset viewer.