#region License Information /* HeuristicLab * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Linq; using HeuristicLab.Algorithms.DataAnalysis; using HeuristicLab.Core; using HeuristicLab.Random; namespace HeuristicLab.Problems.Instances.DataAnalysis { public class Util { public static List SampleGaussianProcess(IRandom random, ICovarianceFunction covFunction, List> data) { double[,] x = new double[data[0].Count, 1]; for (int i = 0; i < x.GetLength(0); i++) for (int j = 0; j < x.GetLength(1); j++) x[i, j] = data[j][i]; double[,] K = new double[x.GetLength(0), x.GetLength(0)]; for (int i = 0; i < K.GetLength(0); i++) for (int j = i; j < K.GetLength(1); j++) K[i, j] = covFunction.GetCovariance(x, i, j, null); var normalRand = new NormalDistributedRandom(random, 0, 1); if (!alglib.spdmatrixcholesky(ref K, K.GetLength(0), true)) throw new ArgumentException(); var r = (from i in Enumerable.Range(0, K.GetLength(0)) select normalRand.NextDouble()).ToArray(); List target = new List(K.GetLength(0)); for (int i = 0; i < K.GetLength(0); i++) { double s = 0.0; for (int j = K.GetLength(0) - 1; j >= 0; j--) { s += K[j, i] * r[j]; } target.Add(s); } return target; } } }