Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/18/08 11:47:35 (16 years ago)
Author:
gkronber
Message:

made evaluator static (related to ticket #168)

Location:
trunk/sources/HeuristicLab.Functions
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Functions/BakedFunctionTree.cs

    r320 r322  
    5252    private bool variablesExpanded = false;
    5353    private List<IVariable> variables;
    54     private BakedTreeEvaluator evaluator = null;
    5554
    5655    public BakedFunctionTree() {
     
    221220    }
    222221
     222    bool resetted = false;
    223223    public double Evaluate(Dataset dataset, int sampleIndex) {
    224224      FlattenVariables();
    225225      FlattenTrees();
    226       if(evaluator == null) evaluator = new BakedTreeEvaluator(linearRepresentation);
    227       return evaluator.Evaluate(dataset, sampleIndex);
     226      if(!resetted) {
     227        BakedTreeEvaluator.ResetEvaluator(linearRepresentation);
     228        resetted = true;
     229      }
     230      return BakedTreeEvaluator.Evaluate(dataset, sampleIndex);
    228231    }
    229232
  • trunk/sources/HeuristicLab.Functions/BakedTreeEvaluator.cs

    r321 r322  
    2929
    3030namespace HeuristicLab.Functions {
    31   internal class BakedTreeEvaluator {
     31  internal static class BakedTreeEvaluator {
     32    private const int MAX_TREE_SIZE = 4096;
     33
    3234    private class Instr {
    3335      public double d_arg0;
     
    3840    }
    3941
    40     private Instr[] codeArr;
    41     private int PC;
    42     private Dataset dataset;
    43     private int sampleIndex;
    44 
    45     public BakedTreeEvaluator(List<LightWeightFunction> linearRepresentation) {
    46       codeArr = new Instr[linearRepresentation.Count];
     42    private static Instr[] codeArr;
     43    private static int PC;
     44    private static Dataset dataset;
     45    private static int sampleIndex;
     46
     47
     48    static BakedTreeEvaluator() {
     49      codeArr = new Instr[MAX_TREE_SIZE];
     50      for(int i = 0; i < MAX_TREE_SIZE; i++) {
     51        codeArr[i] = new Instr();
     52      }
     53    }
     54
     55    public static void ResetEvaluator(List<LightWeightFunction> linearRepresentation) {
    4756      int i = 0;
    4857      foreach(LightWeightFunction f in linearRepresentation) {
    49         codeArr[i++] = TranslateToInstr(f);
    50       }
    51     }
    52 
    53     private Instr TranslateToInstr(LightWeightFunction f) {
    54       Instr instr = new Instr();
     58        TranslateToInstr(f, codeArr[i++]);
     59      }
     60    }
     61
     62    private static Instr TranslateToInstr(LightWeightFunction f, Instr instr) {
    5563      instr.arity = f.arity;
    5664      instr.symbol = EvaluatorSymbolTable.MapFunction(f.functionType);
     
    7078    }
    7179
    72     internal double Evaluate(Dataset dataset, int sampleIndex) {
     80    internal static double Evaluate(Dataset dataset, int sampleIndex) {
    7381      PC = 0;
    74       this.sampleIndex = sampleIndex;
    75       this.dataset = dataset;
     82      BakedTreeEvaluator.sampleIndex = sampleIndex;
     83      BakedTreeEvaluator.dataset = dataset;
    7684      return EvaluateBakedCode();
    7785    }
    7886
    79     private double EvaluateBakedCode() {
     87    private static double EvaluateBakedCode() {
    8088      Instr currInstr = codeArr[PC++];
    8189      switch(currInstr.symbol) {
Note: See TracChangeset for help on using the changeset viewer.