Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/06/14 00:38:34 (10 years ago)
Author:
bburlacu
Message:

#2236: GenerateSteps: added the ability to generate sequences on negative or decreasing intervals.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/ValueGenerator.cs

    r11313 r11348  
    3838    /// <returns>An sequence of values from start to end (inclusive)</returns>
    3939    public static IEnumerable<double> GenerateSteps(double start, double end, double stepWidth) {
    40       if (start > end) throw new ArgumentException("start must be less than or equal end.");
    41       if (stepWidth <= 0) throw new ArgumentException("stepwith must be larger than zero.", "stepWidth");
     40      if (stepWidth.IsAlmost(0))
     41        throw new ArgumentException("The step width cannot be zero.");
     42      if (start < end && stepWidth < 0)
     43        throw new ArgumentException("The step width must be larger than zero for increasing sequences (start < end).");
     44      if (start > end && stepWidth > 0)
     45        throw new ArgumentException("The step width must be smaller than zero for decreasing sequences (start > end).");
    4246      double x = start;
    4347      // x<=end could skip the last value because of numerical problems
     
    6872    /// <returns></returns>
    6973    public static IEnumerable<double> GenerateSteps(double start, double end, double stepWidth, Func<double, double> transform) {
    70       return GenerateSteps(start, end, stepWidth).Select(transform).Where(x => x < end || x.IsAlmost(end));
     74      return GenerateSteps(start, end, stepWidth).Select(transform);
    7175    }
    7276
Note: See TracChangeset for help on using the changeset viewer.