Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/05/12 11:58:17 (12 years ago)
Author:
mkommend
Message:

#1081: Merged trunk changes and fixed compilation errors due to the merge.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceNoise.cs

    r8477 r8742  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     26using HeuristicLab.Data;
    2527using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2628
     
    2931  [Item(Name = "CovarianceNoise",
    3032    Description = "Noise covariance function for Gaussian processes.")]
    31   public class CovarianceNoise : Item, ICovarianceFunction {
     33  public sealed class CovarianceNoise : ParameterizedNamedItem, ICovarianceFunction {
     34
     35
    3236    [Storable]
    3337    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    }
    3543
    3644    [StorableConstructor]
    37     protected CovarianceNoise(bool deserializing)
     45    private CovarianceNoise(bool deserializing)
    3846      : base(deserializing) {
    3947    }
    4048
    41     protected CovarianceNoise(CovarianceNoise original, Cloner cloner)
     49    private CovarianceNoise(CovarianceNoise original, Cloner cloner)
    4250      : base(original, cloner) {
     51      this.scaleParameter = cloner.Clone(original.scaleParameter);
    4352      this.sf2 = original.sf2;
     53      RegisterEvents();
    4454    }
    4555
    4656    public CovarianceNoise()
    4757      : 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();
    4865    }
    4966
     
    5269    }
    5370
     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
    5480    public int GetNumberOfParameters(int numberOfVariables) {
    55       return 1;
     81      return scaleParameter.Fixed ? 0 : 1;
    5682    }
    5783
    5884    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      }
    6390    }
    6491
    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;
    6894    }
    6995
    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;
    7398    }
    7499
    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;
    81102    }
    82103  }
Note: See TracChangeset for help on using the changeset viewer.