Free cookie consent management tool by TermsFeed Policy Generator

source: branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Benchmarks/3.4/Generator/RegressionBenchmark.cs @ 7095

Last change on this file since 7095 was 7095, checked in by sforsten, 12 years ago

#1669: Input variables of Korn functions have been adjusted according to the description.

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