#region License Information
/* HeuristicLab
* Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using HeuristicLab.Random;
namespace HeuristicLab.Problems.Instances.Regression {
public class ValueGenerator {
protected static FastRandom rand = new FastRandom();
public static double[,] Transformation(List> data) {
double[,] values = new double[data.First().Count, data.Count];
for (int i = 0; i < values.GetLength(0); i++) {
for (int j = 0; j < values.GetLength(1); j++) {
values[i, j] = data[j][i];
}
}
return values;
}
public static List GenerateSteps(double start, double end, double stepWidth) {
return Enumerable.Range(0, (int)Math.Round(((end - start) / stepWidth) + 1))
.Select(i => (start + i * stepWidth))
.ToList();
}
public static List GenerateUniformDistributedValues(int amount, double start, double end) {
List values = new List();
for (int i = 0; i < amount; i++) {
values.Add(rand.NextDouble() * (end - start) + start);
}
return values;
}
public static List GenerateNormalDistributedValues(int amount, double mu, double sigma) {
List values = new List();
for (int i = 0; i < amount; i++) {
values.Add(NormalDistributedRandom.NextDouble(rand, mu, sigma));
}
return values;
}
public static List> GenerateAllCombinationsOfValuesInLists(List> sets) {
var combinations = new List>();
foreach (var value in sets[0])
combinations.Add(new List { value });
foreach (var set in sets.Skip(1))
combinations = AddListToCombinations(combinations, set);
combinations = (from i in Enumerable.Range(0, sets.Count)
select (from list in combinations
select list.ElementAt(i)).ToList()).ToList>();
return combinations;
}
private static List> AddListToCombinations
(List> combinations, List set) {
var newCombinations = from value in set
from combination in combinations
select new List(combination) { value };
return newCombinations.ToList();
}
}
}