Free cookie consent management tool by TermsFeed Policy Generator

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