Changeset 8742 for branches/HeuristicLab.TimeSeries/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceNoise.cs
- Timestamp:
- 10/05/12 11:58:17 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TimeSeries/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceNoise.cs
r8477 r8742 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; 26 using HeuristicLab.Data; 25 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 28 … … 29 31 [Item(Name = "CovarianceNoise", 30 32 Description = "Noise covariance function for Gaussian processes.")] 31 public class CovarianceNoise : Item, ICovarianceFunction { 33 public sealed class CovarianceNoise : ParameterizedNamedItem, ICovarianceFunction { 34 35 32 36 [Storable] 33 37 private double sf2; 34 public double Scale { get { return sf2; } } 38 [Storable] 39 private readonly HyperParameter<DoubleValue> scaleParameter; 40 public IValueParameter<DoubleValue> ScaleParameter { 41 get { return scaleParameter; } 42 } 35 43 36 44 [StorableConstructor] 37 pr otectedCovarianceNoise(bool deserializing)45 private CovarianceNoise(bool deserializing) 38 46 : base(deserializing) { 39 47 } 40 48 41 pr otectedCovarianceNoise(CovarianceNoise original, Cloner cloner)49 private CovarianceNoise(CovarianceNoise original, Cloner cloner) 42 50 : base(original, cloner) { 51 this.scaleParameter = cloner.Clone(original.scaleParameter); 43 52 this.sf2 = original.sf2; 53 RegisterEvents(); 44 54 } 45 55 46 56 public CovarianceNoise() 47 57 : base() { 58 Name = ItemName; 59 Description = ItemDescription; 60 61 this.scaleParameter = new HyperParameter<DoubleValue>("Scale", "The scale of noise."); 62 Parameters.Add(this.scaleParameter); 63 64 RegisterEvents(); 48 65 } 49 66 … … 52 69 } 53 70 71 [StorableHook(HookType.AfterDeserialization)] 72 private void AfterDeserialization() { 73 RegisterEvents(); 74 } 75 76 private void RegisterEvents() { 77 Util.AttachValueChangeHandler<DoubleValue, double>(scaleParameter, () => { sf2 = scaleParameter.Value.Value; }); 78 } 79 54 80 public int GetNumberOfParameters(int numberOfVariables) { 55 return 1;81 return scaleParameter.Fixed ? 0 : 1; 56 82 } 57 83 58 84 public void SetParameter(double[] hyp) { 59 this.sf2 = Math.Exp(2 * hyp[0]); 60 } 61 public void SetData(double[,] x) { 62 // nothing to do 85 if (!scaleParameter.Fixed) { 86 scaleParameter.SetValue(new DoubleValue(Math.Exp(2 * hyp[0]))); 87 } else { 88 if (hyp.Length > 0) throw new ArgumentException("The length of the parameter vector does not match the number of free parameters for CovarianceNoise", "hyp"); 89 } 63 90 } 64 91 65 66 public void SetData(double[,] x, double[,] xt) { 67 // nothing to do 92 public double GetCovariance(double[,] x, int i, int j, IEnumerable<int> columnIndices) { 93 return sf2; 68 94 } 69 95 70 public double GetCovariance(int i, int j) { 71 if (i == j) return sf2; 72 else return 0.0; 96 public IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices) { 97 yield return 2 * sf2; 73 98 } 74 99 75 public double GetGradient(int i, int j, int k) { 76 if (k != 0) throw new ArgumentException("CovarianceConst has only one hyperparameters", "k"); 77 if (i == j) 78 return 2 * sf2; 79 else 80 return 0.0; 100 public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j, IEnumerable<int> columnIndices) { 101 return 0.0; 81 102 } 82 103 }
Note: See TracChangeset
for help on using the changeset viewer.