Changeset 8491 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovariancePeriodic.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/CovariancePeriodic.cs
r8484 r8491 34 34 public double Scale { get { return sf2; } } 35 35 [Storable] 36 private double l;37 public double Length { get { return l; } }36 private double inverseLength; 37 public double InverseLength { get { return inverseLength; } } 38 38 [Storable] 39 39 private double p; … … 48 48 : base(original, cloner) { 49 49 sf2 = original.sf2; 50 l = original.l;50 inverseLength = original.inverseLength; 51 51 p = original.p; 52 52 } … … 61 61 public void SetParameter(double[] hyp) { 62 62 if (hyp.Length != 3) throw new ArgumentException(); 63 this. l =Math.Exp(hyp[0]);63 this.inverseLength = 1.0 / Math.Exp(hyp[0]); 64 64 this.p = Math.Exp(hyp[1]); 65 65 this.sf2 = Math.Exp(2 * hyp[2]); … … 69 69 double k = i == j ? 0.0 : GetDistance(x, x, i, j); 70 70 k = Math.PI * k / p; 71 k = Math.Sin(k) / l;71 k = Math.Sin(k) * inverseLength; 72 72 k = k * k; 73 73 … … 77 77 public IEnumerable<double> GetGradient(double[,] x, int i, int j) { 78 78 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; 80 80 gradient *= gradient; 81 81 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; 84 84 yield return 2.0 * sf2 * Math.Exp(-2 * gradient); 85 85 } … … 88 88 double k = GetDistance(x, xt, i, j); 89 89 k = Math.PI * k / p; 90 k = Math.Sin(k) / l;90 k = Math.Sin(k) * inverseLength; 91 91 k = k * k; 92 92 … … 95 95 96 96 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)); 98 98 } 99 99 }
Note: See TracChangeset
for help on using the changeset viewer.