Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/28/08 18:46:02 (16 years ago)
Author:
gkronber
Message:

fixed ticket #205 by creating the function-specific evaluator in the evaluation operators.

Location:
trunk/sources/HeuristicLab.Functions
Files:
1 added
4 edited

Legend:

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

    r363 r396  
    4848  class BakedFunctionTree : ItemBase, IFunctionTree {
    4949    private List<LightWeightFunction> linearRepresentation;
     50    internal List<LightWeightFunction> LinearRepresentation {
     51      get {
     52        FlattenVariables();
     53        FlattenTrees();
     54        return linearRepresentation;
     55      }
     56    }
    5057    private bool treesExpanded = false;
    5158    private List<IFunctionTree> subTrees;
    5259    private bool variablesExpanded = false;
    5360    private List<IVariable> variables;
     61    private BakedTreeEvaluator evaluator;
    5462
    5563    public BakedFunctionTree() {
     
    262270    }
    263271
    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    }
    274275
    275276    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
  • trunk/sources/HeuristicLab.Functions/BakedTreeEvaluator.cs

    r365 r396  
    2929
    3030namespace HeuristicLab.Functions {
    31   internal static class BakedTreeEvaluator {
     31  internal class BakedTreeEvaluator : IEvaluator {
    3232    private const int MAX_TREE_SIZE = 4096;
    3333
     
    4040    }
    4141
    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;
    4950      codeArr = new Instr[MAX_TREE_SIZE];
    5051      for(int i = 0; i < MAX_TREE_SIZE; i++) {
     
    5354    }
    5455
    55     public static void ResetEvaluator(Dataset dataset, List<LightWeightFunction> linearRepresentation) {
     56    public void ResetEvaluator(IFunctionTree functionTree) {
     57      List<LightWeightFunction> linearRepresentation = ((BakedFunctionTree)functionTree).LinearRepresentation;
    5658      int i = 0;
    57       BakedTreeEvaluator.dataset = dataset;
    5859      foreach(LightWeightFunction f in linearRepresentation) {
    5960        TranslateToInstr(f, codeArr[i++]);
     
    6162    }
    6263
    63     private static Instr TranslateToInstr(LightWeightFunction f, Instr instr) {
     64    private Instr TranslateToInstr(LightWeightFunction f, Instr instr) {
    6465      instr.arity = f.arity;
    6566      instr.symbol = EvaluatorSymbolTable.MapFunction(f.functionType);
     
    7980    }
    8081
    81     internal static double Evaluate(int sampleIndex) {
     82    public double Evaluate(int sampleIndex) {
    8283      PC = 0;
    83       BakedTreeEvaluator.sampleIndex = sampleIndex;
     84      this.sampleIndex = sampleIndex;
    8485      return EvaluateBakedCode();
    8586    }
    8687
    87     private static double EvaluateBakedCode() {
     88    private double EvaluateBakedCode() {
    8889      Instr currInstr = codeArr[PC++];
    8990      switch(currInstr.symbol) {
  • trunk/sources/HeuristicLab.Functions/HeuristicLab.Functions.csproj

    r365 r396  
    5858    <Compile Include="Differential.cs" />
    5959    <Compile Include="GreaterThan.cs" />
     60    <Compile Include="IEvaluator.cs" />
    6061    <Compile Include="IfThenElse.cs">
    6162      <SubType>Code</SubType>
  • trunk/sources/HeuristicLab.Functions/IFunctionTree.cs

    r363 r396  
    4040    void RemoveSubTree(int index);
    4141
    42     void PrepareEvaluation(Dataset dataset);
    43     double Evaluate(int sampleIndex);
     42    IEvaluator CreateEvaluator(Dataset dataset);
    4443  }
    4544}
Note: See TracChangeset for help on using the changeset viewer.