Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Various/BreimanOne.cs @ 8601

Last change on this file since 8601 was 7860, checked in by sforsten, 13 years ago

#1784:

  • added additional Keijzer problem instances
  • capitalized names real world problem instances
  • added Friedman I and II
  • added link to VariousInstanceProvider
  • changed symbol of info button for ProblemInstanceProvider in ProblemInstanceConsumerView
  • added CSVProvider for classification and regression problems
  • ProblemInstanceProviderViewGeneric only shows controls to load problem instances, if the selected ProblemInstanceProvider contains IDataDescriptor
File size: 3.4 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 System.Linq;
25using HeuristicLab.Random;
26
27namespace HeuristicLab.Problems.Instances.DataAnalysis {
28  public class BreimanOne : ArtificialRegressionDataDescriptor {
29
30    public override string Name { get { return "Breiman - I"; } }
31    public override string Description {
32      get {
33        return "Paper: Classification and Regression Trees" + Environment.NewLine
34        + "Authors: Leo Breiman, Jerome H. Friedman, Charles J. Stone and R. A. Olson";
35      }
36    }
37    protected override string TargetVariable { get { return "Y"; } }
38    protected override string[] InputVariables { get { return new string[] { "X1", "X2", "X3", "X4", "X5", "X6", "X7", "X8", "X9", "X10", "Y" }; } }
39    protected override string[] AllowedInputVariables { get { return new string[] { "X1", "X2", "X3", "X4", "X5", "X6", "X7", "X8", "X9", "X10" }; } }
40    protected override int TrainingPartitionStart { get { return 0; } }
41    protected override int TrainingPartitionEnd { get { return 5001; } }
42    protected override int TestPartitionStart { get { return 5001; } }
43    protected override int TestPartitionEnd { get { return 10001; } }
44
45    protected static FastRandom rand = new FastRandom();
46
47    protected override List<List<double>> GenerateValues() {
48      List<List<double>> data = new List<List<double>>();
49      List<int> values = new List<int>() { -1, 1 };
50      data.Add(GenerateUniformIntegerDistribution(values, TestPartitionEnd));
51      values.Add(0);
52      for (int i = 0; i < AllowedInputVariables.Count() - 1; i++) {
53        data.Add(GenerateUniformIntegerDistribution(values, TestPartitionEnd));
54      }
55
56      double x1, x2, x3, x4, x5, x6, x7;
57      double f;
58      List<double> results = new List<double>();
59      double sigma = Math.Sqrt(2);
60      for (int i = 0; i < data[0].Count; i++) {
61        x1 = data[0][i];
62        x2 = data[1][i];
63        x3 = data[2][i];
64        x4 = data[3][i];
65        x5 = data[4][i];
66        x6 = data[5][i];
67        x7 = data[6][i];
68
69        if (x1.Equals(1))
70          f = 3 + 3 * x2 + 2 * x3 + x4;
71        else
72          f = -3 + 3 * x5 + 2 * x6 + x7;
73
74        results.Add(f + NormalDistributedRandom.NextDouble(rand, 0, sigma));
75      }
76      data.Add(results);
77
78      return data;
79    }
80
81    private List<double> GenerateUniformIntegerDistribution(List<int> classes, int amount) {
82      List<double> values = new List<double>();
83      for (int i = 0; i < amount; i++) {
84        values.Add(classes[rand.Next(0, classes.Count)]);
85      }
86      return values;
87    }
88  }
89}
Note: See TracBrowser for help on using the repository browser.