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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections;
|
---|
24 | using System.Collections.Generic;
|
---|
25 | using System.Linq;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Random;
|
---|
28 | using MathNet.Numerics.Statistics;
|
---|
29 | using DoubleVector = MathNet.Numerics.LinearAlgebra.Vector<double>;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Problems.Instances.DataAnalysis {
|
---|
32 | public abstract class VectorDataTestFour : ArtificialRegressionDataDescriptor {
|
---|
33 |
|
---|
34 | protected const int Rows = 10000;
|
---|
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", "X4", "X5", "V1", "V2", "V3", "V4", "V5", "Y" }; } }
|
---|
40 | protected override string[] AllowedInputVariables { get { return new string[] { "X1", "X2", "X3", "X4", "X5", "V1", "V2", "V3", "V4", "V5" }; } }
|
---|
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 VectorDataTestFour()
|
---|
49 | : this((int)DateTime.Now.Ticks) { }
|
---|
50 | protected VectorDataTestFour(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, x4, x5;
|
---|
61 | DoubleVector v1, v2, v3, v4, v5;
|
---|
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 x4Column = new List<double>(Rows);
|
---|
68 | var x5Column = new List<double>(Rows);
|
---|
69 | var v1Column = new List<DoubleVector>(Rows);
|
---|
70 | var v2Column = new List<DoubleVector>(Rows);
|
---|
71 | var v3Column = new List<DoubleVector>(Rows);
|
---|
72 | var v4Column = new List<DoubleVector>(Rows);
|
---|
73 | var v5Column = new List<DoubleVector>(Rows);
|
---|
74 | var yColumn = new List<double>(Rows);
|
---|
75 |
|
---|
76 | var vectorLengths = GetVectorLengths(rand);
|
---|
77 | for (int i = 0; i < Rows; i++) {
|
---|
78 | x1 = rand.NextDouble(-2, 2);
|
---|
79 | x2 = rand.NextDouble(2, 6);
|
---|
80 | x3 = rand.NextDouble(0, 1);
|
---|
81 | x4 = rand.NextDouble(30, 100);
|
---|
82 | x5 = rand.NextDouble(150, 200);
|
---|
83 | v1 = rand.NextDoubleVector(2, 6, vectorLengths[0][i]);
|
---|
84 | v2 = rand.NextDoubleVector(3, 5, vectorLengths[1][i]);
|
---|
85 | v3 = rand.NextDoubleVector(-10, 50, vectorLengths[2][i]);
|
---|
86 | v4 = rand.NextDoubleVector(0, 200, vectorLengths[3][i]);
|
---|
87 | v5 = rand.NextDoubleVector(200, 220, vectorLengths[4][i]);
|
---|
88 |
|
---|
89 | var t1 = ((v1 + Math.Log(10 * x5)) * (v4 - 50 * v2.PointwiseSin()).Mean() * x1).Mean() / 10; // mean 50
|
---|
90 | var t2 = (v5.StandardDeviation() + v2.PointwisePower(2.0)).Mean(); // mean 18 + 6 = 24
|
---|
91 | var t3 = Math.Exp(3 * x3) + v2.PointwiseMultiply(v3).Mean() / 10; // mean 7 + 8 = 15
|
---|
92 | y = t1 - 0.1 * t2 * t3;
|
---|
93 |
|
---|
94 | x1Column.Add(x1);
|
---|
95 | x2Column.Add(x2);
|
---|
96 | x3Column.Add(x3);
|
---|
97 | x4Column.Add(x4);
|
---|
98 | x5Column.Add(x5);
|
---|
99 | v1Column.Add(v1);
|
---|
100 | v2Column.Add(v2);
|
---|
101 | v3Column.Add(v3);
|
---|
102 | v4Column.Add(v4);
|
---|
103 | v5Column.Add(v5);
|
---|
104 | yColumn.Add(y);
|
---|
105 | }
|
---|
106 |
|
---|
107 | return new List<IList> {
|
---|
108 | x1Column, x2Column, x3Column, x4Column, x5Column,
|
---|
109 | v1Column, v2Column, v3Column, v4Column, v5Column,
|
---|
110 | yColumn
|
---|
111 | };
|
---|
112 | }
|
---|
113 |
|
---|
114 | protected abstract List<int>[] GetVectorLengths(IRandom rand);
|
---|
115 | }
|
---|
116 |
|
---|
117 | public class VectorDataTestFourA : VectorDataTestFour {
|
---|
118 | public override string Name {
|
---|
119 | get { return "Vector Data Test - IV [fully-constrained]: Y = X1 * sum(V1) + X2 * mean(V2)"; }
|
---|
120 | }
|
---|
121 |
|
---|
122 | public VectorDataTestFourA() : base() { }
|
---|
123 | public VectorDataTestFourA(int seed) : base(seed) { }
|
---|
124 |
|
---|
125 | protected override List<int>[] GetVectorLengths(IRandom rand) {
|
---|
126 | // always same length
|
---|
127 | const int length = 40;
|
---|
128 | return new List<int>[5] {
|
---|
129 | Enumerable.Repeat(length, Rows).ToList(),
|
---|
130 | Enumerable.Repeat(length, Rows).ToList(),
|
---|
131 | Enumerable.Repeat(length, Rows).ToList(),
|
---|
132 | Enumerable.Repeat(length, Rows).ToList(),
|
---|
133 | Enumerable.Repeat(length, Rows).ToList()
|
---|
134 | };
|
---|
135 | }
|
---|
136 | }
|
---|
137 |
|
---|
138 | public class VectorDataTestFourB : VectorDataTestFour {
|
---|
139 | public override string Name { get { return "Vector Data Test - IV [row-constrained]: Y = X1 * sum(V1) + X2 * mean(V2)"; } }
|
---|
140 |
|
---|
141 | public VectorDataTestFourB() : base() { }
|
---|
142 | public VectorDataTestFourB(int seed) : base(seed) { }
|
---|
143 |
|
---|
144 | protected override List<int>[] GetVectorLengths(IRandom rand) {
|
---|
145 | // length between length 40 and 80, same row always the same length
|
---|
146 | var lengths = Enumerable.Range(0, Rows).Select(i => rand.Next(40, 80)).ToList();
|
---|
147 | return new List<int>[5] {
|
---|
148 | Enumerable.Range(0, Rows).Select(i => lengths[i]).ToList(),
|
---|
149 | Enumerable.Range(0, Rows).Select(i => lengths[i]).ToList(),
|
---|
150 | Enumerable.Range(0, Rows).Select(i => lengths[i]).ToList(),
|
---|
151 | Enumerable.Range(0, Rows).Select(i => lengths[i]).ToList(),
|
---|
152 | Enumerable.Range(0, Rows).Select(i => lengths[i]).ToList()
|
---|
153 | };
|
---|
154 | }
|
---|
155 | }
|
---|
156 |
|
---|
157 | public class VectorDataTestFourC : VectorDataTestFour {
|
---|
158 | public override string Name { get { return "Vector Data Test - IV [column-constrained]: Y = X1 * sum(V1) + X2 * mean(V2)"; } }
|
---|
159 |
|
---|
160 | public VectorDataTestFourC() : base() { }
|
---|
161 | public VectorDataTestFourC(int seed) : base(seed) { }
|
---|
162 |
|
---|
163 | protected override List<int>[] GetVectorLengths(IRandom rand) {
|
---|
164 | // length between length 40 and 80; each feature is same length
|
---|
165 | int v1Length = rand.Next(40, 80);
|
---|
166 | int v2Length;
|
---|
167 | do { v2Length = rand.Next(40, 80); } while (v1Length != v2Length);
|
---|
168 | int v3Length = rand.Next(40, 80);
|
---|
169 | int v4Length;
|
---|
170 | do { v4Length = rand.Next(40, 80); } while (v3Length != v4Length);
|
---|
171 | int v5Length = rand.Next(40, 80);
|
---|
172 | return new List<int>[5] {
|
---|
173 | Enumerable.Repeat(v1Length, Rows).ToList(),
|
---|
174 | Enumerable.Repeat(v2Length, Rows).ToList(),
|
---|
175 | Enumerable.Repeat(v3Length, Rows).ToList(),
|
---|
176 | Enumerable.Repeat(v4Length, Rows).ToList(),
|
---|
177 | Enumerable.Repeat(v5Length, Rows).ToList()
|
---|
178 | };
|
---|
179 | }
|
---|
180 | }
|
---|
181 |
|
---|
182 | public class VectorDataTestFourD : VectorDataTestFour {
|
---|
183 | public override string Name { get { return "Vector Data Test - IV [unconstrained]: Y = X1 * sum(V1) + X2 * mean(V2)"; } }
|
---|
184 |
|
---|
185 | public VectorDataTestFourD() : base() { }
|
---|
186 | public VectorDataTestFourD(int seed) : base(seed) { }
|
---|
187 |
|
---|
188 | protected override List<int>[] GetVectorLengths(IRandom rand) {
|
---|
189 | // always random between 40 and 80
|
---|
190 | return new List<int>[5] {
|
---|
191 | Enumerable.Range(0, Rows).Select(i => rand.Next(40, 80)).ToList(),
|
---|
192 | Enumerable.Range(0, Rows).Select(i => rand.Next(40, 80)).ToList(),
|
---|
193 | Enumerable.Range(0, Rows).Select(i => rand.Next(40, 80)).ToList(),
|
---|
194 | Enumerable.Range(0, Rows).Select(i => rand.Next(40, 80)).ToList(),
|
---|
195 | Enumerable.Range(0, Rows).Select(i => rand.Next(40, 80)).ToList()
|
---|
196 | };
|
---|
197 | }
|
---|
198 | }
|
---|
199 | } |
---|