Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3040_VectorBasedGP/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/VectorData/VectorDataTestOne.cs @ 17541

Last change on this file since 17541 was 17541, checked in by pfleck, 4 years ago

#3040 Added a new benchmark instance.

File size: 6.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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;
24using System.Collections.Generic;
25using System.Linq;
26using HeuristicLab.Core;
27using HeuristicLab.Random;
28using MathNet.Numerics.Statistics;
29
30using DoubleVector = MathNet.Numerics.LinearAlgebra.Vector<double>;
31
32namespace HeuristicLab.Problems.Instances.DataAnalysis {
33  public abstract class VectorDataTestOne : ArtificialRegressionDataDescriptor {
34
35    protected const int Rows = 100;
36
37    public override string Description { get { return ""; } }
38
39    protected override string TargetVariable { get { return "Y"; } }
40    protected override string[] VariableNames { get { return new string[] { "X1", "X2", "X3", "V1", "V2", "Y" }; } }
41    protected override string[] AllowedInputVariables { get { return new string[] { "X1", "X2", "X3", "V1", "V2" }; } }
42    protected override int TrainingPartitionStart { get { return 0; } }
43    protected override int TrainingPartitionEnd { get { return Rows * 3 / 4; } }
44    protected override int TestPartitionStart { get { return TrainingPartitionEnd; } }
45    protected override int TestPartitionEnd { get { return Rows; } }
46
47    public int Seed { get; private set; }
48
49    protected VectorDataTestOne()
50      : this((int)DateTime.Now.Ticks) { }
51    protected VectorDataTestOne(int seed)
52      : base() {
53      Seed = seed;
54    }
55
56
57    protected override List<List<double>> GenerateValues() { return null; }
58    protected override List<IList> GenerateValuesExtended() {
59      var rand = new MersenneTwister((uint)Seed);
60
61      double x1, x2, x3;
62      DoubleVector v1, v2;
63      double y;
64
65      var x1Column = new List<double>(Rows);
66      var x2Column = new List<double>(Rows);
67      var x3Column = new List<double>(Rows);
68      var v1Column = new List<DoubleVector>(Rows);
69      var v2Column = new List<DoubleVector>(Rows);
70      var yColumn = new List<double>(Rows);
71
72      var vectorLengths = GetVectorLengths(rand);
73      for (int i = 0; i < Rows; i++) {
74        x1 = rand.NextDouble(-2, 2);
75        x2 = rand.NextDouble(2, 6);
76        x3 = rand.NextDouble(0, 1);
77        int v1Length = vectorLengths[0][i];
78        int v2Length = vectorLengths[1][i];
79        v1 = rand.NextDoubleVector(-2, 2, v1Length);
80        v2 = rand.NextDoubleVector(3, 5, v2Length);
81
82        y = x1 * v1.Sum() + x2 * v2.Mean();
83
84        x1Column.Add(x1);
85        x2Column.Add(x2);
86        x3Column.Add(x3);
87        v1Column.Add(v1);
88        v2Column.Add(v2);
89        yColumn.Add(y);
90      }
91
92      return new List<IList> { x1Column, x2Column, x3Column, v1Column, v2Column, yColumn };
93    }
94
95    protected abstract List<int>[] GetVectorLengths(IRandom rand);
96  }
97
98  public class VectorDataTestOneA : VectorDataTestOne {
99    public override string Name {
100      get { return "Vector Data Test - I [fully-constrained]: Y = X1 * sum(V1) + X2 * mean(V2)"; }
101    }
102
103    public VectorDataTestOneA() : base() { }
104    public VectorDataTestOneA(int seed) : base(seed) { }
105
106    protected override List<int>[] GetVectorLengths(IRandom rand) {
107      // always same length
108      const int length = 5;
109      return new List<int>[2] {
110        Enumerable.Repeat(length, Rows).ToList(),
111        Enumerable.Repeat(length, Rows).ToList()
112      };
113    }
114  }
115
116  public class VectorDataTestOneB : VectorDataTestOne {
117    public override string Name { get { return "Vector Data Test - I [row-constrained]: Y = X1 * sum(V1) + X2 * mean(V2)"; } }
118
119    public VectorDataTestOneB() : base() { }
120    public VectorDataTestOneB(int seed) : base(seed) { }
121
122    protected override List<int>[] GetVectorLengths(IRandom rand) {
123      // length between length 4 and 8, same row always the same length
124      var lengths = Enumerable.Range(0, Rows).Select(i => rand.Next(4, 8)).ToList();
125      return new List<int>[2] {
126        Enumerable.Range(0, Rows).Select(i => lengths[i]).ToList(),
127        Enumerable.Range(0, Rows).Select(i => lengths[i]).ToList()
128      };
129    }
130  }
131
132  public class VectorDataTestOneC : VectorDataTestOne {
133    public override string Name { get { return "Vector Data Test - I [column-constrained]: Y = X1 * sum(V1) + X2 * mean(V2)"; } }
134
135    public VectorDataTestOneC() : base() { }
136    public VectorDataTestOneC(int seed) : base(seed) { }
137
138    protected override List<int>[] GetVectorLengths(IRandom rand) {
139      // length between length 4 and 8; each feature is same length
140      // force two different lengths
141      int v1Length = rand.Next(4, 8);
142      int v2Length;
143      do {
144        v2Length = rand.Next(4, 8);
145      } while (v1Length != v2Length);
146      return new List<int>[2] {
147        Enumerable.Repeat(v1Length, Rows).ToList(),
148        Enumerable.Repeat(v2Length, Rows).ToList()
149      };
150    }
151  }
152
153  public class VectorDataTestOneD : VectorDataTestOne {
154    public override string Name { get { return "Vector Data Test - I [unconstrained]: Y = X1 * sum(V1) + X2 * mean(V2)"; } }
155
156    public VectorDataTestOneD() : base() { }
157    public VectorDataTestOneD(int seed) : base(seed) { }
158
159    protected override List<int>[] GetVectorLengths(IRandom rand) {
160      // always random between 4 and 8
161      return new List<int>[2] {
162          Enumerable.Range(0, Rows).Select(i => rand.Next(4, 8)).ToList(),
163          Enumerable.Range(0, Rows).Select(i => rand.Next(4, 8)).ToList()
164        };
165    }
166  }
167}
Note: See TracBrowser for help on using the repository browser.