Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1891


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

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

Location:
trunk/sources
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/AccuracyEvaluator.cs

    r1796 r1891  
    4343    }
    4444
    45     public override void Evaluate(IScope scope, ITreeEvaluator evaluator, IFunctionTree tree, Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) {
     45    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) {
    4646      DoubleData accuracy = GetVariableValue<DoubleData>("Accuracy", scope, false, false);
    4747      if (accuracy == null) {
     
    5353      int nCorrect = 0;
    5454      for (int sample = start; sample < end; sample++) {
    55         double est = evaluator.Evaluate(tree, sample);
     55        double est = evaluator.Evaluate(sample);
    5656        double origClass = dataset.GetValue(sample, targetVariable);
    5757        double estClass = double.NaN;
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/ClassificationMeanSquaredErrorEvaluator.cs

    r1796 r1891  
    4343    }
    4444
    45     public override void Evaluate(IScope scope, ITreeEvaluator evaluator, IFunctionTree tree, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) {
     45    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) {
    4646      double errorsSquaredSum = 0;
    4747      for (int sample = start; sample < end; sample++) {
    48         double estimated = evaluator.Evaluate(tree, sample);
     48        double estimated = evaluator.Evaluate(sample);
    4949        double original = dataset.GetValue(sample, targetVariable);
    5050        if (!double.IsNaN(original) && !double.IsInfinity(original)) {
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/ConfusionMatrixEvaluator.cs

    r1796 r1891  
    4141    }
    4242
    43     public override void Evaluate(IScope scope, ITreeEvaluator evaluator, IFunctionTree tree, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) {
     43    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end) {
    4444      IntMatrixData matrix = GetVariableValue<IntMatrixData>("ConfusionMatrix", scope, false, false);
    4545      if (matrix == null) {
     
    5050      int nSamples = end - start;
    5151      for (int sample = start; sample < end; sample++) {
    52         double est = evaluator.Evaluate(tree, sample);
     52        double est = evaluator.Evaluate(sample);
    5353        double origClass = dataset.GetValue(sample, targetVariable);
    5454        int estClassIndex = -1;
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/GPClassificationEvaluatorBase.cs

    r1796 r1891  
    3737    }
    3838
    39     public override void Evaluate(IScope scope, ITreeEvaluator evaluator, IFunctionTree tree, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
     39    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
    4040
    4141      ItemList<DoubleData> classes = GetVariableValue<ItemList<DoubleData>>("TargetClassValues", scope, true);
     
    4848      }
    4949
    50       Evaluate(scope, evaluator, tree, dataset, targetVariable, classesArr, thresholds, start, end);
     50      Evaluate(scope, evaluator, dataset, targetVariable, classesArr, thresholds, start, end);
    5151    }
    5252
    53     public abstract void Evaluate(IScope scope, ITreeEvaluator evaluator, IFunctionTree tree, Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end);
     53    public abstract void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end);
    5454  }
    5555}
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/MulticlassOneVsOneAnalyzer.cs

    r1796 r1891  
    8686        BakedTreeEvaluator evaluator = new BakedTreeEvaluator();
    8787        evaluator.ResetEvaluator(dataset, targetVariable, trainingSamplesStart, trainingSamplesEnd, 1.0);
    88 
     88        evaluator.PrepareForEvaluation(functionTree);
    8989        for(int i = 0; i < (samplesEnd - samplesStart); i++) {
    90           double est = evaluator.Evaluate(functionTree, i + samplesStart);
     90          double est = evaluator.Evaluate(i + samplesStart);
    9191          if(est < 0.5) {
    9292            CastVote(votes, i, classAValue, classValues);
  • trunk/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/3.3/AveragePercentageChangeEvaluator.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      bool differential = GetVariableValue<BoolData>("Differential", scope, true).Data;
    4646      DoubleData apc = GetVariableValue<DoubleData>("APC", scope, false, false);
     
    5858          prevOriginal = dataset.GetValue(sample - 1, targetVariable);
    5959          originalPercentageChange = (dataset.GetValue(sample, targetVariable) - prevOriginal) / prevOriginal;
    60           estimatedPercentageChange = (evaluator.Evaluate(tree, sample) - prevOriginal) / prevOriginal;
     60          estimatedPercentageChange = (evaluator.Evaluate(sample) - prevOriginal) / prevOriginal;
    6161          if (updateTargetValues) {
    6262            dataset.SetValue(sample, targetVariable, estimatedPercentageChange * prevOriginal + prevOriginal);
     
    6464        } else {
    6565          originalPercentageChange = dataset.GetValue(sample, targetVariable);
    66           estimatedPercentageChange = evaluator.Evaluate(tree, sample);
     66          estimatedPercentageChange = evaluator.Evaluate(sample);
    6767          if (updateTargetValues) {
    6868            dataset.SetValue(sample, targetVariable, estimatedPercentageChange);
  • trunk/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/3.3/ProfitEvaluator.cs

    r1796 r1891  
    4343    }
    4444
    45     public override void Evaluate(IScope scope, ITreeEvaluator evaluator, IFunctionTree tree, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
     45    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
    4646      int exchangeRateVarIndex = GetVariableValue<IntData>("ExchangeRate", scope, true).Data;
    4747      double transactionCost = GetVariableValue<DoubleData>("TransactionCost", scope, true).Data;
     
    5858        exchangeRate = dataset.GetValue(sample, exchangeRateVarIndex);
    5959        double originalPercentageChange = dataset.GetValue(sample, targetVariable);
    60         double estimatedPercentageChange = evaluator.Evaluate(tree, sample);
     60        double estimatedPercentageChange = evaluator.Evaluate(sample);
    6161        if (updateTargetValues) {
    6262          dataset.SetValue(sample, targetVariable, estimatedPercentageChange);
  • trunk/sources/HeuristicLab.GP.StructureIdentification.TimeSeries/3.3/TheilInequalityCoefficientEvaluator.cs

    r1796 r1891  
    5454    }
    5555
    56     public override void Evaluate(IScope scope, ITreeEvaluator evaluator, IFunctionTree tree, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
     56    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
    5757      #region create result variables
    5858      DoubleData theilInequaliy = GetVariableValue<DoubleData>("TheilInequalityCoefficient", scope, false, false);
     
    8585      for (int sample = start; sample < end; sample++) {
    8686        double prevValue = dataset.GetValue(sample - 1, targetVariable);
    87         double estimatedChange = evaluator.Evaluate(tree, sample) - prevValue;
     87        double estimatedChange = evaluator.Evaluate(sample) - prevValue;
    8888        double originalChange = dataset.GetValue(sample, targetVariable) - prevValue;
    8989        if (updateTargetValues) {
  • 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.