Ignore:
Timestamp:
07/07/19 23:47:53 (3 years ago)
Author:
mkommend
Message:

#2966: Merged 16629, 16631, 16646, 16740, 16743, 16757, 16758, 16769, 16822 to stable.

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs

    r17097 r17100  
    6969    #endregion
    7070
    71     public Interval GetSymbolicExressionTreeInterval(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows = null) {
     71    public Interval GetSymbolicExpressionTreeInterval(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows = null) {
    7272      var variableRanges = DatasetUtil.GetVariableRanges(dataset, rows);
    73       return GetSymbolicExressionTreeInterval(tree, variableRanges);
    74     }
    75 
    76     public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, IDataset dataset,
    77       out Dictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals, IEnumerable<int> rows = null) {
     73      return GetSymbolicExpressionTreeInterval(tree, variableRanges);
     74    }
     75
     76    public Interval GetSymbolicExpressionTreeIntervals(ISymbolicExpressionTree tree, IDataset dataset,
     77      out IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals, IEnumerable<int> rows = null) {
    7878      var variableRanges = DatasetUtil.GetVariableRanges(dataset, rows);
    79       return GetSymbolicExressionTreeIntervals(tree, variableRanges, out nodeIntervals);
    80     }
    81 
    82     public Interval GetSymbolicExressionTreeInterval(ISymbolicExpressionTree tree, Dictionary<string, Interval> variableRanges) {
     79      return GetSymbolicExpressionTreeIntervals(tree, variableRanges, out nodeIntervals);
     80    }
     81
     82    public Interval GetSymbolicExpressionTreeInterval(ISymbolicExpressionTree tree, IDictionary<string, Interval> variableRanges) {
    8383      lock (syncRoot) {
    8484        EvaluatedSolutions++;
     
    8888      var outputInterval = Evaluate(instructions, ref instructionCount);
    8989
    90       return outputInterval;
    91     }
    92 
    93 
    94     public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree,
    95       Dictionary<string, Interval> variableRanges, out Dictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals) {
     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);
     95    }
     96
     97
     98    public Interval GetSymbolicExpressionTreeIntervals(ISymbolicExpressionTree tree,
     99      IDictionary<string, Interval> variableRanges, out IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals) {
    96100      lock (syncRoot) {
    97101        EvaluatedSolutions++;
     
    102106      var outputInterval = Evaluate(instructions, ref instructionCount, intervals);
    103107
    104       nodeIntervals = intervals;
    105 
    106       return outputInterval;
    107     }
    108 
    109 
    110     private static Instruction[] PrepareInterpreterState(ISymbolicExpressionTree tree, Dictionary<string, Interval> variableRanges) {
     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);
     123    }
     124
     125
     126    private static Instruction[] PrepareInterpreterState(ISymbolicExpressionTree tree, IDictionary<string, Interval> variableRanges) {
    111127      if (variableRanges == null)
    112128        throw new ArgumentNullException("No variablew ranges are present!", nameof(variableRanges));
     
    125141    }
    126142
    127     private Interval Evaluate(Instruction[] instructions, ref int instructionCounter, Dictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals = null) {
     143    private Interval Evaluate(Instruction[] instructions, ref int instructionCounter, IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals = null) {
    128144      Instruction currentInstr = instructions[instructionCounter];
    129145      //Use ref parameter, because the tree will be iterated through recursively from the left-side branch to the right side
     
    200216            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    201217            result = Interval.Tangens(argumentInterval);
     218            break;
     219          }
     220        case OpCodes.Tanh: {
     221            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
     222            result = Interval.HyperbolicTangent(argumentInterval);
    202223            break;
    203224          }
Note: See TracChangeset for help on using the changeset viewer.