Changeset 12292 for trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/ValueGenerator.cs
- Timestamp:
- 04/07/15 14:56:24 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/ValueGenerator.cs
r12012 r12292 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using System.Linq; 25 using HeuristicLab.Common;26 24 using HeuristicLab.Random; 27 25 28 26 namespace HeuristicLab.Problems.Instances.DataAnalysis { 29 publicstatic class ValueGenerator {27 internal static class ValueGenerator { 30 28 private static FastRandom rand = new FastRandom(); 31 32 /// <summary>33 /// Generates a sequence of evenly spaced points by returning the start value and adding the stepwidth until the end is reached or surpassed.34 ///35 /// </summary>36 /// <param name="start">The smallest and first value of the sequence.</param>37 /// <param name="end">The largest and last value of the sequence.</param>38 /// <param name="stepWidth">The step size between subsequent values.</param>39 /// <param name="includeEnd">Determines if the end should be included in the sequence regardless if the end is divisible by the stepwidth.</param>40 /// <returns>A sequence of values from start to end (inclusive)</returns>41 [Obsolete("It is recommended to use the decimal overload to achieve a higher numerical accuracy.")]42 public static IEnumerable<double> GenerateSteps(double start, double end, double stepWidth, bool includeEnd = false) {43 //mkommend: IEnumerable.Cast fails due to boxing and unboxing of the involved types44 // http://referencesource.microsoft.com/#System.Core/System/Linq/Enumerable.cs#27bb217a6d5457ec45 // http://blogs.msdn.com/b/ericlippert/archive/2009/03/19/representation-and-identity.aspx46 47 return GenerateSteps((decimal)start, (decimal)end, (decimal)stepWidth, includeEnd).Select(x => (double)x);48 }49 50 /// <summary>51 /// Generates a sequence of evenly spaced points by returning the start value and adding the stepwidth until the end is reached or surpassed.52 /// </summary>53 /// <param name="start">The smallest and first value of the sequence.</param>54 /// <param name="end">The largest and last value of the sequence.</param>55 /// <param name="stepWidth">The step size between subsequent values.</param>56 /// /// <param name="includeEnd">Determines if the end should be included in the sequence regardless if the end is divisible by the stepwidth.</param>57 /// <returns>A sequence of values from start to end</returns>58 public static IEnumerable<decimal> GenerateSteps(decimal start, decimal end, decimal stepWidth, bool includeEnd = false) {59 if (stepWidth == 0)60 throw new ArgumentException("The step width cannot be zero.");61 if (start < end && stepWidth < 0)62 throw new ArgumentException("The step width must be larger than zero for increasing sequences (start < end).");63 if (start > end && stepWidth > 0)64 throw new ArgumentException("The step width must be smaller than zero for decreasing sequences (start > end).");65 66 decimal x = start;67 while (x <= end) {68 yield return x;69 x += stepWidth;70 }71 if (x - stepWidth < end && includeEnd) yield return end;72 }73 29 74 30 /// <summary> … … 100 56 } 101 57 102 // iterative approach 58 // Generate the cartesian product. 59 // The result is transposed, therefore the inner lists represent a column of values instead of a combination-pair. 103 60 public static IEnumerable<IEnumerable<double>> GenerateAllCombinationsOfValuesInLists(List<List<double>> lists) { 104 61 List<List<double>> allCombinations = new List<List<double>>();
Note: See TracChangeset
for help on using the changeset viewer.