- Timestamp:
- 11/08/08 13:55:59 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.Boolean/BooleanTreeInterpreter.cs
r720 r722 37 37 private int targetVariable; 38 38 private int currentRow; 39 private Dictionary<IFunctionTree, int> cachedIndex = new Dictionary<IFunctionTree, int>(); 39 40 40 41 public void Reset(Dataset dataset, IFunctionTree tree, int targetVariable) { … … 42 43 this.tree = tree; 43 44 this.targetVariable = targetVariable; 45 cachedIndex.Clear(); 44 46 } 45 47 46 48 internal int GetNumberMatchingInstances(int start, int end) { 47 49 int matchingInstances = 0; 48 for (int i = start; i < end; i++) {50 for (int i = start; i < end; i++) { 49 51 currentRow = i; 50 52 int result = Step(tree) ? 1 : 0; 51 if (result - dataset.GetValue(i, targetVariable) < EPSILON) matchingInstances++;53 if (Math.Abs(result - dataset.GetValue(i, targetVariable)) < EPSILON) matchingInstances++; 52 54 } 53 55 return matchingInstances; … … 56 58 internal bool Step(IFunctionTree tree) { 57 59 int symbol = SymbolTable.MapFunction(tree.Function); 58 switch (symbol) {59 case SymbolTable.AND: return Step(tree.SubTrees[0]) & Step(tree.SubTrees[0]);60 case SymbolTable.OR: return Step(tree.SubTrees[0]) | Step(tree.SubTrees[0]);60 switch (symbol) { 61 case SymbolTable.AND: return Step(tree.SubTrees[0]) && Step(tree.SubTrees[1]); 62 case SymbolTable.OR: return Step(tree.SubTrees[0]) || Step(tree.SubTrees[1]); 61 63 case SymbolTable.NOT: return !Step(tree.SubTrees[0]); 62 64 case SymbolTable.XOR: return Step(tree.SubTrees[0]) ^ Step(tree.SubTrees[1]); 63 case SymbolTable.NAND: return !(Step(tree.SubTrees[0]) & Step(tree.SubTrees[0]));64 case SymbolTable.NOR: return !(Step(tree.SubTrees[0]) | Step(tree.SubTrees[0]));65 case SymbolTable.NAND: return !(Step(tree.SubTrees[0]) && Step(tree.SubTrees[1])); 66 case SymbolTable.NOR: return !(Step(tree.SubTrees[0]) || Step(tree.SubTrees[1])); 65 67 case SymbolTable.VARIABLE: 66 int index = ((ConstrainedIntData)tree.LocalVariables.ToArray()[0].Value).Data; 67 if(dataset.GetValue(currentRow, targetVariable) == 0.0) return false; 68 else return true; 68 int index; 69 if (cachedIndex.TryGetValue(tree, out index)==false) { 70 } else { 71 index = ((ConstrainedIntData)tree.LocalVariables.ToArray()[0].Value).Data; 72 cachedIndex[tree] = index; 73 } 74 return dataset.GetValue(currentRow, index) != 0.0; 69 75 case SymbolTable.UNKNOWN: 70 76 default:
Note: See TracChangeset
for help on using the changeset viewer.