Changeset 8612 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovariancePeriodic.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/CovariancePeriodic.cs
r8582 r8612 31 31 [StorableClass] 32 32 [Item(Name = "CovariancePeriodic", Description = "Periodic covariance function for Gaussian processes.")] 33 public class CovariancePeriodic : CovarianceFunction { 33 public sealed class CovariancePeriodic : ParameterizedNamedItem, ICovarianceFunction { 34 35 [Storable] 36 private double scale; 37 [Storable] 38 private readonly HyperParameter<DoubleValue> scaleParameter; 34 39 public IValueParameter<DoubleValue> ScaleParameter { 35 40 get { return scaleParameter; } 36 41 } 42 43 [Storable] 44 private double inverseLength; 45 [Storable] 46 private readonly HyperParameter<DoubleValue> inverseLengthParameter; 37 47 public IValueParameter<DoubleValue> InverseLengthParameter { 38 48 get { return inverseLengthParameter; } 39 49 } 50 51 [Storable] 52 private double period; 53 [Storable] 54 private readonly HyperParameter<DoubleValue> periodParameter; 40 55 public IValueParameter<DoubleValue> PeriodParameter { 41 56 get { return periodParameter; } 42 57 } 43 58 44 [Storable]45 private HyperParameter<DoubleValue> scaleParameter;46 [Storable]47 private HyperParameter<DoubleValue> inverseLengthParameter;48 [Storable]49 private HyperParameter<DoubleValue> periodParameter;50 51 [Storable]52 private double scale;53 [Storable]54 private double inverseLength;55 [Storable]56 private double period;57 58 59 59 60 [StorableConstructor] 60 pr otectedCovariancePeriodic(bool deserializing) : base(deserializing) { }61 pr otectedCovariancePeriodic(CovariancePeriodic original, Cloner cloner)61 private CovariancePeriodic(bool deserializing) : base(deserializing) { } 62 private CovariancePeriodic(CovariancePeriodic original, Cloner cloner) 62 63 : base(original, cloner) { 63 64 this.scaleParameter = cloner.Clone(original.scaleParameter); … … 73 74 public CovariancePeriodic() 74 75 : base() { 76 Name = ItemName; 77 Description = ItemDescription; 78 75 79 scaleParameter = new HyperParameter<DoubleValue>("Scale", "The scale of the periodic covariance function."); 76 80 inverseLengthParameter = new HyperParameter<DoubleValue>("InverseLength", "The inverse length parameter for the periodic covariance function."); … … 94 98 // caching 95 99 private void RegisterEvents() { 96 AttachValueChangeHandler<DoubleValue, double>(scaleParameter, () => { scale = scaleParameter.Value.Value; });97 AttachValueChangeHandler<DoubleValue, double>(inverseLengthParameter, () => { inverseLength = inverseLengthParameter.Value.Value; });98 AttachValueChangeHandler<DoubleValue, double>(periodParameter, () => { period = periodParameter.Value.Value; });100 Util.AttachValueChangeHandler<DoubleValue, double>(scaleParameter, () => { scale = scaleParameter.Value.Value; }); 101 Util.AttachValueChangeHandler<DoubleValue, double>(inverseLengthParameter, () => { inverseLength = inverseLengthParameter.Value.Value; }); 102 Util.AttachValueChangeHandler<DoubleValue, double>(periodParameter, () => { period = periodParameter.Value.Value; }); 99 103 } 100 104 101 public overrideint GetNumberOfParameters(int numberOfVariables) {105 public int GetNumberOfParameters(int numberOfVariables) { 102 106 return 103 107 (new[] { scaleParameter, inverseLengthParameter, periodParameter }).Count(p => !p.Fixed); 104 108 } 105 109 106 public overridevoid SetParameter(double[] hyp) {110 public void SetParameter(double[] hyp) { 107 111 int i = 0; 108 112 if (!inverseLengthParameter.Fixed) { … … 121 125 } 122 126 123 public overridedouble GetCovariance(double[,] x, int i, int j) {127 public double GetCovariance(double[,] x, int i, int j) { 124 128 double k = i == j ? 0.0 : GetDistance(x, x, i, j); 125 129 k = Math.PI * k / period; … … 130 134 } 131 135 132 public overrideIEnumerable<double> GetGradient(double[,] x, int i, int j) {136 public IEnumerable<double> GetGradient(double[,] x, int i, int j) { 133 137 double v = i == j ? 0.0 : Math.PI * GetDistance(x, x, i, j) / period; 134 138 double gradient = Math.Sin(v) * inverseLength; … … 140 144 } 141 145 142 public overridedouble GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {146 public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) { 143 147 double k = GetDistance(x, xt, i, j); 144 148 k = Math.PI * k / period;
Note: See TracChangeset
for help on using the changeset viewer.