Changeset 8416 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceSEiso.cs
- Timestamp:
- 08/06/12 15:02:34 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceSEiso.cs
r8401 r8416 50 50 protected CovarianceSEiso(CovarianceSEiso original, Cloner cloner) 51 51 : 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 } 55 63 this.sf2 = original.sf2; 56 64 this.l = original.l; … … 70 78 } 71 79 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); 74 87 this.symmetric = true; 75 88 } 76 89 77 90 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) { 82 92 this.symmetric = false; 83 93 this.x = x; … … 90 100 return sf2 * Math.Exp(-sd[i, j] / 2.0); 91 101 } 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 104 102 105 103 public double[] GetGradient(int i, int j) {
Note: See TracChangeset
for help on using the changeset viewer.