1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2011 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.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using HeuristicLab.Common;
|
---|
26 | using HeuristicLab.Data;
|
---|
27 | using HeuristicLab.Random;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Problems.DataAnalysis.Benchmarks {
|
---|
30 | public abstract class RegressionBenchmark : Benchmark, IRegressionBenchmarkProblemDataGenerator {
|
---|
31 |
|
---|
32 | #region properties
|
---|
33 | protected string targetVariable;
|
---|
34 | protected List<string> inputVariables;
|
---|
35 | protected IntRange trainingPartition;
|
---|
36 | protected IntRange testPartition;
|
---|
37 |
|
---|
38 | public string TargetVariable {
|
---|
39 | get { return targetVariable; }
|
---|
40 | }
|
---|
41 |
|
---|
42 | public List<string> InputVariable {
|
---|
43 | get { return inputVariables; }
|
---|
44 | }
|
---|
45 |
|
---|
46 | public IntRange TrainingPartition {
|
---|
47 | get { return trainingPartition; }
|
---|
48 | }
|
---|
49 |
|
---|
50 | public IntRange TestPartition {
|
---|
51 | get { return testPartition; }
|
---|
52 | }
|
---|
53 | #endregion
|
---|
54 |
|
---|
55 | protected static FastRandom rand = new FastRandom();
|
---|
56 |
|
---|
57 | protected RegressionBenchmark() { }
|
---|
58 | protected RegressionBenchmark(RegressionBenchmark original, Cloner cloner)
|
---|
59 | : base(original, cloner) {
|
---|
60 | }
|
---|
61 |
|
---|
62 | public abstract IDataAnalysisProblemData GenerateProblemData();
|
---|
63 |
|
---|
64 | public static List<double> GenerateSteps(DoubleRange range, double stepWidth) {
|
---|
65 | return Enumerable.Range(0, (int)Math.Round(((range.End - range.Start) / stepWidth) + 1))
|
---|
66 | .Select(i => (range.Start + i * stepWidth))
|
---|
67 | .ToList<double>();
|
---|
68 | }
|
---|
69 |
|
---|
70 | public static List<double> GenerateUniformDistributedValues(int amount, DoubleRange range) {
|
---|
71 | List<double> values = new List<double>();
|
---|
72 | for (int i = 0; i < amount; i++) {
|
---|
73 | values.Add(rand.NextDouble() * (range.End - range.Start) + range.Start);
|
---|
74 | }
|
---|
75 | return values;
|
---|
76 | }
|
---|
77 |
|
---|
78 | public static List<double> GenerateNormalDistributedValues(int amount, double mu, double sigma) {
|
---|
79 | List<double> values = new List<double>();
|
---|
80 | for (int i = 0; i < amount; i++) {
|
---|
81 | values.Add(NormalDistributedRandom.NextDouble(rand, mu, sigma));
|
---|
82 | }
|
---|
83 | return values;
|
---|
84 | }
|
---|
85 |
|
---|
86 | public static List<List<double>> GenerateAllCombinationsOfValuesInLists(List<List<double>> sets) {
|
---|
87 |
|
---|
88 | var combinations = new List<List<double>>();
|
---|
89 |
|
---|
90 | foreach (var value in sets[0])
|
---|
91 | combinations.Add(new List<double> { value });
|
---|
92 |
|
---|
93 | foreach (var set in sets.Skip(1))
|
---|
94 | combinations = AddListToCombinations(combinations, set);
|
---|
95 |
|
---|
96 | combinations = (from i in Enumerable.Range(0, sets.Count)
|
---|
97 | select (from list in combinations
|
---|
98 | select list.ElementAt(i)).ToList<double>()).ToList<List<double>>();
|
---|
99 |
|
---|
100 | return combinations;
|
---|
101 | }
|
---|
102 |
|
---|
103 | private static List<List<double>> AddListToCombinations
|
---|
104 | (List<List<double>> combinations, List<double> set) {
|
---|
105 | var newCombinations = from value in set
|
---|
106 | from combination in combinations
|
---|
107 | select new List<double>(combination) { value };
|
---|
108 |
|
---|
109 | return newCombinations.ToList();
|
---|
110 | }
|
---|
111 |
|
---|
112 | public static List<double> GenerateUniformIntegerDistribution(List<int> classes, int amount) {
|
---|
113 | List<double> values = new List<double>();
|
---|
114 | for (int i = 0; i < amount; i++) {
|
---|
115 | values.Add(rand.Next(0, classes.Count));
|
---|
116 | }
|
---|
117 | return values;
|
---|
118 | }
|
---|
119 | }
|
---|
120 | }
|
---|