Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/06/12 15:02:34 (12 years ago)
Author:
gkronber
Message:

#1902 worked on sum and product covariance functions and fixed a few bugs.

File:
1 edited

Legend:

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

    r8401 r8416  
    5050    protected CovarianceSEiso(CovarianceSEiso original, Cloner cloner)
    5151      : base(original, cloner) {
    52       // note: using shallow copies here
    53       this.x = original.x;
    54       this.xt = original.xt;
     52      if (original.x != null) {
     53        this.x = new double[original.x.GetLength(0), original.x.GetLength(1)];
     54        Array.Copy(original.x, this.x, x.Length);
     55
     56        this.xt = new double[original.xt.GetLength(0), original.xt.GetLength(1)];
     57        Array.Copy(original.xt, this.xt, xt.Length);
     58
     59        this.sd = new double[original.sd.GetLength(0), original.sd.GetLength(1)];
     60        Array.Copy(original.sd, this.sd, sd.Length);
     61        this.sf2 = original.sf2;
     62      }
    5563      this.sf2 = original.sf2;
    5664      this.l = original.l;
     
    7078    }
    7179
    72     public void SetParameter(double[] hyp, double[,] x) {
    73       SetParameter(hyp, x, x);
     80    public void SetParameter(double[] hyp) {
     81      this.l = Math.Exp(hyp[0]);
     82      this.sf2 = Math.Min(1E6, Math.Exp(2 * hyp[1])); // upper limit for scale
     83      sd = null;
     84    }
     85    public void SetData(double[,] x) {
     86      SetData(x, x);
    7487      this.symmetric = true;
    7588    }
    7689
    7790
    78     public void SetParameter(double[] hyp, double[,] x, double[,] xt) {
    79       this.l = Math.Exp(hyp[0]);
    80       this.sf2 = Math.Exp(2 * hyp[1]);
    81 
     91    public void SetData(double[,] x, double[,] xt) {
    8292      this.symmetric = false;
    8393      this.x = x;
     
    90100      return sf2 * Math.Exp(-sd[i, j] / 2.0);
    91101    }
    92 
    93 
    94     public double[] GetDiagonalCovariances() {
    95       if (x != xt) throw new InvalidOperationException();
    96       int rows = x.GetLength(0);
    97       var sd = new double[rows];
    98       for (int i = 0; i < rows; i++) {
    99         sd[i] = Util.SqrDist(Util.GetRow(x, i).Select(e => e / l), Util.GetRow(xt, i).Select(e => e / l));
    100       }
    101       return sd.Select(d => sf2 * Math.Exp(-d / 2.0)).ToArray();
    102     }
    103 
    104102
    105103    public double[] GetGradient(int i, int j) {
Note: See TracChangeset for help on using the changeset viewer.