Changeset 8489 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceProd.cs
 Timestamp:
 08/14/12 15:24:30 (12 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceProd.cs
r8484 r8489 50 50 this.factors = cloner.Clone(original.factors); 51 51 this.numberOfVariables = original.numberOfVariables; 52 AttachEventHandlers();53 52 } 54 53 … … 56 55 : base() { 57 56 this.factors = new ItemList<ICovarianceFunction>(); 58 AttachEventHandlers();59 }60 61 private void AttachEventHandlers() {62 this.factors.CollectionReset += (sender, args) => ClearCache();63 this.factors.ItemsAdded += (sender, args) => ClearCache();64 this.factors.ItemsRemoved += (sender, args) => ClearCache();65 this.factors.ItemsReplaced += (sender, args) => ClearCache();66 this.factors.ItemsMoved += (sender, args) => ClearCache();67 57 } 68 58 … … 91 81 92 82 public IEnumerable<double> GetGradient(double[,] x, int i, int j) { 93 //if (cachedParameterMap == null) {94 // CalculateParameterMap();95 //}96 //int ti = cachedParameterMap[k].Item1;97 //k = cachedParameterMap[k].Item2;98 //double gradient = 1.0;99 //for (int ii = 0; ii < factors.Count; ii++) {100 // var f = factors[ii];101 // if (ii == ti) {102 // gradient *= f.GetGradient(x, i, j, k);103 // } else {104 // gradient *= f.GetCovariance(x, i, j);105 // }106 //}107 //return gradient;108 83 var covariances = factors.Select(f => f.GetCovariance(x, i, j)).ToArray(); 109 84 for (int ii = 0; ii < factors.Count; ii++) { … … 120 95 return factors.Select(f => f.GetCrossCovariance(x, xt, i, j)).Aggregate((a, b) => a * b); 121 96 } 122 123 private Dictionary<int, Tuple<int, int>> cachedParameterMap;124 private void ClearCache() {125 cachedParameterMap = null;126 }127 128 private void CalculateParameterMap() {129 cachedParameterMap = new Dictionary<int, Tuple<int, int>>();130 int k = 0;131 for (int ti = 0; ti < factors.Count; ti++) {132 for (int ti_k = 0; ti_k < factors[ti].GetNumberOfParameters(numberOfVariables); ti_k++) {133 cachedParameterMap[k++] = Tuple.Create(ti, ti_k);134 }135 }136 }137 97 } 138 98 }
Note: See TracChangeset
for help on using the changeset viewer.