Changeset 8491 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceRQiso.cs
- Timestamp:
- 08/14/12 17:10:08 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceRQiso.cs
r8484 r8491 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq;25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Core; … … 36 35 public double Scale { get { return sf2; } } 37 36 [Storable] 38 private double l;39 public double Length { get { return l; } }37 private double inverseLength; 38 public double InverseLength { get { return inverseLength; } } 40 39 [Storable] 41 40 private double alpha; … … 50 49 : base(original, cloner) { 51 50 this.sf2 = original.sf2; 52 this. l = original.l;51 this.inverseLength = original.inverseLength; 53 52 this.alpha = original.alpha; 54 53 } … … 68 67 public void SetParameter(double[] hyp) { 69 68 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]); 71 70 this.sf2 = Math.Exp(2 * hyp[1]); 72 71 this.alpha = Math.Exp(hyp[2]); … … 75 74 76 75 public double GetCovariance(double[,] x, int i, int j) { 77 double lInv = 1.0 / l;78 76 double d = i == j 79 77 ? 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); 81 79 return sf2 * Math.Pow(1 + 0.5 * d / alpha, -alpha); 82 80 } 83 81 84 82 public IEnumerable<double> GetGradient(double[,] x, int i, int j) { 85 double lInv = 1.0 / l;86 83 double d = i == j 87 84 ? 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); 89 86 90 87 double b = 1 + 0.5 * d / alpha; … … 95 92 96 93 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); 99 95 return sf2 * Math.Pow(1 + 0.5 * d / alpha, -alpha); 100 96 }
Note: See TracChangeset
for help on using the changeset viewer.