Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 15651 was 15583, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers

File size: 3.6 KB
RevLine 
[7849]1#region License Information
2/* HeuristicLab
[15583]3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[7849]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;
[14228]25using HeuristicLab.Core;
[7849]26using HeuristicLab.Random;
27
28namespace HeuristicLab.Problems.Instances.DataAnalysis {
29  public class BreimanOne : ArtificialRegressionDataDescriptor {
30
31    public override string Name { get { return "Breiman - I"; } }
32    public override string Description {
33      get {
34        return "Paper: Classification and Regression Trees" + Environment.NewLine
35        + "Authors: Leo Breiman, Jerome H. Friedman, Charles J. Stone and R. A. Olson";
36      }
37    }
38    protected override string TargetVariable { get { return "Y"; } }
[8825]39    protected override string[] VariableNames { get { return new string[] { "X1", "X2", "X3", "X4", "X5", "X6", "X7", "X8", "X9", "X10", "Y" }; } }
[7849]40    protected override string[] AllowedInputVariables { get { return new string[] { "X1", "X2", "X3", "X4", "X5", "X6", "X7", "X8", "X9", "X10" }; } }
41    protected override int TrainingPartitionStart { get { return 0; } }
42    protected override int TrainingPartitionEnd { get { return 5001; } }
43    protected override int TestPartitionStart { get { return 5001; } }
44    protected override int TestPartitionEnd { get { return 10001; } }
45
[14229]46    public int Seed { get; private set; }
[7849]47
[14228]48    public BreimanOne() : this((int)DateTime.Now.Ticks) { }
49    public BreimanOne(int seed) : base() {
50      Seed = seed;
51    }
52
[7849]53    protected override List<List<double>> GenerateValues() {
54      List<List<double>> data = new List<List<double>>();
55      List<int> values = new List<int>() { -1, 1 };
[14228]56      var rand = new MersenneTwister((uint)Seed);
57      data.Add(GenerateUniformIntegerDistribution(rand, values, TestPartitionEnd));
[7849]58      values.Add(0);
59      for (int i = 0; i < AllowedInputVariables.Count() - 1; i++) {
[14228]60        data.Add(GenerateUniformIntegerDistribution(rand, values, TestPartitionEnd));
[7849]61      }
62      double x1, x2, x3, x4, x5, x6, x7;
63      double f;
64      List<double> results = new List<double>();
65      double sigma = Math.Sqrt(2);
66      for (int i = 0; i < data[0].Count; i++) {
67        x1 = data[0][i];
68        x2 = data[1][i];
69        x3 = data[2][i];
70        x4 = data[3][i];
71        x5 = data[4][i];
72        x6 = data[5][i];
73        x7 = data[6][i];
74
75        if (x1.Equals(1))
76          f = 3 + 3 * x2 + 2 * x3 + x4;
77        else
78          f = -3 + 3 * x5 + 2 * x6 + x7;
79
80        results.Add(f + NormalDistributedRandom.NextDouble(rand, 0, sigma));
81      }
82      data.Add(results);
83
84      return data;
85    }
86
[14228]87    private List<double> GenerateUniformIntegerDistribution(IRandom rand, List<int> classes, int amount) {
[7849]88      List<double> values = new List<double>();
89      for (int i = 0; i < amount; i++) {
90        values.Add(classes[rand.Next(0, classes.Count)]);
91      }
92      return values;
93    }
94  }
95}
Note: See TracBrowser for help on using the repository browser.