Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/22/10 18:41:07 (14 years ago)
Author:
gkronber
Message:

Minor improvements. #938 (Data types and operators for regression problems)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Symbolic/SimpleArithmeticExpressionInterpreter.cs

    r3462 r3491  
    3333  [StorableClass]
    3434  [Item("SimpleArithmeticExpressionInterpreter", "Interpreter for arithmetic symbolic expression trees including function calls.")]
     35  // not thread safe!
    3536  public class SimpleArithmeticExpressionInterpreter : Item, ISymbolicExpressionTreeInterpreter {
    3637    private class OpCodes {
     
    4546    }
    4647
     48    private const int ARGUMENT_STACK_SIZE = 1024;
    4749    private Dataset dataset;
    4850    private int row;
     
    5860        this.row = row;
    5961        pc = 0;
    60         argumentStack.Clear();
     62        argStackPointer = 0;
    6163        var estimatedValue = Evaluate();
    6264        if (double.IsNaN(estimatedValue) || double.IsInfinity(estimatedValue)) yield return 0.0;
     
    8587    }
    8688
    87     private Stack<List<double>> argumentStack = new Stack<List<double>>();
     89    private double[] argumentStack = new double[ARGUMENT_STACK_SIZE];
     90    private int argStackPointer;
     91
    8892    public double Evaluate() {
    8993      var currentInstr = code[pc++];
     
    118122          }
    119123        case OpCodes.Call: {
    120             // save current arguments
    121             List<double> arguments = new List<double>();
    122124            // evaluate sub-trees
     125            // push on argStack in reverse order
    123126            for (int i = 0; i < currentInstr.nArguments; i++) {
    124               arguments.Add(Evaluate());
     127              argumentStack[argStackPointer + currentInstr.nArguments - i] = Evaluate();
     128              argStackPointer++;
    125129            }
    126             argumentStack.Push(arguments);
     130
    127131            // save the pc
    128132            int nextPc = pc;
     
    131135            // evaluate the function
    132136            double v = Evaluate();
    133             argumentStack.Pop();
     137
     138            // decrease the argument stack pointer by the number of arguments pushed
     139            // to set the argStackPointer back to the original location
     140            argStackPointer -= currentInstr.nArguments;
     141
    134142            // restore the pc => evaluation will continue at point after my subtrees 
    135143            pc = nextPc;
     
    137145          }
    138146        case OpCodes.Arg: {
    139             return argumentStack.Peek()[currentInstr.iArg0];
     147            return argumentStack[argStackPointer - currentInstr.iArg0];
    140148          }
    141149        case OpCodes.Variable: {
Note: See TracChangeset for help on using the changeset viewer.