Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3040_VectorBasedGP/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/VectorData/VectorDataTestThree.cs

Last change on this file was 17915, checked in by pfleck, 3 years ago

#3040 started added some vector benchmarks for gptp.

File size: 6.3 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 VectorDataTestThree : 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 VectorDataTestThree()
49      : this((int)DateTime.Now.Ticks) { }
50    protected VectorDataTestThree(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.NextIncreasingDoubleVector(1, 4, v1Length);
79        v2 = rand.NextIncreasingDoubleVector(3, 5, v2Length);
80
81        //Y = (X1 + sum[2:](V1)) * mean[:-2](V2 + X2)
82        y = (x1 + v1.SubVector(2, v1.Count - 2).Sum()) * (v2 + x2).SubVector(0, v2.Count - 2).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 VectorDataTestThreeA : VectorDataTestThree {
99    public override string Name {
100      get { return "Vector Data Test - III [fully-constrained]: Y = (X1 + sum[2:](V1)) * mean[:-2](V2 + X2)"; }
101    }
102
103    public VectorDataTestThreeA() : base() { }
104    public VectorDataTestThreeA(int seed) : base(seed) { }
105
106    protected override List<int>[] GetVectorLengths(IRandom rand) {
107      // always same length
108      const int length = 8;
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 VectorDataTestThreeB : VectorDataTestThree {
117    public override string Name { get { return "Vector Data Test - III [row-constrained]: Y = (X1 + sum[2:](V1)) * mean[:-2](V2 + X2)"; } }
118
119    public VectorDataTestThreeB() : base() { }
120    public VectorDataTestThreeB(int seed) : base(seed) { }
121
122    protected override List<int>[] GetVectorLengths(IRandom rand) {
123      // length between length 6 and 10, same row always the same length
124      var lengths = Enumerable.Range(0, Rows).Select(i => rand.Next(6, 10)).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 VectorDataTestThreeC : VectorDataTestThree {
133    public override string Name { get { return "Vector Data Test - III [column-constrained]: Y = (X1 + sum[2:](V1)) * mean[:-2](V2 + X2)"; } }
134
135    public VectorDataTestThreeC() : base() { }
136    public VectorDataTestThreeC(int seed) : base(seed) { }
137
138    protected override List<int>[] GetVectorLengths(IRandom rand) {
139      // length between length 6 and 10; each feature is same length
140      // force two different lengths
141      int v1Length = rand.Next(6, 10);
142      int v2Length;
143      do {
144        v2Length = rand.Next(6, 10);
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 VectorDataTestThreeD : VectorDataTestThree {
154    public override string Name { get { return "Vector Data Test - III [unconstrained]: Y = (X1 + sum[2:](V1)) * mean[:-2](V2 + X2)"; } }
155
156    public VectorDataTestThreeD() : base() { }
157    public VectorDataTestThreeD(int seed) : base(seed) { }
158
159    protected override List<int>[] GetVectorLengths(IRandom rand) {
160      // always random between 6 and 10
161      return new List<int>[2] {
162          Enumerable.Range(0, Rows).Select(i => rand.Next(6, 10)).ToList(),
163          Enumerable.Range(0, Rows).Select(i => rand.Next(6, 10)).ToList()
164        };
165    }
166  }
167}
Note: See TracBrowser for help on using the repository browser.