Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/ValueGenerator.cs @ 7664

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

#1784:

  • added Keijzer, Korns, Vladislavleva und Nguyen regression problem instances
  • changes have been made in the ProblemView. Some parts have been replaced with views from Problems.Instances.Views
File size: 3.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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
23using System;
24using System.Collections.Generic;
25using System.Linq;
26using HeuristicLab.Random;
27namespace HeuristicLab.Problems.Instances.Regression {
28  public class ValueGenerator {
29    protected static FastRandom rand = new FastRandom();
30
31    public static double[,] Transformation(List<List<double>> data) {
32      if (!data.All(x => x.Count.Equals(data.First().Count)))
33        throw new ArgumentException("Can't create jagged array.");
34      double[,] values = new double[data.First().Count, data.Count];
35      for (int i = 0; i < values.GetLength(0); i++) {
36        for (int j = 0; j < values.GetLength(1); j++) {
37          values[i, j] = data[j][i];
38        }
39      }
40      return values;
41    }
42
43    public static List<double> GenerateSteps(double start, double end, double stepWidth) {
44      return Enumerable.Range(0, (int)Math.Round(((end - start) / stepWidth) + 1))
45                                      .Select(i => (start + i * stepWidth))
46                                      .ToList<double>();
47    }
48
49    public static List<double> GenerateUniformDistributedValues(int amount, double start, double end) {
50      List<double> values = new List<double>();
51      for (int i = 0; i < amount; i++) {
52        values.Add(rand.NextDouble() * (end - start) + start);
53      }
54      return values;
55    }
56
57    public static List<double> GenerateNormalDistributedValues(int amount, double mu, double sigma) {
58      List<double> values = new List<double>();
59      for (int i = 0; i < amount; i++) {
60        values.Add(NormalDistributedRandom.NextDouble(rand, mu, sigma));
61      }
62      return values;
63    }
64
65    public static List<List<double>> GenerateAllCombinationsOfValuesInLists(List<List<double>> sets) {
66
67      var combinations = new List<List<double>>();
68
69      foreach (var value in sets[0])
70        combinations.Add(new List<double> { value });
71
72      foreach (var set in sets.Skip(1))
73        combinations = AddListToCombinations(combinations, set);
74
75      combinations = (from i in Enumerable.Range(0, sets.Count)
76                      select (from list in combinations
77                              select list.ElementAt(i)).ToList<double>()).ToList<List<double>>();
78
79      return combinations;
80    }
81
82    private static List<List<double>> AddListToCombinations
83         (List<List<double>> combinations, List<double> set) {
84      var newCombinations = from value in set
85                            from combination in combinations
86                            select new List<double>(combination) { value };
87
88      return newCombinations.ToList();
89    }
90  }
91}
Note: See TracBrowser for help on using the repository browser.