- Timestamp:
- 08/03/09 12:26:42 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/TreeEvaluatorBase.cs
r2174 r2222 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq;25 using System.Text;26 24 using HeuristicLab.Core; 27 using System.Xml;28 using System.Diagnostics;29 25 using HeuristicLab.DataAnalysis; 26 using HeuristicLab.GP.Interfaces; 30 27 31 28 namespace HeuristicLab.GP.StructureIdentification { … … 44 41 public byte arity; 45 42 public byte symbol; 46 public IFunction function;47 43 } 48 44 … … 60 56 minValue = mean - punishmentFactor * range; 61 57 62 BakedFunctionTree bakedTree = functionTree as BakedFunctionTree; 63 if (bakedTree == null) throw new ArgumentException("TreeEvaluators can only evaluate BakedFunctionTrees"); 64 65 List<LightWeightFunction> linearRepresentation = bakedTree.LinearRepresentation; 66 codeArr = new Instr[linearRepresentation.Count]; 58 codeArr = new Instr[functionTree.GetSize()]; 67 59 int i = 0; 68 foreach ( LightWeightFunction f in linearRepresentation) {69 codeArr[i++] = TranslateToInstr( f);60 foreach (IFunctionTree tree in IteratePrefix(functionTree)) { 61 codeArr[i++] = TranslateToInstr(tree); 70 62 } 71 63 } 72 64 73 private Instr TranslateToInstr(LightWeightFunction f) { 65 private IEnumerable<IFunctionTree> IteratePrefix(IFunctionTree functionTree) { 66 List<IFunctionTree> prefixForm = new List<IFunctionTree>(); 67 prefixForm.Add(functionTree); 68 foreach (IFunctionTree subTree in functionTree.SubTrees) { 69 prefixForm.AddRange(IteratePrefix(subTree)); 70 } 71 return prefixForm; 72 } 73 74 private Instr TranslateToInstr(IFunctionTree tree) { 74 75 Instr instr = new Instr(); 75 instr.arity = f.arity;76 instr.symbol = EvaluatorSymbolTable.MapFunction( f.functionType);76 instr.arity = (byte)tree.SubTrees.Count; 77 instr.symbol = EvaluatorSymbolTable.MapFunction(tree.Function); 77 78 switch (instr.symbol) { 78 79 case EvaluatorSymbolTable.DIFFERENTIAL: 79 80 case EvaluatorSymbolTable.VARIABLE: { 80 instr.i_arg0 = (short)dataset.GetVariableIndex((string)f.localData[0]); // var 81 instr.d_arg0 = (double)f.localData[1]; // weight 82 instr.i_arg1 = (short)(int)f.localData[2]; // sample-offset 81 VariableFunctionTree varTree = (VariableFunctionTree)tree; 82 instr.i_arg0 = (short)dataset.GetVariableIndex(varTree.VariableName); 83 instr.d_arg0 = varTree.Weight; 84 instr.i_arg1 = (short)varTree.SampleOffset; 83 85 break; 84 86 } 85 87 case EvaluatorSymbolTable.CONSTANT: { 86 instr.d_arg0 = (double)f.localData[0]; // value 88 ConstantFunctionTree constTree = (ConstantFunctionTree)tree; 89 instr.d_arg0 = constTree.Value; 87 90 break; 88 91 } 89 92 case EvaluatorSymbolTable.UNKNOWN: { 90 instr.function = f.functionType; 91 break; 93 throw new NotSupportedException("Unknown function symbol: " + instr.symbol); 92 94 } 93 95 }
Note: See TracChangeset
for help on using the changeset viewer.