Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/10/12 13:28:55 (12 years ago)
Author:
gkronber
Message:

#1902 implemented all mean and covariance functions with parameters as ParameterizedNamedItems

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovariancePeriodic.cs

    r8582 r8612  
    3131  [StorableClass]
    3232  [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;
    3439    public IValueParameter<DoubleValue> ScaleParameter {
    3540      get { return scaleParameter; }
    3641    }
     42
     43    [Storable]
     44    private double inverseLength;
     45    [Storable]
     46    private readonly HyperParameter<DoubleValue> inverseLengthParameter;
    3747    public IValueParameter<DoubleValue> InverseLengthParameter {
    3848      get { return inverseLengthParameter; }
    3949    }
     50
     51    [Storable]
     52    private double period;
     53    [Storable]
     54    private readonly HyperParameter<DoubleValue> periodParameter;
    4055    public IValueParameter<DoubleValue> PeriodParameter {
    4156      get { return periodParameter; }
    4257    }
    4358
    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 
    5859
    5960    [StorableConstructor]
    60     protected CovariancePeriodic(bool deserializing) : base(deserializing) { }
    61     protected CovariancePeriodic(CovariancePeriodic original, Cloner cloner)
     61    private CovariancePeriodic(bool deserializing) : base(deserializing) { }
     62    private CovariancePeriodic(CovariancePeriodic original, Cloner cloner)
    6263      : base(original, cloner) {
    6364      this.scaleParameter = cloner.Clone(original.scaleParameter);
     
    7374    public CovariancePeriodic()
    7475      : base() {
     76      Name = ItemName;
     77      Description = ItemDescription;
     78     
    7579      scaleParameter = new HyperParameter<DoubleValue>("Scale", "The scale of the periodic covariance function.");
    7680      inverseLengthParameter = new HyperParameter<DoubleValue>("InverseLength", "The inverse length parameter for the periodic covariance function.");
     
    9498    // caching
    9599    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; });
    99103    }
    100104
    101     public override int GetNumberOfParameters(int numberOfVariables) {
     105    public int GetNumberOfParameters(int numberOfVariables) {
    102106      return
    103107        (new[] { scaleParameter, inverseLengthParameter, periodParameter }).Count(p => !p.Fixed);
    104108    }
    105109
    106     public override void SetParameter(double[] hyp) {
     110    public void SetParameter(double[] hyp) {
    107111      int i = 0;
    108112      if (!inverseLengthParameter.Fixed) {
     
    121125    }
    122126
    123     public override double GetCovariance(double[,] x, int i, int j) {
     127    public double GetCovariance(double[,] x, int i, int j) {
    124128      double k = i == j ? 0.0 : GetDistance(x, x, i, j);
    125129      k = Math.PI * k / period;
     
    130134    }
    131135
    132     public override IEnumerable<double> GetGradient(double[,] x, int i, int j) {
     136    public IEnumerable<double> GetGradient(double[,] x, int i, int j) {
    133137      double v = i == j ? 0.0 : Math.PI * GetDistance(x, x, i, j) / period;
    134138      double gradient = Math.Sin(v) * inverseLength;
     
    140144    }
    141145
    142     public override double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {
     146    public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {
    143147      double k = GetDistance(x, xt, i, j);
    144148      k = Math.PI * k / period;
Note: See TracChangeset for help on using the changeset viewer.