Free cookie consent management tool by TermsFeed Policy Generator

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

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

#3040

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