Changeset 8612 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceNoise.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/CovarianceNoise.cs
r8484 r8612 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Data; 26 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 28 … … 30 31 [Item(Name = "CovarianceNoise", 31 32 Description = "Noise covariance function for Gaussian processes.")] 32 public class CovarianceNoise : Item, ICovarianceFunction { 33 public sealed class CovarianceNoise : ParameterizedNamedItem, ICovarianceFunction { 34 35 33 36 [Storable] 34 37 private double sf2; 35 public double Scale { get { return sf2; } } 38 [Storable] 39 private readonly HyperParameter<DoubleValue> scaleParameter; 40 public IValueParameter<DoubleValue> ScaleParameter { 41 get { return scaleParameter; } 42 } 36 43 37 44 [StorableConstructor] 38 pr otectedCovarianceNoise(bool deserializing)45 private CovarianceNoise(bool deserializing) 39 46 : base(deserializing) { 40 47 } 41 48 42 pr otectedCovarianceNoise(CovarianceNoise original, Cloner cloner)49 private CovarianceNoise(CovarianceNoise original, Cloner cloner) 43 50 : base(original, cloner) { 51 this.scaleParameter = cloner.Clone(original.scaleParameter); 44 52 this.sf2 = original.sf2; 53 RegisterEvents(); 45 54 } 46 55 47 56 public CovarianceNoise() 48 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(); 49 65 } 50 66 … … 53 69 } 54 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 55 80 public int GetNumberOfParameters(int numberOfVariables) { 56 return 1;81 return scaleParameter.Fixed ? 0 : 1; 57 82 } 58 83 59 84 public void SetParameter(double[] hyp) { 60 this.sf2 = Math.Exp(2 * hyp[0]); 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 } 61 90 } 62 91
Note: See TracChangeset
for help on using the changeset viewer.