Changeset 8484 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceSum.cs
- Timestamp:
- 08/14/12 13:25:17 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceSum.cs
r8463 r8484 77 77 78 78 public void SetParameter(double[] hyp) { 79 if (terms.Count == 0) throw new ArgumentException("At least one term is needed for sum covariance function."); 79 80 int offset = 0; 80 81 foreach (var t in terms) { … … 84 85 } 85 86 } 86 public void SetData(double[,] x) {87 SetData(x, x);88 }89 87 90 public void SetData(double[,] x, double[,] xt) { 91 foreach (var t in terms) { 92 t.SetData(x, xt); 93 } 94 } 95 96 public double GetCovariance(int i, int j) { 97 return terms.Select(t => t.GetCovariance(i, j)).Sum(); 88 public double GetCovariance(double[,] x, int i, int j) { 89 return terms.Select(t => t.GetCovariance(x, i, j)).Sum(); 98 90 } 99 91 100 92 private Dictionary<int, Tuple<int, int>> cachedParameterMap; 101 public double GetGradient(int i, int j, int k) { 102 if (cachedParameterMap == null) { 103 CalculateParameterMap(); 104 } 105 int ti = cachedParameterMap[k].Item1; 106 k = cachedParameterMap[k].Item2; 107 return terms[ti].GetGradient(i, j, k); 93 public IEnumerable<double> GetGradient(double[,] x, int i, int j) { 94 //if (cachedParameterMap == null) { 95 // CalculateParameterMap(); 96 //} 97 //int ti = cachedParameterMap[k].Item1; 98 //k = cachedParameterMap[k].Item2; 99 //return terms[ti].GetGradient(x, i, j, k); 100 return terms.Select(t => t.GetGradient(x, i, j)).Aggregate(Enumerable.Concat); 108 101 } 102 103 public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) { 104 return terms.Select(t => t.GetCrossCovariance(x, xt, i, j)).Sum(); 105 } 106 109 107 private void ClearCache() { 110 108 cachedParameterMap = null; 111 109 } 112 110 113 private void CalculateParameterMap() {114 cachedParameterMap = new Dictionary<int, Tuple<int, int>>();115 int k = 0;116 for (int ti = 0; ti < terms.Count; ti++) {117 for (int ti_k = 0; ti_k < terms[ti].GetNumberOfParameters(numberOfVariables); ti_k++) {118 cachedParameterMap[k++] = Tuple.Create(ti, ti_k);119 }120 }121 }111 //private void CalculateParameterMap() { 112 // cachedParameterMap = new Dictionary<int, Tuple<int, int>>(); 113 // int k = 0; 114 // for (int ti = 0; ti < terms.Count; ti++) { 115 // for (int ti_k = 0; ti_k < terms[ti].GetNumberOfParameters(numberOfVariables); ti_k++) { 116 // cachedParameterMap[k++] = Tuple.Create(ti, ti_k); 117 // } 118 // } 119 //} 122 120 } 123 121 }
Note: See TracChangeset
for help on using the changeset viewer.