Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/14/12 17:10:08 (12 years ago)
Author:
gkronber
Message:

#1902 fixed test cases, improved performance

File:
1 edited

Legend:

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

    r8484 r8491  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Core;
     
    3635    public double Scale { get { return sf2; } }
    3736    [Storable]
    38     private double l;
    39     public double Length { get { return l; } }
     37    private double inverseLength;
     38    public double InverseLength { get { return inverseLength; } }
    4039    [Storable]
    4140    private double alpha;
     
    5049      : base(original, cloner) {
    5150      this.sf2 = original.sf2;
    52       this.l = original.l;
     51      this.inverseLength = original.inverseLength;
    5352      this.alpha = original.alpha;
    5453    }
     
    6867    public void SetParameter(double[] hyp) {
    6968      if (hyp.Length != 3) throw new ArgumentException("CovarianceRQiso has three hyperparameters", "k");
    70       this.l = Math.Exp(hyp[0]);
     69      this.inverseLength = 1.0 / Math.Exp(hyp[0]);
    7170      this.sf2 = Math.Exp(2 * hyp[1]);
    7271      this.alpha = Math.Exp(hyp[2]);
     
    7574
    7675    public double GetCovariance(double[,] x, int i, int j) {
    77       double lInv = 1.0 / l;
    7876      double d = i == j
    7977                   ? 0.0
    80                    : Util.SqrDist(Util.GetRow(x, i).Select(e => e * lInv), Util.GetRow(x, j).Select(e => e * lInv));
     78                   : Util.SqrDist(x, i, j, inverseLength);
    8179      return sf2 * Math.Pow(1 + 0.5 * d / alpha, -alpha);
    8280    }
    8381
    8482    public IEnumerable<double> GetGradient(double[,] x, int i, int j) {
    85       double lInv = 1.0 / l;
    8683      double d = i == j
    8784                   ? 0.0
    88                    : Util.SqrDist(Util.GetRow(x, i).Select(e => e * lInv), Util.GetRow(x, j).Select(e => e * lInv));
     85                   : Util.SqrDist(x, i, j, inverseLength);
    8986
    9087      double b = 1 + 0.5 * d / alpha;
     
    9592
    9693    public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {
    97       double lInv = 1.0 / l;
    98       double d = Util.SqrDist(Util.GetRow(x, i).Select(e => e * lInv), Util.GetRow(xt, j).Select(e => e * lInv));
     94      double d = Util.SqrDist(x, i, xt, j, inverseLength);
    9995      return sf2 * Math.Pow(1 + 0.5 * d / alpha, -alpha);
    10096    }
Note: See TracChangeset for help on using the changeset viewer.