Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1784:

  • added Problem.Instances.Classification project
  • added classification problem instances
  • added a class Transformer to Problem.Instances
File size: 3.0 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 List<double> GenerateSteps(double start, double end, double stepWidth) {
32      return Enumerable.Range(0, (int)Math.Round(((end - start) / stepWidth) + 1))
33                                      .Select(i => (start + i * stepWidth))
34                                      .ToList<double>();
35    }
36
37    public static List<double> GenerateUniformDistributedValues(int amount, double start, double end) {
38      List<double> values = new List<double>();
39      for (int i = 0; i < amount; i++) {
40        values.Add(rand.NextDouble() * (end - start) + start);
41      }
42      return values;
43    }
44
45    public static List<double> GenerateNormalDistributedValues(int amount, double mu, double sigma) {
46      List<double> values = new List<double>();
47      for (int i = 0; i < amount; i++) {
48        values.Add(NormalDistributedRandom.NextDouble(rand, mu, sigma));
49      }
50      return values;
51    }
52
53    public static List<List<double>> GenerateAllCombinationsOfValuesInLists(List<List<double>> sets) {
54
55      var combinations = new List<List<double>>();
56
57      foreach (var value in sets[0])
58        combinations.Add(new List<double> { value });
59
60      foreach (var set in sets.Skip(1))
61        combinations = AddListToCombinations(combinations, set);
62
63      combinations = (from i in Enumerable.Range(0, sets.Count)
64                      select (from list in combinations
65                              select list.ElementAt(i)).ToList<double>()).ToList<List<double>>();
66
67      return combinations;
68    }
69
70    private static List<List<double>> AddListToCombinations
71         (List<List<double>> combinations, List<double> set) {
72      var newCombinations = from value in set
73                            from combination in combinations
74                            select new List<double>(combination) { value };
75
76      return newCombinations.ToList();
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.