Free cookie consent management tool by TermsFeed Policy Generator

source: branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/RegressionBenchmarks/Other/BreimanOne.cs @ 7485

Last change on this file since 7485 was 7485, checked in by sforsten, 12 years ago

#1708:

  • changes according to mkommend's reviewing comments have been made
File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using HeuristicLab.Data;
25using HeuristicLab.Random;
26
27namespace HeuristicLab.Problems.DataAnalysis.Benchmarks {
28  public class BreimanOne : RegressionToyBenchmark {
29
30    public BreimanOne() {
31      Name = "Breiman - I";
32      Description = "Paper: Classification and Regression Trees" + Environment.NewLine
33        + "Authors: Leo Breiman, Jerome H. Friedman, Charles J. Stone and R. A. Olson";
34      targetVariable = "Y";
35      inputVariables = new List<string>() { "X1", "X2", "X3", "X4", "X5", "X6", "X7", "X8", "X9", "X10" };
36      trainingPartition = new IntRange(0, 5001);
37      testPartition = new IntRange(5001, 10001);
38    }
39
40    protected override List<double> GenerateTarget(List<List<double>> data) {
41      double x1, x2, x3, x4, x5, x6, x7;
42      double f;
43      List<double> results = new List<double>();
44      double sigma = Math.Sqrt(2);
45      for (int i = 0; i < data[0].Count; i++) {
46        x1 = data[0][i];
47        x2 = data[1][i];
48        x3 = data[2][i];
49        x4 = data[3][i];
50        x5 = data[4][i];
51        x6 = data[5][i];
52        x7 = data[6][i];
53
54        if (x1.Equals(1))
55          f = 3 + 3 * x2 + 2 * x3 + x4;
56        else
57          f = -3 + 3 * x5 + 2 * x6 + x7;
58
59        results.Add(f + NormalDistributedRandom.NextDouble(rand, 0, sigma));
60      }
61      return results;
62    }
63
64    protected override List<List<double>> GenerateInput() {
65      List<List<double>> dataList = new List<List<double>>();
66      List<int> values = new List<int>() { -1, 1 };
67      dataList.Add(BreimanOne.GenerateUniformIntegerDistribution(values, testPartition.End));
68      values.Add(0);
69      for (int i = 0; i < inputVariables.Count - 1; i++) {
70        dataList.Add(BreimanOne.GenerateUniformIntegerDistribution(values, testPartition.End));
71      }
72
73      return dataList;
74    }
75
76    public static List<double> GenerateUniformIntegerDistribution(List<int> classes, int amount) {
77      List<double> values = new List<double>();
78      for (int i = 0; i < amount; i++) {
79        values.Add(classes[rand.Next(0, classes.Count)]);
80      }
81      return values;
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.