Changeset 8982 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceSum.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/CovarianceFunctions/CovarianceSum.cs
r8929 r8982 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Linq.Expressions; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 66 67 } 67 68 68 public void SetParameter(double[] hyp) { 69 if (terms.Count == 0) throw new ArgumentException("At least one term is needed for sum covariance function."); 69 public void SetParameter(double[] p) { 70 70 int offset = 0; 71 71 foreach (var t in terms) { 72 72 var numberOfParameters = t.GetNumberOfParameters(numberOfVariables); 73 t.SetParameter( hyp.Skip(offset).Take(numberOfParameters).ToArray());73 t.SetParameter(p.Skip(offset).Take(numberOfParameters).ToArray()); 74 74 offset += numberOfParameters; 75 75 } 76 76 } 77 77 78 public double GetCovariance(double[,] x, int i, int j, IEnumerable<int> columnIndices) { 79 return terms.Select(t => t.GetCovariance(x, i, j, columnIndices)).Sum(); 80 } 78 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) { 79 if (terms.Count == 0) throw new ArgumentException("at least one term is necessary for the product covariance function."); 80 var functions = new List<ParameterizedCovarianceFunction>(); 81 foreach (var t in terms) { 82 var numberOfParameters = t.GetNumberOfParameters(numberOfVariables); 83 functions.Add(t.GetParameterizedCovarianceFunction(p.Take(numberOfParameters).ToArray(), columnIndices)); 84 p = p.Skip(numberOfParameters).ToArray(); 85 } 81 86 82 public IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices) { 83 return terms.Select(t => t.GetGradient(x, i, j, columnIndices)).Aggregate(Enumerable.Concat); 84 } 85 86 public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j, IEnumerable<int> columnIndices) { 87 return terms.Select(t => t.GetCrossCovariance(x, xt, i, j, columnIndices)).Sum(); 87 var sum = new ParameterizedCovarianceFunction(); 88 sum.Covariance = (x, i, j) => functions.Select(e => e.Covariance(x, i, j)).Sum(); 89 sum.CrossCovariance = (x, xt, i, j) => functions.Select(e => e.CrossCovariance(x, xt, i, j)).Sum(); 90 sum.CovarianceGradient = (x, i, j) => functions.Select(e => e.CovarianceGradient(x, i, j)).Aggregate(Enumerable.Concat); 91 return sum; 88 92 } 89 93 }
Note: See TracChangeset
for help on using the changeset viewer.