Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/09/12 16:32:44 (12 years ago)
Author:
gkronber
Message:

#1902 improved GPR implementation

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/GaussianProcessRegressionTest.cs

    r8455 r8463  
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.Linq;
    2524using System.Threading;
    2625using HeuristicLab.Algorithms.DataAnalysis;
    2726using HeuristicLab.Common;
    28 using HeuristicLab.Core;
    2927using HeuristicLab.Problems.DataAnalysis;
    30 using HeuristicLab.SequentialEngine;
     28using HeuristicLab.Problems.Instances.DataAnalysis;
    3129using Microsoft.VisualStudio.TestTools.UnitTesting;
    3230
    33 namespace HeuristicLab_33.Tests {
     31namespace HeuristicLab.Algorithms.DataAnalysis_34.Tests {
    3432  [TestClass]
     33  [DeploymentItem(@"HeuristicLab.Algorithms.DataAnalysis-3.4/co2.txt")]
    3534  public class GaussianProcessRegressionTest {
    3635    public GaussianProcessRegressionTest() { }
     
    5857      ex = null;
    5958
    60       var cv = new CrossValidation();
    6159      var alg = new GaussianProcessRegression();
    62       alg.Engine = new SequentialEngine();
    63       cv.Algorithm = alg;
     60      alg.Engine = new HeuristicLab.SequentialEngine.SequentialEngine();
    6461
    65       cv.Problem = new RegressionProblem();
    66       var rand = new HeuristicLab.Random.MersenneTwister();
    67       double[,] data = GenerateData(100, rand);
    68       List<string> variables = new List<string>() { "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "y" };
    69       Dataset ds = new Dataset(variables, data);
    70       cv.Problem.ProblemDataParameter.ActualValue = new RegressionProblemData(ds, variables.Take(10), variables.Last());
    71       cv.Algorithm.Prepare();
    72       cv.Folds.Value = 5;
    73       cv.SamplesStart.Value = 0;
    74       cv.SamplesEnd.Value = 99;
     62      alg.Problem = new RegressionProblem();
     63      var provider = new RegressionCSVInstanceProvider();
     64      var problemData = (RegressionProblemData)provider.ImportData("co2.txt");
     65      problemData.TargetVariableParameter.ActualValue = problemData.TargetVariableParameter.ValidValues.First(x => x.Value == "interpolated");
     66      problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "year"), false);
     67      problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "month"), false);
     68      problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "average"), false);
     69      problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "interpolated"), false);
     70      problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "trend"), false);
     71      problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "#days"), false);
    7572
    76       cv.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(cv_ExceptionOccurred);
    77       cv.Stopped += new EventHandler(cv_Stopped);
     73      alg.Problem.ProblemDataParameter.Value = problemData;
    7874
    79       cv.Prepare();
    80       cv.Start();
     75      alg.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(cv_ExceptionOccurred);
     76      alg.Stopped += new EventHandler(cv_Stopped);
     77
     78      alg.Prepare();
     79      alg.Start();
    8180      trigger.WaitOne();
    8281      if (ex != null) throw ex;
    8382
    84       TestContext.WriteLine("Runtime: {0}", cv.ExecutionTime.ToString());
    85 
    86     }
    87 
    88     // poly-10: y = x1 x2 + x3 x4 + x5 x6 + x1 x7 x9 + x3 x6 x10
    89     private double[,] GenerateData(int n, IRandom random) {
    90       double[,] data = new double[n, 11];
    91       for (int i = 0; i < n; i++) {
    92         for (int c = 0; c < 10; c++) {
    93           data[i, c] = random.NextDouble() * 2.0 - 1.0;
    94         }
    95         data[i, 10] =
    96           data[i, 0] * data[i, 1] +
    97           data[i, 2] * data[i, 3] +
    98           data[i, 4] * data[i, 5] +
    99           data[i, 0] * data[i, 6] * data[i, 8] +
    100           data[i, 2] * data[i, 5] * data[i, 9];
    101       }
    102       return data;
     83      TestContext.WriteLine("Runtime: {0}", alg.ExecutionTime.ToString());
    10384    }
    10485
Note: See TracChangeset for help on using the changeset viewer.