Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1784:

  • ProblemInstanceProvider are sorted now
  • the return values of ValueGenerator have been changed to !IEnumerable
  • changes have been applied to classes which are using the ValueGenerator
  • change of the cast in ProblemInstanceProviderViewGeneric and !importButton.Enable is set now in SetEnabledStateOfControls
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 IEnumerable<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    }
35
36    public static IEnumerable<double> GenerateUniformDistributedValues(int amount, double start, double end) {
37      List<double> values = new List<double>();
38      for (int i = 0; i < amount; i++) {
39        values.Add(rand.NextDouble() * (end - start) + start);
40      }
41      return values;
42    }
43
44    public static IEnumerable<double> GenerateNormalDistributedValues(int amount, double mu, double sigma) {
45      List<double> values = new List<double>();
46      for (int i = 0; i < amount; i++) {
47        values.Add(NormalDistributedRandom.NextDouble(rand, mu, sigma));
48      }
49      return values;
50    }
51
52    public static IEnumerable<IEnumerable<double>> GenerateAllCombinationsOfValuesInLists(List<List<double>> sets) {
53
54      var combinations = new List<List<double>>();
55
56      foreach (var value in sets[0])
57        combinations.Add(new List<double> { value });
58
59      foreach (var set in sets.Skip(1))
60        combinations = AddListToCombinations(combinations, set);
61
62      IEnumerable<IEnumerable<double>> res = (from i in Enumerable.Range(0, sets.Count)
63                                              select (from list in combinations
64                                                      select list.ElementAt(i)));
65
66      return res;
67    }
68
69    private static List<List<double>> AddListToCombinations
70         (List<List<double>> combinations, List<double> set) {
71      var newCombinations = from value in set
72                            from combination in combinations
73                            select new List<double>(combination) { value };
74
75      return newCombinations.ToList();
76    }
77  }
78}
Note: See TracBrowser for help on using the repository browser.