Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/25/09 17:46:17 (15 years ago)
Author:
gkronber
Message:

Fixed #645 (Tree evaluators precompile the model for each evaluation of a row).

Location:
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/CoefficientOfDeterminationEvaluator.cs

    r1796 r1891  
    4242    }
    4343
    44     public override void Evaluate(IScope scope, ITreeEvaluator evaluator, IFunctionTree tree, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
     44    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
    4545      double errorsSquaredSum = 0.0;
    4646      double originalDeviationTotalSumOfSquares = 0.0;
     
    5050      int n = 0;
    5151      for (int sample = start; sample < end; sample++) {
    52         double estimated = evaluator.Evaluate(tree, sample);
     52        double estimated = evaluator.Evaluate(sample);
    5353        double original = dataset.GetValue(sample, targetVariable);
    5454        if (updateTargetValues) {
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/EarlyStoppingMeanSquaredErrorEvaluator.cs

    r1796 r1891  
    4444
    4545    // evaluates the function-tree for the given target-variable and the whole dataset and returns the MSE
    46     public override void Evaluate(IScope scope, ITreeEvaluator evaluator, IFunctionTree tree, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
     46    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
    4747      double qualityLimit = GetVariableValue<DoubleData>("QualityLimit", scope, false).Data;
    4848      DoubleData mse = GetVariableValue<DoubleData>("MSE", scope, false, false);
     
    5656      int n = 0;
    5757      for (int sample = start; sample < end; sample++) {
    58         double estimated = evaluator.Evaluate(tree, sample);
     58        double estimated = evaluator.Evaluate(sample);
    5959        double original = dataset.GetValue(sample, targetVariable);
    6060        if (updateTargetValues) {
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/GPEvaluatorBase.cs

    r1796 r1891  
    5757      bool useEstimatedValues = GetVariableValue<BoolData>("UseEstimatedTargetValue", scope, true).Data;
    5858      ITreeEvaluator evaluator = GetVariableValue<ITreeEvaluator>("TreeEvaluator", scope, true);
     59      evaluator.PrepareForEvaluation(functionTree);
    5960
    6061      double[] backupValues = null;
     
    6869      }
    6970
    70       Evaluate(scope, evaluator, functionTree, dataset, targetVariable, start, end, useEstimatedValues);
     71      Evaluate(scope, evaluator, dataset, targetVariable, start, end, useEstimatedValues);
    7172
    7273      // restore the values of the target variable from the backup array if necessary
     
    8283    }
    8384
    84     public abstract void Evaluate(IScope scope, ITreeEvaluator evaluator, IFunctionTree tree, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues);
     85    public abstract void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues);
    8586  }
    8687}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/MeanAbsolutePercentageErrorEvaluator.cs

    r1796 r1891  
    4343    }
    4444
    45     public override void Evaluate(IScope scope, ITreeEvaluator evaluator, IFunctionTree tree, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
     45    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
    4646      double errorsSum = 0.0;
    4747      int n = 0;
    4848      for (int sample = start; sample < end; sample++) {
    49         double estimated = evaluator.Evaluate(tree, sample);
     49        double estimated = evaluator.Evaluate(sample);
    5050        double original = dataset.GetValue(sample, targetVariable);
    5151
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/MeanAbsolutePercentageOfRangeErrorEvaluator.cs

    r1796 r1891  
    4343    }
    4444
    45     public override void Evaluate(IScope scope, ITreeEvaluator evaluator, IFunctionTree tree, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
     45    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
    4646      double errorsSum = 0.0;
    4747      int n = 0;
    4848      double range = dataset.GetRange(targetVariable, start, end);
    4949      for (int sample = start; sample < end; sample++) {
    50         double estimated = evaluator.Evaluate(tree, sample);
     50        double estimated = evaluator.Evaluate(sample);
    5151        double original = dataset.GetValue(sample, targetVariable);
    5252
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/MeanSquaredErrorEvaluator.cs

    r1796 r1891  
    4343    }
    4444
    45     public override void Evaluate(IScope scope, ITreeEvaluator evaluator, IFunctionTree tree, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
     45    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
    4646      double errorsSquaredSum = 0;
    4747      int n = 0;
    4848      for (int sample = start; sample < end; sample++) {
    4949        double original = dataset.GetValue(sample, targetVariable);
    50         double estimated = evaluator.Evaluate(tree, sample);
     50        double estimated = evaluator.Evaluate(sample);
    5151        if (updateTargetValues) {
    5252          dataset.SetValue(sample, targetVariable, estimated);
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/SimpleEvaluator.cs

    r1796 r1891  
    3636    }
    3737
    38     public override void Evaluate(IScope scope, ITreeEvaluator evaluator, IFunctionTree tree, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
     38    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
    3939      ItemList values = GetVariableValue<ItemList>("Values", scope, false, false);
    4040      if (values == null) {
     
    5050      for (int sample = start; sample < end; sample++) {
    5151        ItemList row = new ItemList();
    52         double estimated = evaluator.Evaluate(tree, sample);
     52        double estimated = evaluator.Evaluate(sample);
    5353        double original = dataset.GetValue(sample, targetVariable);
    5454        if (updateTargetValues) {
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/UncertainMeanSquaredErrorEvaluator.cs

    r1796 r1891  
    5050
    5151    // evaluates the function-tree for the given target-variable and the whole dataset and returns the MSE
    52     public override void Evaluate(IScope scope, ITreeEvaluator evaluator, IFunctionTree tree, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
     52    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
    5353      double qualityLimit = GetVariableValue<DoubleData>("QualityLimit", scope, false).Data;
    5454      int minSamples = GetVariableValue<IntData>("MinEvaluatedSamples", scope, true).Data;
     
    7878      int n = 0;
    7979      for (int sample = 0; sample < rows; sample++) {
    80         double estimated = evaluator.Evaluate(tree, indexes[sample]);
     80        double estimated = evaluator.Evaluate(indexes[sample]);
    8181        double original = dataset.GetValue(indexes[sample], targetVariable);
    8282        if (!double.IsNaN(original) && !double.IsInfinity(original)) {
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/VarianceAccountedForEvaluator.cs

    r1796 r1891  
    5353    }
    5454
    55     public override void Evaluate(IScope scope, ITreeEvaluator evaluator, IFunctionTree tree, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
     55    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
    5656      int nSamples = end - start;
    5757      double[] errors = new double[nSamples];
    5858      double[] originalTargetVariableValues = new double[nSamples];
    5959      for (int sample = start; sample < end; sample++) {
    60         double estimated = evaluator.Evaluate(tree, sample);
     60        double estimated = evaluator.Evaluate(sample);
    6161        double original = dataset.GetValue(sample, targetVariable);
    6262        if (updateTargetValues) {
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/ITreeEvaluator.cs

    r1796 r1891  
    3232  public interface ITreeEvaluator : IItem {
    3333    void ResetEvaluator(Dataset dataset, int targetVariable, int start, int end, double punishmentFactor);
    34     double Evaluate(IFunctionTree functionTree, int sampleIndex);
     34    void PrepareForEvaluation(IFunctionTree functionTree);
     35    double Evaluate(int sampleIndex);
    3536  }
    3637}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/TreeEvaluatorBase.cs

    r1873 r1891  
    6262    }
    6363
     64    public void PrepareForEvaluation(IFunctionTree functionTree) {
     65      BakedFunctionTree bakedTree = functionTree as BakedFunctionTree;
     66      if (bakedTree == null) throw new ArgumentException("TreeEvaluators can only evaluate BakedFunctionTrees");
     67
     68      List<LightWeightFunction> linearRepresentation = bakedTree.LinearRepresentation;
     69      codeArr = new Instr[linearRepresentation.Count];
     70      int i = 0;
     71      foreach (LightWeightFunction f in linearRepresentation) {
     72        codeArr[i++] = TranslateToInstr(f);
     73      }
     74    }
     75
    6476    private Instr TranslateToInstr(LightWeightFunction f) {
    6577      Instr instr = new Instr();
     
    8698    }
    8799
    88     public double Evaluate(IFunctionTree functionTree, int sampleIndex) {
    89       BakedFunctionTree bakedTree = functionTree as BakedFunctionTree;
    90       if (bakedTree == null) throw new ArgumentException("TreeEvaluators can only evaluate BakedFunctionTrees");
    91 
    92       List<LightWeightFunction> linearRepresentation = bakedTree.LinearRepresentation;
    93       codeArr = new Instr[linearRepresentation.Count];
    94       int i = 0;
    95       foreach (LightWeightFunction f in linearRepresentation) {
    96         codeArr[i++] = TranslateToInstr(f);
    97       }
    98 
     100    public double Evaluate(int sampleIndex) {
    99101      PC = 0;
    100102      this.sampleIndex = sampleIndex;
Note: See TracChangeset for help on using the changeset viewer.