Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Various/FriedmanTwo.cs @ 14228

Last change on this file since 14228 was 14228, checked in by gkronber, 8 years ago

#2371: added constructors to allow specification of random seeds for randomly generated regression problem instances (primarily for unit tests)

File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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 FriedmanTwo : ArtificialRegressionDataDescriptor {
29
30    public override string Name { get { return "Friedman - II"; } }
31    public override string Description {
32      get {
33        return "Paper: Multivariate Adaptive Regression Splines" + Environment.NewLine
34        + "Authors: Jerome H. Friedman";
35      }
36    }
37    protected override string TargetVariable { get { return "Y"; } }
38    protected override string[] VariableNames { 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 5000; } }
42    protected override int TestPartitionStart { get { return 5000; } }
43    protected override int TestPartitionEnd { get { return 10000; } }
44
45    public int Seed { get; }
46
47    public FriedmanTwo() : this((int)DateTime.Now.Ticks) { }
48
49    public FriedmanTwo(int seed) : base() {
50      Seed = seed;
51    }
52    protected override List<List<double>> GenerateValues() {
53      List<List<double>> data = new List<List<double>>();
54      var rand = new MersenneTwister((uint)Seed);
55
56      for (int i = 0; i < AllowedInputVariables.Count(); i++) {
57        data.Add(ValueGenerator.GenerateUniformDistributedValues(rand.Next(), 10000, 0, 1).ToList());
58      }
59
60      double x1, x2, x3, x4, x5;
61      double f;
62      List<double> results = new List<double>();
63      for (int i = 0; i < data[0].Count; i++) {
64        x1 = data[0][i];
65        x2 = data[1][i];
66        x3 = data[2][i];
67        x4 = data[3][i];
68        x5 = data[4][i];
69
70        f = 10 * Math.Sin(Math.PI * x1 * x2) + 20 * Math.Pow(x3 - 0.5, 2) + 10 * x4 + 5 * x5;
71
72        results.Add(f + NormalDistributedRandom.NextDouble(rand, 0, 1));
73      }
74      data.Add(results);
75
76      return data;
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.