public void GaussianProcessRegressionPerformanceTest() {
      ex = null;

      var alg = new GaussianProcessRegression();
      alg.Engine = new HeuristicLab.SequentialEngine.SequentialEngine();

      alg.Problem = new RegressionProblem();
      var provider = new RegressionCSVInstanceProvider();
      var problemData = (RegressionProblemData)provider.ImportData(@"Test Resources\co2.txt");
      problemData.TargetVariableParameter.ActualValue = problemData.TargetVariableParameter.ValidValues.First(x => x.Value == "interpolated");
      problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "year"), false);
      problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "month"), false);
      problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "average"), false);
      problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "interpolated"), false);
      problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "trend"), false);
      problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "#days"), false);

      alg.Problem.ProblemDataParameter.Value = problemData;

      alg.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(cv_ExceptionOccurred);
      alg.Stopped += new EventHandler(cv_Stopped);

      alg.Prepare();
      alg.Start();
      trigger.WaitOne();
      if (ex != null) throw ex;

      TestContext.WriteLine("Runtime: {0}", alg.ExecutionTime.ToString());
    }
    public void GaussianProcessModelOutputTest() {
      var provider = new RegressionCSVInstanceProvider();
      var problemData = provider.ImportData(@"Test Resources\co2.txt");

      var targetVariable = "interpolated";
      var allowedInputVariables = new string[] { "decimal date" };
      var rows = Enumerable.Range(0, 401);

      var meanFunction = new MeanConst();
      var covarianceFunction = new CovarianceSum();
      covarianceFunction.Terms.Add(new CovarianceSquaredExponentialIso());
      var prod = new CovarianceProduct();
      prod.Factors.Add(new CovarianceSquaredExponentialIso());
      prod.Factors.Add(new CovariancePeriodic());
      covarianceFunction.Terms.Add(prod);

      {
        var hyp = new double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        var model = new GaussianProcessModel(problemData.Dataset, targetVariable, allowedInputVariables, rows, hyp,
                                             meanFunction,
                                             covarianceFunction);
        Assert.AreEqual(4.3170e+004, model.NegativeLogLikelihood, 1);

        var dHyp = model.HyperparameterGradients;
        Assert.AreEqual(-248.7932, dHyp[0], 1E-2);
        var dHypCovExpected = new double[] { -0.5550e4, -5.5533e4, -0.2511e4, -2.7625e4, -1.3033e4, 0.0289e4, -2.7625e4 };
        AssertEqual(dHypCovExpected, dHyp.Skip(1).Take(7).ToArray(), 1);
        Assert.AreEqual(-2.0171e+003, dHyp.Last(), 1);


        var predTrain = model.GetEstimatedValues(problemData.Dataset, new int[] { 0, 400 }).ToArray();
        Assert.AreEqual(310.5930, predTrain[0], 1e-3);
        Assert.AreEqual(347.9993, predTrain[1], 1e-3);

        var predTrainVar = model.GetEstimatedVariance(problemData.Dataset, problemData.TrainingIndices).ToArray();
      }

      {
        var hyp = new double[] { 0.029973094285941, 0.455535210579926, 3.438647883940457, 1.464114485889487, 3.001788584487478, 3.815289323309630, 4.374914122810222, 3.001788584487478, 0.716427415979145 };
        var model = new GaussianProcessModel(problemData.Dataset, targetVariable, allowedInputVariables, rows, hyp,
                                             meanFunction,
                                             covarianceFunction);
        Assert.AreEqual(872.8448, model.NegativeLogLikelihood, 1e-3);

        var dHyp = model.HyperparameterGradients;
        Assert.AreEqual(-0.0046, dHyp[0], 1e-3);
        var dHypCovExpected = new double[] { 0.2652, -0.2386, 0.1706, -0.1744, 0.0000, 0.0000, -0.1744 };
        AssertEqual(dHypCovExpected, dHyp.Skip(1).Take(7).ToArray(), 1e-3);
        Assert.AreEqual(0.8621, dHyp.Last(), 1e-3);

        var predTrain = model.GetEstimatedValues(problemData.Dataset, new int[] { 0, 400 }).ToArray();
        Assert.AreEqual(315.3692, predTrain[0], 1e-3);
        Assert.AreEqual(356.6076, predTrain[1], 1e-3);
      }
    }