Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1784:

  • added export button and corrected the LoadData in RegressionInstanceProvider
  • added RegressionProblemView
File size: 3.3 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
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      double[,] values = new double[data.First().Count, data.Count];
33      for (int i = 0; i < values.GetLength(0); i++) {
34        for (int j = 0; j < values.GetLength(1); j++) {
35          values[i, j] = data[j][i];
36        }
37      }
38      return values;
39    }
40
41    public static List<double> GenerateSteps(double start, double end, double stepWidth) {
42      return Enumerable.Range(0, (int)Math.Round(((end - start) / stepWidth) + 1))
43                                      .Select(i => (start + i * stepWidth))
44                                      .ToList<double>();
45    }
46
47    public static List<double> GenerateUniformDistributedValues(int amount, double start, double end) {
48      List<double> values = new List<double>();
49      for (int i = 0; i < amount; i++) {
50        values.Add(rand.NextDouble() * (end - start) + start);
51      }
52      return values;
53    }
54
55    public static List<double> GenerateNormalDistributedValues(int amount, double mu, double sigma) {
56      List<double> values = new List<double>();
57      for (int i = 0; i < amount; i++) {
58        values.Add(NormalDistributedRandom.NextDouble(rand, mu, sigma));
59      }
60      return values;
61    }
62
63    public static List<List<double>> GenerateAllCombinationsOfValuesInLists(List<List<double>> sets) {
64
65      var combinations = new List<List<double>>();
66
67      foreach (var value in sets[0])
68        combinations.Add(new List<double> { value });
69
70      foreach (var set in sets.Skip(1))
71        combinations = AddListToCombinations(combinations, set);
72
73      combinations = (from i in Enumerable.Range(0, sets.Count)
74                      select (from list in combinations
75                              select list.ElementAt(i)).ToList<double>()).ToList<List<double>>();
76
77      return combinations;
78    }
79
80    private static List<List<double>> AddListToCombinations
81         (List<List<double>> combinations, List<double> set) {
82      var newCombinations = from value in set
83                            from combination in combinations
84                            select new List<double>(combination) { value };
85
86      return newCombinations.ToList();
87    }
88  }
89}
Note: See TracBrowser for help on using the repository browser.