Changeset 8455 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis
- Timestamp:
- 08/09/12 09:33:23 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceLinear.cs
r8417 r8455 29 29 [Item(Name = "CovarianceLinear", Description = "Linear covariance function for Gaussian processes.")] 30 30 public class CovarianceLinear : Item, ICovarianceFunction { 31 private static readonly double[] emptyArray = new double[0];32 33 31 [Storable] 34 32 private double[,] x; … … 89 87 } 90 88 91 public double [] GetGradient(int i, int j) {92 return emptyArray;89 public double GetGradient(int i, int j, int k) { 90 throw new NotSupportedException("CovarianceLinear does not have hyperparameters."); 93 91 } 94 92 -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovariancePeriodic.cs
r8417 r8455 117 117 } 118 118 119 public double[] GetGradient(int i, int j) { 119 public double GetGradient(int i, int j, int k) { 120 double v = Math.PI * sd[i, j] / p; 121 switch (k) { 122 case 0: { 123 double newK = Math.Sin(v) / l; 124 newK = newK * newK; 125 return 4 * sf2 * Math.Exp(-2 * newK) * newK; 126 } 127 case 1: { 128 double r = Math.Sin(v) / l; 129 return 4 * sf2 / l * Math.Exp(-2 * r * r) * r * Math.Cos(v) * v; 130 } 131 case 2: { 132 double newK = Math.Sin(v) / l; 133 newK = newK * newK; 134 return 2 * sf2 * Math.Exp(-2 * newK); 120 135 121 var res = new double[3]; 122 double k = sd[i, j]; 123 k = Math.PI * k / p; 124 { 125 double newK = Math.Sin(k) / l; 126 newK = newK * newK; 127 res[0] = 4 * sf2 * Math.Exp(-2 * newK) * newK; 136 } 137 default: { 138 throw new ArgumentException("CovariancePeriodic only has three hyperparameters.", "k"); 139 } 128 140 } 129 {130 double r = Math.Sin(k) / l;131 res[1] = 4 * sf2 / l * Math.Exp(-2 * r * r) * r * Math.Cos(k) * k;132 }133 {134 double newK = Math.Sin(k) / l;135 newK = newK * newK;136 res[2] = 2 * sf2 * Math.Exp(-2 * newK);137 }138 139 return res;140 141 } 141 142 -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceProd.cs
r8439 r8455 86 86 } 87 87 88 public double[] GetGradient(int i, int j) {89 return Enumerable.Range(0, GetNumberOfParameters(numberOfVariables)).Select(k => GetGradient(i, j, k)).ToArray();90 }91 88 public double GetGradient(int i, int j, int k) { 92 89 // map from parameter index to factor … … 97 94 var f = factors[ii]; 98 95 if (ii == vi[k]) { 99 res *= f.GetGradient(i, j )[jj];96 res *= f.GetGradient(i, j, jj); 100 97 } else { 101 98 res *= f.GetCovariance(i, j); -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceSEard.cs
r8416 r8455 99 99 } 100 100 101 public double[] GetGradient(int i, int j) { 102 var res = new double[l.Length + 1]; 103 for (int k = 0; k < l.Length; k++) { 101 public double GetGradient(int i, int j, int k) { 102 if (k < l.Length) { 104 103 double sqrDist = Util.SqrDist(x[i, k] / l[k], xt[j, k] / l[k]); 105 106 res[k] = sf2 * Math.Exp(-sd[i, j] / 2.0) * sqrDist; 104 return sf2 * Math.Exp(-sd[i, j] / 2.0) * sqrDist; 105 } else if (k == l.Length) { 106 return 2.0 * sf2 * Math.Exp(-sd[i, j] / 2.0); 107 } else { 108 throw new ArgumentException("CovarianceSEard has dimension+1 hyperparameters.", "k"); 107 109 } 108 res[res.Length - 1] = 2.0 * sf2 * Math.Exp(-sd[i, j] / 2.0);109 return res;110 110 } 111 111 -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceSEiso.cs
r8416 r8455 101 101 } 102 102 103 public double[] GetGradient(int i, int j) { 104 var res = new double[2]; 105 res[0] = sf2 * Math.Exp(-sd[i, j] / 2.0) * sd[i, j]; 106 res[1] = 2.0 * sf2 * Math.Exp(-sd[i, j] / 2.0); 107 return res; 103 public double GetGradient(int i, int j, int k) { 104 switch (k) { 105 case 0: return sf2 * Math.Exp(-sd[i, j] / 2.0) * sd[i, j]; 106 case 1: return 2.0 * sf2 * Math.Exp(-sd[i, j] / 2.0); 107 default: throw new ArgumentException("CovarianceSEiso has two hyperparameters", "k"); 108 } 108 109 } 109 110 -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceSum.cs
r8416 r8455 86 86 } 87 87 88 public double[] GetGradient(int i, int j) { 89 return terms.Select(t => t.GetGradient(i, j)).SelectMany(seq => seq).ToArray(); 88 public double GetGradient(int i, int j, int k) { 89 int ii = 0; 90 while (k > terms[ii].GetNumberOfParameters(numberOfVariables)) { 91 k -= terms[ii].GetNumberOfParameters(numberOfVariables); 92 } 93 return terms[ii].GetGradient(i, j, k); 90 94 } 91 95 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModel.cs
r8416 r8455 188 188 for (int i = 0; i < n; i++) { 189 189 for (int j = 0; j < n; j++) { 190 var covDeriv = covarianceFunction.GetGradient(i, j);191 190 for (int k = 0; k < covGradients.Length; k++) { 192 covGradients[k] += q[i, j] * cov Deriv[k];191 covGradients[k] += q[i, j] * covarianceFunction.GetGradient(i, j, k); 193 192 } 194 193 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/ICovarianceFunction.cs
r8416 r8455 30 30 31 31 double GetCovariance(int i, int j); 32 double [] GetGradient(int i, int j);32 double GetGradient(int i, int j, int k); 33 33 } 34 34 }
Note: See TracChangeset
for help on using the changeset viewer.