Changeset 8742 for branches/HeuristicLab.TimeSeries/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/MeanConst.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/MeanConst.cs
r8477 r8742 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Data; 26 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 28 … … 29 30 [StorableClass] 30 31 [Item(Name = "MeanConst", Description = "Constant mean function for Gaussian processes.")] 31 public class MeanConst :Item, IMeanFunction {32 public sealed class MeanConst : ParameterizedNamedItem, IMeanFunction { 32 33 [Storable] 33 34 private double c; 34 public double Value { get { return c; } } 35 [Storable] 36 private readonly HyperParameter<DoubleValue> valueParameter; 37 public IValueParameter<DoubleValue> ValueParameter { get { return valueParameter; } } 35 38 36 public int GetNumberOfParameters(int numberOfVariables) {37 return 1;38 }39 39 [StorableConstructor] 40 pr otectedMeanConst(bool deserializing) : base(deserializing) { }41 pr otectedMeanConst(MeanConst original, Cloner cloner)40 private MeanConst(bool deserializing) : base(deserializing) { } 41 private MeanConst(MeanConst original, Cloner cloner) 42 42 : base(original, cloner) { 43 43 this.c = original.c; 44 this.valueParameter = cloner.Clone(original.valueParameter); 45 RegisterEvents(); 44 46 } 45 47 public MeanConst() 46 48 : base() { 49 this.name = ItemName; 50 this.description = ItemDescription; 51 52 this.valueParameter = new HyperParameter<DoubleValue>("Value", "The constant value for the constant mean function."); 53 Parameters.Add(valueParameter); 54 RegisterEvents(); 55 } 56 57 public override IDeepCloneable Clone(Cloner cloner) { 58 return new MeanConst(this, cloner); 59 } 60 61 [StorableHook(HookType.AfterDeserialization)] 62 private void AfterDeserialization() { 63 RegisterEvents(); 64 } 65 66 private void RegisterEvents() { 67 Util.AttachValueChangeHandler<DoubleValue, double>(valueParameter, () => { c = valueParameter.Value.Value; }); 68 } 69 70 public int GetNumberOfParameters(int numberOfVariables) { 71 return valueParameter.Fixed ? 0 : 1; 47 72 } 48 73 49 74 public void SetParameter(double[] hyp) { 50 if (hyp.Length != 1) throw new ArgumentException("Only one hyper-parameter allowed for constant mean function.", "hyp"); 51 this.c = hyp[0]; 52 } 53 public void SetData(double[,] x) { 54 // nothing to do 75 if (!valueParameter.Fixed) { 76 valueParameter.SetValue(new DoubleValue(hyp[0])); 77 } else if (hyp.Length > 0) 78 throw new ArgumentException("The length of the parameter vector does not match the number of free parameters for the constant mean function.", "hyp"); 55 79 } 56 80 … … 63 87 return Enumerable.Repeat(1.0, x.GetLength(0)).ToArray(); 64 88 } 65 66 public override IDeepCloneable Clone(Cloner cloner) {67 return new MeanConst(this, cloner);68 }69 89 } 70 90 }
Note: See TracChangeset
for help on using the changeset viewer.