Changeset 322 for trunk/sources/HeuristicLab.Functions
- Timestamp:
- 06/18/08 11:47:35 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Functions
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Functions/BakedFunctionTree.cs
r320 r322 52 52 private bool variablesExpanded = false; 53 53 private List<IVariable> variables; 54 private BakedTreeEvaluator evaluator = null;55 54 56 55 public BakedFunctionTree() { … … 221 220 } 222 221 222 bool resetted = false; 223 223 public double Evaluate(Dataset dataset, int sampleIndex) { 224 224 FlattenVariables(); 225 225 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); 228 231 } 229 232 -
trunk/sources/HeuristicLab.Functions/BakedTreeEvaluator.cs
r321 r322 29 29 30 30 namespace HeuristicLab.Functions { 31 internal class BakedTreeEvaluator { 31 internal static class BakedTreeEvaluator { 32 private const int MAX_TREE_SIZE = 4096; 33 32 34 private class Instr { 33 35 public double d_arg0; … … 38 40 } 39 41 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) { 47 56 int i = 0; 48 57 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) { 55 63 instr.arity = f.arity; 56 64 instr.symbol = EvaluatorSymbolTable.MapFunction(f.functionType); … … 70 78 } 71 79 72 internal double Evaluate(Dataset dataset, int sampleIndex) {80 internal static double Evaluate(Dataset dataset, int sampleIndex) { 73 81 PC = 0; 74 this.sampleIndex = sampleIndex;75 this.dataset = dataset;82 BakedTreeEvaluator.sampleIndex = sampleIndex; 83 BakedTreeEvaluator.dataset = dataset; 76 84 return EvaluateBakedCode(); 77 85 } 78 86 79 private double EvaluateBakedCode() {87 private static double EvaluateBakedCode() { 80 88 Instr currInstr = codeArr[PC++]; 81 89 switch(currInstr.symbol) {
Note: See TracChangeset
for help on using the changeset viewer.