Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/29/08 11:21:04 (16 years ago)
Author:
gkronber
Message:

fixed #328 by restructuring evaluation operators to remove state in evaluation operators.

File:
1 edited

Legend:

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

    r656 r702  
    2727using HeuristicLab.Data;
    2828using HeuristicLab.Operators;
     29using HeuristicLab.DataAnalysis;
    2930
    3031namespace HeuristicLab.GP.StructureIdentification {
    3132  public class MeanAbsolutePercentageErrorEvaluator : GPEvaluatorBase {
    32     private DoubleData mape;
    3333    public override string Description {
    3434      get {
     
    4343    }
    4444
    45     public override IOperation Apply(IScope scope) {
    46       mape = GetVariableValue<DoubleData>("MAPE", scope, false, false);
    47       if(mape == null) {
    48         mape = new DoubleData();
    49         scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("MAPE"), mape));
    50       }
    51 
    52       return base.Apply(scope);
    53     }
    54 
    55     public override void Evaluate(int start, int end) {
     45    public override void Evaluate(IScope scope, BakedTreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
    5646      double errorsSum = 0.0;
    5747      int n = 0;
    5848      for(int sample = start; sample < end; sample++) {
    59         double estimated = GetEstimatedValue(sample);
    60         double original = GetOriginalValue(sample);
    61         SetOriginalValue(sample, estimated);
    62         if(!double.IsNaN(original) && !double.IsInfinity(original) && original!=0.0) {
     49        double estimated = evaluator.Evaluate(sample);
     50        double original = dataset.GetValue(targetVariable, sample);
     51
     52        if(updateTargetValues) {
     53          dataset.SetValue(targetVariable, sample, estimated);
     54        }
     55       
     56        if(!double.IsNaN(original) && !double.IsInfinity(original) && original != 0.0) {
    6357          double percent_error = Math.Abs((estimated - original) / original);
    6458          errorsSum += percent_error;
     
    6963      if(double.IsNaN(quality) || double.IsInfinity(quality))
    7064        quality = double.MaxValue;
     65
     66      // create a variable for the MAPE
     67      DoubleData mape = GetVariableValue<DoubleData>("MAPE", scope, false, false);
     68      if(mape == null) {
     69        mape = new DoubleData();
     70        scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("MAPE"), mape));
     71      }
     72
    7173      mape.Data = quality;
    7274    }
Note: See TracChangeset for help on using the changeset viewer.