Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/29/09 18:28:45 (15 years ago)
Author:
gkronber
Message:

GP Refactoring #713

  • introduced a plugin for GP interfaces
  • created a new interface IGeneticProgrammingModel which represents GP models in HL scopes instead of IFunctionTree
  • changed interfaces IFunction and IFunctionTree
  • moved some files to new directories (general housekeeping)
  • changed all GP operators and engines to work with IGeneticProgrammingModels
  • removed parameters TreeSize and TreeHeight in all GP operators
  • changed parameter OperatorLibrary to FunctionLibrary in all GP operators
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/TreeEvaluatorBase.cs

    r2202 r2210  
    2929using HeuristicLab.DataAnalysis;
    3030using HeuristicLab.Data;
     31using HeuristicLab.GP.Interfaces;
    3132
    3233namespace HeuristicLab.GP.StructureIdentification {
     
    4546      public byte arity;
    4647      public byte symbol;
    47       public IFunction function;
    4848    }
    4949
     
    6161      minValue = mean - punishmentFactor * range;
    6262
    63       BakedFunctionTree bakedTree = functionTree as BakedFunctionTree;
    64       if (bakedTree == null) throw new ArgumentException("TreeEvaluators can only evaluate BakedFunctionTrees");
    65 
    66       List<LightWeightFunction> linearRepresentation = bakedTree.LinearRepresentation;
    67       codeArr = new Instr[linearRepresentation.Count];
     63      codeArr = new Instr[functionTree.GetSize()];
    6864      int i = 0;
    69       foreach (LightWeightFunction f in linearRepresentation) {
    70         codeArr[i++] = TranslateToInstr(f);
     65      foreach (IFunctionTree tree in IteratePrefix(functionTree)) {
     66        codeArr[i++] = TranslateToInstr(tree);
    7167      }
    7268    }
    7369
    74     private Instr TranslateToInstr(LightWeightFunction f) {
     70    private IEnumerable<IFunctionTree> IteratePrefix(IFunctionTree functionTree) {
     71      List<IFunctionTree> prefixForm = new List<IFunctionTree>();
     72      prefixForm.Add(functionTree);
     73      foreach (IFunctionTree subTree in functionTree.SubTrees) {
     74        prefixForm.AddRange(IteratePrefix(subTree));
     75      }
     76      return prefixForm;
     77    }
     78
     79    private Instr TranslateToInstr(IFunctionTree tree) {
    7580      Instr instr = new Instr();
    76       instr.arity = f.arity;
    77       instr.symbol = EvaluatorSymbolTable.MapFunction(f.functionType);
     81      instr.arity = (byte)tree.SubTrees.Count;
     82      instr.symbol = EvaluatorSymbolTable.MapFunction(tree.Function);
    7883      switch (instr.symbol) {
    7984        case EvaluatorSymbolTable.DIFFERENTIAL:
    8085        case EvaluatorSymbolTable.VARIABLE: {
    81             instr.i_arg0 = (short)dataset.GetVariableIndex((((StringData)f.localData[1].Value).Data)); // var
    82             instr.d_arg0 = ((DoubleData)f.localData[0].Value).Data; // weight
    83             instr.i_arg1 = (short)((ConstrainedIntData)f.localData[2].Value).Data; // sample-offset
     86            VariableFunctionTree varTree = (VariableFunctionTree)tree;
     87            instr.i_arg0 = (short)dataset.GetVariableIndex(varTree.VariableName);
     88            instr.d_arg0 = varTree.Weight;
     89            instr.i_arg1 = (short)varTree.SampleOffset;
    8490            break;
    8591          }
    8692        case EvaluatorSymbolTable.CONSTANT: {
    87             instr.d_arg0 = ((DoubleData)f.localData[0].Value).Data; // value
     93            ConstantFunctionTree constTree = (ConstantFunctionTree)tree;
     94            instr.d_arg0 = constTree.Value;
    8895            break;
    8996          }
    9097        case EvaluatorSymbolTable.UNKNOWN: {
    91             instr.function = f.functionType;
    92             break;
     98            throw new NotSupportedException("Unknown function symbol: " + instr.symbol);
    9399          }
    94100      }
Note: See TracChangeset for help on using the changeset viewer.