#region License Information
/* HeuristicLab
* Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using HeuristicLab.Core;
using HeuristicLab.Problems.DataAnalysis;
using HeuristicLab.Random;
namespace HeuristicLab.Problems.Instances.DataAnalysis {
public class VectorDataTestOne : ArtificialRegressionDataDescriptor {
public override string Name { get { return "Vector Data Test - I (Y = X1 * sum(V1) + X2 * avg(V2)"; } }
public override string Description { get { return ""; } }
protected override string TargetVariable { get { return "Y"; } }
protected override string[] VariableNames { get { return new string[] { "X1", "X2", "X3", "V1", "V2", "Y" }; } }
protected override string[] AllowedInputVariables { get { return new string[] { "X1", "X2", "X3", "V1", "V2" }; } }
protected override int TrainingPartitionStart { get { return 0; } }
protected override int TrainingPartitionEnd { get { return 80; } }
protected override int TestPartitionStart { get { return 80; } }
protected override int TestPartitionEnd { get { return 100; } }
public int Seed { get; private set; }
public VectorDataTestOne()
: this((int)DateTime.Now.Ticks) { }
public VectorDataTestOne(int seed)
: base() {
Seed = seed;
}
protected override List> GenerateValues() { return null; }
protected override List GenerateValuesExtended() {
var rand = new MersenneTwister((uint)Seed);
double x1, x2, x3;
DoubleVector v1, v2;
double y;
var x1Column = new List(100);
var x2Column = new List(100);
var x3Column = new List(100);
var v1Column = new List(100);
var v2Column = new List(100);
var yColumn = new List(100);
for (int i = 0; i < 100; i++) {
x1 = GetRandomDouble(-2, 2, rand);
x2 = GetRandomDouble(2, 6, rand);
x3 = GetRandomDouble(0, 1, rand);
int length = rand.Next(3, 6);
v1 = GetRandomDoubleVector(-2, 2, length, rand);
v2 = GetRandomDoubleVector(3, 5, length, rand);
y = x1 * v1.Sum() + x2 * v2.Average();
x1Column.Add(x1);
x2Column.Add(x2);
x3Column.Add(x3);
v1Column.Add(v1);
v2Column.Add(v2);
yColumn.Add(y);
}
return new List { x1Column, x2Column, x3Column, v1Column, v2Column, yColumn };
}
private static double GetRandomDouble(double min, double max, IRandom rand) {
return (max - min) * rand.NextDouble() + min;
}
private static DoubleVector GetRandomDoubleVector(double min, double max, int length, IRandom rand) {
var values = new double[length];
for (int i = 0; i < values.Length; i++) {
values[i] = GetRandomDouble(min, max, rand);
}
return new DoubleVector(values);
}
}
}