Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/08/13 11:01:56 (12 years ago)
Author:
gkronber
Message:

#1967 implemented utility app to draw random samples using a GP prior

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GaussianProcessTuning/HeuristicLab.Problems.Instances.DataAnalysis.GaussianProcessRegression/Util.cs

    r9099 r9124  
    3131
    3232
     33    public static List<double> SampleGaussianProcess(IRandom random, ParameterizedCovarianceFunction covFunction, List<List<double>> data) {
     34      int n = data[0].Count;
    3335
    34     public static List<double> SampleGaussianProcess(IRandom random, ParameterizedCovarianceFunction covFunction, List<List<double>> data) {
     36      var normalRand = new NormalDistributedRandom(random, 0, 1);
     37      var alpha = (from i in Enumerable.Range(0, n)
     38                   select normalRand.NextDouble()).ToArray();
     39      return SampleGaussianProcess(random, covFunction, data, alpha);
     40    }
     41
     42    public static List<double> SampleGaussianProcess(IRandom random, ParameterizedCovarianceFunction covFunction, List<List<double>> data, double[] alpha) {
     43      if (alpha.Length != data[0].Count) throw new ArgumentException();
    3544
    3645      double[,] x = new double[data[0].Count, data.Count];
     
    4352          K[i, j] = covFunction.Covariance(x, i, j);
    4453
    45       var normalRand = new NormalDistributedRandom(random, 0, 1);
    46 
    4754      if (!alglib.spdmatrixcholesky(ref K, K.GetLength(0), true)) throw new ArgumentException();
    48       var r = (from i in Enumerable.Range(0, K.GetLength(0))
    49                select normalRand.NextDouble()).ToArray();
    5055
    5156      List<double> target = new List<double>(K.GetLength(0));
     
    5459        for (int j = K.GetLength(0) - 1; j >= 0; j--) {
    5560
    56           s += K[j, i] * r[j];
     61          s += K[j, i] * alpha[j];
    5762        }
    5863
Note: See TracChangeset for help on using the changeset viewer.