Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceProd.cs @ 8371

Last change on this file since 8371 was 8323, checked in by gkronber, 12 years ago

#1902 initial import of Gaussian process regression algorithm

File size: 1.6 KB
Line 
1using System.Collections.Generic;
2using System.Linq;
3
4namespace HeuristicLab.Algorithms.DataAnalysis.GaussianProcess {
5  public class CovarianceProd : ICovarianceFunction {
6    private IList<ICovarianceFunction> covariances;
7
8    public int NumberOfParameters {
9      get { return covariances.Sum(c => c.NumberOfParameters); }
10    }
11
12    public CovarianceProd(IEnumerable<ICovarianceFunction> covariances) {
13      this.covariances = covariances.ToList();
14    }
15
16    public void SetMatrix(double[,] x) {
17      foreach (var covariance in covariances) {
18        covariance.SetMatrix(x, x);
19      }
20    }
21
22    public void SetMatrix(double[,] x, double[,] xt) {
23      foreach (var covariance in covariances) {
24        covariance.SetMatrix(x, xt);
25      }
26    }
27
28    public void SetHyperparamter(double[] hyp) {
29      int i = 0;
30      foreach (var covariance in covariances) {
31        int n = covariance.NumberOfParameters;
32        covariance.SetHyperparamter(hyp.Skip(i).Take(n).ToArray());
33        i += n;
34      }
35    }
36
37    public double GetCovariance(int i, int j) {
38      return covariances.Select(c => c.GetCovariance(i, j))
39        .Aggregate((a, b) => a * b);
40    }
41
42
43    public double[] GetDiagonalCovariances() {
44      return covariances
45        .Select(c => c.GetDiagonalCovariances())
46        .Aggregate((s, d) => s.Zip(d, (a, b) => a * b).ToArray())
47        .ToArray();
48    }
49
50    public double[] GetDerivatives(int i, int j) {
51      return covariances
52        .Select(c => c.GetDerivatives(i, j))
53        .Aggregate(Enumerable.Empty<double>(), (h0, h1) => h0.Concat(h1))
54        .ToArray();
55    }
56  }
57}
Note: See TracBrowser for help on using the repository browser.