Changeset 16629


Ignore:
Timestamp:
02/28/19 14:02:15 (3 months ago)
Author:
gkronber
Message:

#2971: added extra checks to make sure that IntervalInterpreter always returns a valid interval

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs

    r16565 r16629  
    8888      var outputInterval = Evaluate(instructions, ref instructionCount);
    8989
    90       return outputInterval;
     90      // because of numerical errors the bounds might be incorrect
     91      if (outputInterval.LowerBound <= outputInterval.UpperBound)
     92        return outputInterval;
     93      else
     94        return new Interval(outputInterval.UpperBound, outputInterval.LowerBound);
    9195    }
    9296
     
    102106      var outputInterval = Evaluate(instructions, ref instructionCount, intervals);
    103107
    104       nodeIntervals = intervals;
    105 
    106       return outputInterval;
     108      // fix incorrect intervals if necessary (could occur because of numerical errors)
     109      nodeIntervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>();
     110      foreach(var kvp in intervals) {
     111        var interval = kvp.Value;
     112        if (interval.IsInfiniteOrUndefined || interval.LowerBound <= interval.UpperBound)
     113          nodeIntervals.Add(kvp.Key, interval);
     114        else
     115          nodeIntervals.Add(kvp.Key, new Interval(interval.UpperBound, interval.LowerBound));
     116      }
     117
     118      // because of numerical errors the bounds might be incorrect
     119      if (outputInterval.IsInfiniteOrUndefined || outputInterval.LowerBound <= outputInterval.UpperBound)
     120        return outputInterval;
     121      else
     122        return new Interval(outputInterval.UpperBound, outputInterval.LowerBound);
    107123    }
    108124
Note: See TracChangeset for help on using the changeset viewer.