Changeset 396 for trunk/sources/HeuristicLab.Functions
- Timestamp:
- 07/28/08 18:46:02 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Functions
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Functions/BakedFunctionTree.cs
r363 r396 48 48 class BakedFunctionTree : ItemBase, IFunctionTree { 49 49 private List<LightWeightFunction> linearRepresentation; 50 internal List<LightWeightFunction> LinearRepresentation { 51 get { 52 FlattenVariables(); 53 FlattenTrees(); 54 return linearRepresentation; 55 } 56 } 50 57 private bool treesExpanded = false; 51 58 private List<IFunctionTree> subTrees; 52 59 private bool variablesExpanded = false; 53 60 private List<IVariable> variables; 61 private BakedTreeEvaluator evaluator; 54 62 55 63 public BakedFunctionTree() { … … 262 270 } 263 271 264 public void PrepareEvaluation(Dataset dataset) { 265 FlattenVariables(); 266 FlattenTrees(); 267 BakedTreeEvaluator.ResetEvaluator(dataset, linearRepresentation); 268 } 269 270 public double Evaluate(int sampleIndex) { 271 return BakedTreeEvaluator.Evaluate(sampleIndex); 272 } 273 272 public IEvaluator CreateEvaluator(Dataset dataset) { 273 return new BakedTreeEvaluator(dataset); 274 } 274 275 275 276 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { -
trunk/sources/HeuristicLab.Functions/BakedTreeEvaluator.cs
r365 r396 29 29 30 30 namespace HeuristicLab.Functions { 31 internal static class BakedTreeEvaluator {31 internal class BakedTreeEvaluator : IEvaluator { 32 32 private const int MAX_TREE_SIZE = 4096; 33 33 … … 40 40 } 41 41 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() { 42 private Instr[] codeArr; 43 private int PC; 44 private Dataset dataset; 45 private int sampleIndex; 46 47 48 public BakedTreeEvaluator(Dataset dataset) { 49 this.dataset = dataset; 49 50 codeArr = new Instr[MAX_TREE_SIZE]; 50 51 for(int i = 0; i < MAX_TREE_SIZE; i++) { … … 53 54 } 54 55 55 public static void ResetEvaluator(Dataset dataset, List<LightWeightFunction> linearRepresentation) { 56 public void ResetEvaluator(IFunctionTree functionTree) { 57 List<LightWeightFunction> linearRepresentation = ((BakedFunctionTree)functionTree).LinearRepresentation; 56 58 int i = 0; 57 BakedTreeEvaluator.dataset = dataset;58 59 foreach(LightWeightFunction f in linearRepresentation) { 59 60 TranslateToInstr(f, codeArr[i++]); … … 61 62 } 62 63 63 private staticInstr TranslateToInstr(LightWeightFunction f, Instr instr) {64 private Instr TranslateToInstr(LightWeightFunction f, Instr instr) { 64 65 instr.arity = f.arity; 65 66 instr.symbol = EvaluatorSymbolTable.MapFunction(f.functionType); … … 79 80 } 80 81 81 internal static double Evaluate(int sampleIndex) {82 public double Evaluate(int sampleIndex) { 82 83 PC = 0; 83 BakedTreeEvaluator.sampleIndex = sampleIndex;84 this.sampleIndex = sampleIndex; 84 85 return EvaluateBakedCode(); 85 86 } 86 87 87 private staticdouble EvaluateBakedCode() {88 private double EvaluateBakedCode() { 88 89 Instr currInstr = codeArr[PC++]; 89 90 switch(currInstr.symbol) { -
trunk/sources/HeuristicLab.Functions/HeuristicLab.Functions.csproj
r365 r396 58 58 <Compile Include="Differential.cs" /> 59 59 <Compile Include="GreaterThan.cs" /> 60 <Compile Include="IEvaluator.cs" /> 60 61 <Compile Include="IfThenElse.cs"> 61 62 <SubType>Code</SubType> -
trunk/sources/HeuristicLab.Functions/IFunctionTree.cs
r363 r396 40 40 void RemoveSubTree(int index); 41 41 42 void PrepareEvaluation(Dataset dataset); 43 double Evaluate(int sampleIndex); 42 IEvaluator CreateEvaluator(Dataset dataset); 44 43 } 45 44 }
Note: See TracChangeset
for help on using the changeset viewer.