Changeset 16403


Ignore:
Timestamp:
12/19/18 10:56:29 (2 months ago)
Author:
chaider
Message:

#2966 Changed variable names

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2966_interval_calculation/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs

    r16393 r16403  
    7070
    7171    public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows = null) {
    72       var intervalBoundaries = DatasetUtil.GetVariableRanges(dataset, rows);
    73       return GetSymbolicExressionTreeIntervals(tree, intervalBoundaries);
     72      var variableRanges = DatasetUtil.GetVariableRanges(dataset, rows);
     73      return GetSymbolicExressionTreeIntervals(tree, variableRanges);
    7474    }
    7575
    7676    public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, IDataset dataset,
    7777      out Dictionary<ISymbolicExpressionTreeNode, Interval> intervals, IEnumerable<int> rows = null) {
    78       var intervalBoundaries = DatasetUtil.GetVariableRanges(dataset, rows);
    79       return GetSymbolicExressionTreeIntervals(tree, intervalBoundaries, out intervals);
    80     }
    81 
    82     public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, Dictionary<string, Interval> customIntervals) {
     78      var variableRanges = DatasetUtil.GetVariableRanges(dataset, rows);
     79      return GetSymbolicExressionTreeIntervals(tree, variableRanges, out intervals);
     80    }
     81
     82    public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, Dictionary<string, Interval> customIntervalsForVariables) {
    8383      lock (syncRoot) {
    8484        EvaluatedSolutions++;
    8585      }
    8686      int instructionCount = 0;
    87       var instructions = PrepareInterpreterState(tree, customIntervals);
     87      var instructions = PrepareInterpreterState(tree, customIntervalsForVariables);
    8888      var outputInterval = Evaluate(instructions, ref instructionCount);
    8989
     
    9393
    9494    public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree,
    95       Dictionary<string, Interval> customIntervals, out Dictionary<ISymbolicExpressionTreeNode, Interval> intervals) {
     95      Dictionary<string, Interval> customIntervalsForVariables, out Dictionary<ISymbolicExpressionTreeNode, Interval> intervals) {
    9696      lock (syncRoot) {
    9797        EvaluatedSolutions++;
     
    9999      int instructionCount = 0;
    100100      intervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>();
    101       var instructions = PrepareInterpreterState(tree, customIntervals);
     101      var instructions = PrepareInterpreterState(tree, customIntervalsForVariables);
    102102      var outputInterval = Evaluate(instructions, ref instructionCount, intervals);
    103103
     
    106106
    107107
    108     private static Instruction[] PrepareInterpreterState(ISymbolicExpressionTree tree, Dictionary<string, Interval> customIntervals) {
     108    private static Instruction[] PrepareInterpreterState(ISymbolicExpressionTree tree, Dictionary<string, Interval> customIntervalsForVariables) {
    109109      Instruction[] code = SymbolicExpressionTreeCompiler.Compile(tree, OpCodes.MapSymbolToOpCode);
    110110
    111       if (customIntervals == null)
    112         throw new ArgumentException("No interval ranges are present!", nameof(customIntervals));
     111      if (customIntervalsForVariables == null)
     112        throw new ArgumentException("No interval ranges are present!", nameof(customIntervalsForVariables));
    113113
    114114      foreach (var variable in tree.IterateNodesPrefix().OfType<VariableTreeNode>().Select(n => n.VariableName).Distinct()) {
    115         if (!customIntervals.ContainsKey(variable)) throw new InvalidOperationException($"No ranges for variable {variable} is present");
     115        if (!customIntervalsForVariables.ContainsKey(variable)) throw new InvalidOperationException($"No ranges for variable {variable} is present");
    116116      }
    117117
    118118      foreach (Instruction instr in code.Where(i => i.opCode == OpCodes.Variable)) {
    119119        var variableTreeNode = (VariableTreeNode)instr.dynamicNode;
    120         instr.data = customIntervals[variableTreeNode.VariableName];
     120        instr.data = customIntervalsForVariables[variableTreeNode.VariableName];
    121121      }
    122122      return code;
     
    130130        //Variables, Constants, ...
    131131        case OpCodes.Variable: {
    132             if (intervals != null)
    133               intervals.Add(currentInstr.dynamicNode, (Interval)currentInstr.data);
    134132            var variableTreeNode = (VariableTreeNode)currentInstr.dynamicNode;
    135133            var variableWeight = variableTreeNode.Weight;
    136 
    137             return Interval.Multiply((Interval)currentInstr.data, new Interval(variableWeight, variableWeight));
     134            var varibleWeightInterval = new Interval(variableWeight, variableWeight);
     135
     136            result = Interval.Multiply((Interval)currentInstr.data, varibleWeightInterval);
     137            break;
    138138          }
    139139        case OpCodes.Constant: {
    140140            var constTreeNode = (ConstantTreeNode)currentInstr.dynamicNode;
    141             var inter = new Interval(constTreeNode.Value, constTreeNode.Value);
    142             if (intervals != null)
    143               intervals.Add(currentInstr.dynamicNode, inter);
    144             return inter;
     141            result = new Interval(constTreeNode.Value, constTreeNode.Value);
     142            break;
    145143          }
    146144        //Elementary arithmetic rules
Note: See TracChangeset for help on using the changeset viewer.