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

    r8484 r8491  
    3434    public double Scale { get { return sf2; } }
    3535    [Storable]
    36     private double l;
    37     public double Length { get { return l; } }
     36    private double inverseLength;
     37    public double InverseLength { get { return inverseLength; } }
    3838    [Storable]
    3939    private double p;
     
    4848      : base(original, cloner) {
    4949      sf2 = original.sf2;
    50       l = original.l;
     50      inverseLength = original.inverseLength;
    5151      p = original.p;
    5252    }
     
    6161    public void SetParameter(double[] hyp) {
    6262      if (hyp.Length != 3) throw new ArgumentException();
    63       this.l = Math.Exp(hyp[0]);
     63      this.inverseLength = 1.0 / Math.Exp(hyp[0]);
    6464      this.p = Math.Exp(hyp[1]);
    6565      this.sf2 = Math.Exp(2 * hyp[2]);
     
    6969      double k = i == j ? 0.0 : GetDistance(x, x, i, j);
    7070      k = Math.PI * k / p;
    71       k = Math.Sin(k) / l;
     71      k = Math.Sin(k) * inverseLength;
    7272      k = k * k;
    7373
     
    7777    public IEnumerable<double> GetGradient(double[,] x, int i, int j) {
    7878      double v = i == j ? 0.0 : Math.PI * GetDistance(x, x, i, j) / p;
    79       double gradient = Math.Sin(v) / l;
     79      double gradient = Math.Sin(v) * inverseLength;
    8080      gradient *= gradient;
    8181      yield return 4.0 * sf2 * Math.Exp(-2.0 * gradient) * gradient;
    82       double r = Math.Sin(v) / l;
    83       yield return 4.0 * sf2 / l * Math.Exp(-2 * r * r) * r * Math.Cos(v) * v;
     82      double r = Math.Sin(v) * inverseLength;
     83      yield return 4.0 * sf2 * inverseLength * Math.Exp(-2 * r * r) * r * Math.Cos(v) * v;
    8484      yield return 2.0 * sf2 * Math.Exp(-2 * gradient);
    8585    }
     
    8888      double k = GetDistance(x, xt, i, j);
    8989      k = Math.PI * k / p;
    90       k = Math.Sin(k) / l;
     90      k = Math.Sin(k) * inverseLength;
    9191      k = k * k;
    9292
     
    9595
    9696    private double GetDistance(double[,] x, double[,] xt, int i, int j) {
    97       return Math.Sqrt(Util.SqrDist(Util.GetRow(x, i), Util.GetRow(xt, j)));
     97      return Math.Sqrt(Util.SqrDist(x, i, xt, j));
    9898    }
    9999  }
Note: See TracChangeset for help on using the changeset viewer.