Changeset 8982 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/MeanFunctions/MeanSum.cs
- Timestamp:
- 12/01/12 19:02:47 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/MeanFunctions/MeanSum.cs
r8929 r8982 19 19 */ 20 20 #endregion 21 22 using System.Collections.Generic; 21 23 using System.Linq; 22 24 using HeuristicLab.Common; … … 57 59 } 58 60 59 public void SetParameter(double[] hyp) {61 public void SetParameter(double[] p) { 60 62 int offset = 0; 61 63 foreach (var t in terms) { 62 64 var numberOfParameters = t.GetNumberOfParameters(numberOfVariables); 63 t.SetParameter( hyp.Skip(offset).Take(numberOfParameters).ToArray());65 t.SetParameter(p.Skip(offset).Take(numberOfParameters).ToArray()); 64 66 offset += numberOfParameters; 65 67 } 66 68 } 67 69 68 public double[] GetMean(double[,] x) { 69 var res = terms.First().GetMean(x); 70 foreach (var t in terms.Skip(1)) { 71 var a = t.GetMean(x); 72 for (int i = 0; i < res.Length; i++) res[i] += a[i]; 70 public ParameterizedMeanFunction GetParameterizedMeanFunction(double[] p, IEnumerable<int> columnIndices) { 71 var termMf = new List<ParameterizedMeanFunction>(); 72 int totalNumberOfParameters = GetNumberOfParameters(numberOfVariables); 73 int[] termIndexMap = new int[totalNumberOfParameters]; // maps k-th parameter to the correct mean-term 74 int[] hyperParameterIndexMap = new int[totalNumberOfParameters]; // maps k-th parameter to the l-th parameter of the correct mean-term 75 int c = 0; 76 // get the parameterized mean function for each term 77 for (int termIndex = 0; termIndex < terms.Count; termIndex++) { 78 var numberOfParameters = terms[termIndex].GetNumberOfParameters(numberOfVariables); 79 termMf.Add(terms[termIndex].GetParameterizedMeanFunction(p.Take(numberOfParameters).ToArray(), columnIndices)); 80 p = p.Skip(numberOfParameters).ToArray(); 81 82 for (int hyperParameterIndex = 0; hyperParameterIndex < numberOfParameters; hyperParameterIndex++) { 83 termIndexMap[c] = termIndex; 84 hyperParameterIndexMap[c] = hyperParameterIndex; 85 c++; 86 } 73 87 } 74 return res;75 }76 88 77 public double[] GetGradients(int k, double[,] x) { 78 int i = 0; 79 while (k >= terms[i].GetNumberOfParameters(numberOfVariables)) { 80 k -= terms[i].GetNumberOfParameters(numberOfVariables); 81 i++; 82 } 83 return terms[i].GetGradients(k, x); 89 var mf = new ParameterizedMeanFunction(); 90 mf.Mean = (x, i) => termMf.Select(t => t.Mean(x, i)).Sum(); 91 mf.Gradient = (x, i, k) => { 92 return termMf[termIndexMap[k]].Gradient(x, i, hyperParameterIndexMap[k]); 93 }; 94 return mf; 84 95 } 85 96 }
Note: See TracChangeset
for help on using the changeset viewer.