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/CovarianceLinearArd.cs

    r8582 r8612  
    3232  [Item(Name = "CovarianceLinearArd",
    3333    Description = "Linear covariance function with automatic relevance determination for Gaussian processes.")]
    34   public class CovarianceLinearArd : CovarianceFunction {
     34  public sealed class CovarianceLinearArd : ParameterizedNamedItem, ICovarianceFunction {
     35    [Storable]
     36    private double[] inverseLength;
     37    [Storable]
     38    private readonly HyperParameter<DoubleArray> inverseLengthParameter;
    3539    public IValueParameter<DoubleArray> InverseLengthParameter {
    3640      get { return inverseLengthParameter; }
    3741    }
    3842
    39     [Storable]
    40     private HyperParameter<DoubleArray> inverseLengthParameter;
    41 
    42     [Storable]
    43     private double[] inverseLength;
    44 
    4543    [StorableConstructor]
    46     protected CovarianceLinearArd(bool deserializing) : base(deserializing) { }
    47     protected CovarianceLinearArd(CovarianceLinearArd original, Cloner cloner)
     44    private CovarianceLinearArd(bool deserializing) : base(deserializing) { }
     45    private CovarianceLinearArd(CovarianceLinearArd original, Cloner cloner)
    4846      : base(original, cloner) {
    4947      inverseLengthParameter = cloner.Clone(original.inverseLengthParameter);
     
    5755    public CovarianceLinearArd()
    5856      : base() {
     57      Name = ItemName;
     58      Description = ItemDescription;
     59
    5960      inverseLengthParameter = new HyperParameter<DoubleArray>("InverseLength",
    6061                                                               "The inverse length parameter for ARD.");
     
    7475    // caching
    7576    private void RegisterEvents() {
    76       AttachArrayChangeHandler<DoubleArray, double>(inverseLengthParameter, () => { inverseLength = inverseLengthParameter.Value.ToArray(); });
     77      Util.AttachArrayChangeHandler<DoubleArray, double>(inverseLengthParameter, () => { inverseLength = inverseLengthParameter.Value.ToArray(); });
    7778    }
    7879
    7980
    80     public override int GetNumberOfParameters(int numberOfVariables) {
     81    public int GetNumberOfParameters(int numberOfVariables) {
    8182      if (!inverseLengthParameter.Fixed)
    8283        return numberOfVariables;
     
    8586    }
    8687
    87     public override void SetParameter(double[] hyp) {
     88    public void SetParameter(double[] hyp) {
    8889      if (!inverseLengthParameter.Fixed && hyp.Length > 0) {
    8990        inverseLengthParameter.SetValue(new DoubleArray(hyp.Select(e => 1.0 / Math.Exp(e)).ToArray()));
     
    9192    }
    9293
    93     public override double GetCovariance(double[,] x, int i, int j) {
     94    public double GetCovariance(double[,] x, int i, int j) {
    9495      return Util.ScalarProd(x, i, j, inverseLength);
    9596    }
    9697
    97     public override IEnumerable<double> GetGradient(double[,] x, int i, int j) {
     98    public IEnumerable<double> GetGradient(double[,] x, int i, int j) {
    9899      for (int k = 0; k < inverseLength.Length; k++) {
    99100        yield return -2.0 * x[i, k] * x[j, k] * inverseLength[k] * inverseLength[k];
     
    101102    }
    102103
    103     public override double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {
     104    public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {
    104105      return Util.ScalarProd(x, i, xt, j, inverseLength);
    105106    }
Note: See TracChangeset for help on using the changeset viewer.