Changeset 8489
- Timestamp:
- 08/14/12 15:24:30 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess
- Files:
-
- 3 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 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceSEard.cs
r8484 r8489 88 88 for (int ii = 0; ii < l.Length; ii++) { 89 89 double sqrDist = Util.SqrDist(x[i, ii] / l[ii], x[j, ii] / l[ii]); 90 yield return sf2 * Math.Exp( d / 2.0) * sqrDist;90 yield return sf2 * Math.Exp(-d / 2.0) * sqrDist; 91 91 } 92 yield return 2.0 * sf2 * Math.Exp( d / 2.0);92 yield return 2.0 * sf2 * Math.Exp(-d / 2.0); 93 93 } 94 94 -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceSum.cs
r8484 r8489 50 50 this.terms = cloner.Clone(original.terms); 51 51 this.numberOfVariables = original.numberOfVariables; 52 AttachEventHandlers();53 52 } 54 53 … … 56 55 : base() { 57 56 this.terms = new ItemList<ICovarianceFunction>(); 58 AttachEventHandlers();59 }60 61 private void AttachEventHandlers() {62 this.terms.CollectionReset += (sender, args) => ClearCache();63 this.terms.ItemsAdded += (sender, args) => ClearCache();64 this.terms.ItemsRemoved += (sender, args) => ClearCache();65 this.terms.ItemsReplaced += (sender, args) => ClearCache();66 this.terms.ItemsMoved += (sender, args) => ClearCache();67 57 } 68 58 … … 90 80 } 91 81 92 private Dictionary<int, Tuple<int, int>> cachedParameterMap;93 82 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 83 return terms.Select(t => t.GetGradient(x, i, j)).Aggregate(Enumerable.Concat); 101 84 } … … 104 87 return terms.Select(t => t.GetCrossCovariance(x, xt, i, j)).Sum(); 105 88 } 106 107 private void ClearCache() {108 cachedParameterMap = null;109 }110 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 //}120 89 } 121 90 }
Note: See TracChangeset
for help on using the changeset viewer.