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

Last change on this file since 17365 was 17365, checked in by pfleck, 11 months ago

#3040 Added explicit vector types to avoid type-missmatches when representing vectors as IList<T>, List<T> or IReadOnlyList<T>.

File size: 3.7 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.Problems.DataAnalysis;
28using HeuristicLab.Random;
29
30namespace HeuristicLab.Problems.Instances.DataAnalysis {
31  public class VectorDataTestOne : ArtificialRegressionDataDescriptor {
32
33    public override string Name { get { return "Vector Data Test - I (Y = X1 * sum(V1) + X2 * avg(V2)"; } }
34    public override string Description { get { return ""; } }
35
36    protected override string TargetVariable { get { return "Y"; } }
37    protected override string[] VariableNames { get { return new string[] { "X1", "X2", "X3", "V1", "V2", "Y" }; } }
38    protected override string[] AllowedInputVariables { get { return new string[] { "X1", "X2", "X3", "V1", "V2" }; } }
39    protected override int TrainingPartitionStart { get { return 0; } }
40    protected override int TrainingPartitionEnd { get { return 80; } }
41    protected override int TestPartitionStart { get { return 80; } }
42    protected override int TestPartitionEnd { get { return 100; } }
43
44    public int Seed { get; private set; }
45
46    public VectorDataTestOne()
47      : this((int)DateTime.Now.Ticks) { }
48    public VectorDataTestOne(int seed)
49      : base() {
50      Seed = seed;
51    }
52
53
54    protected override List<List<double>> GenerateValues() { return null; }
55    protected override List<IList> GenerateValuesExtended() {
56      var rand = new MersenneTwister((uint)Seed);
57
58      double x1, x2, x3;
59      DoubleVector v1, v2;
60      double y;
61
62      var x1Column = new List<double>(100);
63      var x2Column = new List<double>(100);
64      var x3Column = new List<double>(100);
65      var v1Column = new List<DoubleVector>(100);
66      var v2Column = new List<DoubleVector>(100);
67      var yColumn = new List<double>(100);
68
69      for (int i = 0; i < 100; i++) {
70        x1 = GetRandomDouble(-2, 2, rand);
71        x2 = GetRandomDouble(2, 6, rand);
72        x3 = GetRandomDouble(0, 1, rand);
73        int length = rand.Next(3, 6);
74        v1 = GetRandomDoubleVector(-2, 2, length, rand);
75        v2 = GetRandomDoubleVector(3, 5, length, rand);
76        y = x1 * v1.Sum() + x2 * v2.Average();
77
78        x1Column.Add(x1);
79        x2Column.Add(x2);
80        x3Column.Add(x3);
81        v1Column.Add(v1);
82        v2Column.Add(v2);
83        yColumn.Add(y);
84      }
85
86      return new List<IList> { x1Column, x2Column, x3Column, v1Column, v2Column, yColumn };
87    }
88
89
90    private static double GetRandomDouble(double min, double max, IRandom rand) {
91      return (max - min) * rand.NextDouble() + min;
92    }
93    private static DoubleVector GetRandomDoubleVector(double min, double max, int length, IRandom rand) {
94      var values = new double[length];
95      for (int i = 0; i < values.Length; i++) {
96        values[i] = GetRandomDouble(min, max, rand);
97      }
98      return new DoubleVector(values);
99    }
100  }
101}
Note: See TracBrowser for help on using the repository browser.