Changeset 11435
 Timestamp:
 10/09/14 11:25:57 (8 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/ValueGenerator.cs
r11434 r11435 37 37 /// <param name="end">The largest and last value of the sequence.</param> 38 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> 39 40 /// <returns>A sequence of values from start to end (inclusive)</returns> 40 41 [Obsolete("It is recommended to use the decimal overload to achieve a higher numerical accuracy.")] 41 public static IEnumerable<double> GenerateSteps(double start, double end, double stepWidth ) {42 public static IEnumerable<double> GenerateSteps(double start, double end, double stepWidth, bool includeEnd = false) { 42 43 //mkommend: IEnumerable.Cast fails due to boxing and unboxing of the involved types 43 44 // http://referencesource.microsoft.com/#System.Core/System/Linq/Enumerable.cs#27bb217a6d5457ec 44 45 // http://blogs.msdn.com/b/ericlippert/archive/2009/03/19/representationandidentity.aspx 45 46 46 return GenerateSteps((decimal)start, (decimal)end, (decimal)stepWidth ).Select(x => (double)x);47 return GenerateSteps((decimal)start, (decimal)end, (decimal)stepWidth, includeEnd).Select(x => (double)x); 47 48 } 48 49 … … 53 54 /// <param name="end">The largest and last value of the sequence.</param> 54 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> 55 57 /// <returns>A sequence of values from start to end</returns> 56 public static IEnumerable<decimal> GenerateSteps(decimal start, decimal end, decimal stepWidth ) {58 public static IEnumerable<decimal> GenerateSteps(decimal start, decimal end, decimal stepWidth, bool includeEnd = false) { 57 59 if (stepWidth == 0) 58 60 throw new ArgumentException("The step width cannot be zero."); … … 67 69 x += stepWidth; 68 70 } 69 } 70 71 /// <summary> 72 /// Generates a sequence of points between start and end according to given transformation 73 /// </summary> 74 /// <param name="start">The smallest and first value of the sequence.</param> 75 /// <param name="end">The largest and last value of the sequence.</param> 76 /// <param name="stepWidth">The step size between subsequent values (before transform)</param> 77 /// <param name="transform">The transform function</param> 78 /// <returns></returns> 79 [Obsolete("It is recommended to use the decimal overload to achieve a higher numerical accuracy.")] 80 public static IEnumerable<double> GenerateSteps(double start, double end, double stepWidth, Func<double, double> transform) { 81 return GenerateSteps(start,end, stepWidth).Select(transform); 82 } 83 84 /// <summary> 85 /// Generates a sequence of points between start and end according to given transformation 86 /// </summary> 87 /// <param name="start">The smallest and first value of the sequence.</param> 88 /// <param name="end">The largest and last value of the sequence.</param> 89 /// <param name="stepWidth">The step size between subsequent values (before transform)</param> 90 /// <param name="transform">The transform function</param> 91 /// <returns></returns> 92 public static IEnumerable<decimal> GenerateSteps(decimal start, decimal end, decimal stepWidth, Func<decimal, decimal> transform) { 93 return GenerateSteps(start, end, stepWidth).Select(transform); 71 if (x  stepWidth < end && includeEnd) yield return end; 94 72 } 95 73
Note: See TracChangeset
for help on using the changeset viewer.