Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/25/09 18:43:26 (15 years ago)
Author:
gkronber
Message:

Fixed #643 (Simple evaluation operators in HL.Modeling and GP specific evaluation operators in HL.GP.StructureIdentification should be unified).

File:
1 edited

Legend:

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

    r1891 r1894  
    2727using HeuristicLab.Data;
    2828using HeuristicLab.Operators;
     29using HeuristicLab.Modeling;
    2930using HeuristicLab.DataAnalysis;
    3031
    3132namespace HeuristicLab.GP.StructureIdentification {
    32   public class MeanAbsolutePercentageOfRangeErrorEvaluator : GPEvaluatorBase {
     33  public class MeanAbsolutePercentageOfRangeErrorEvaluator : SimpleGPEvaluatorBase {
     34    public override string OutputVariableName {
     35      get {
     36        return "MAPRE";
     37      }
     38    }
    3339    public override string Description {
    3440      get {
     
    3844    }
    3945
    40     public MeanAbsolutePercentageOfRangeErrorEvaluator()
    41       : base() {
    42       AddVariableInfo(new VariableInfo("MAPRE", "The mean absolute percentage range error of the model", typeof(DoubleData), VariableKind.New));
    43     }
    44 
    45     public override void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
    46       double errorsSum = 0.0;
    47       int n = 0;
    48       double range = dataset.GetRange(targetVariable, start, end);
    49       for (int sample = start; sample < end; sample++) {
    50         double estimated = evaluator.Evaluate(sample);
    51         double original = dataset.GetValue(sample, targetVariable);
    52 
    53         if (updateTargetValues) {
    54           dataset.SetValue(sample, targetVariable, estimated);
    55         }
    56 
    57         if (!double.IsNaN(original) && !double.IsInfinity(original) && original != 0.0) {
    58           double percent_error = Math.Abs((estimated - original) / range);
    59           errorsSum += percent_error;
    60           n++;
    61         }
    62       }
    63       double quality = errorsSum / n;
     46    public override double Evaluate(double[,] values) {
     47      double quality = SimpleMeanAbsolutePercentageOfRangeErrorEvaluator.Calculate(values);
    6448      if (double.IsNaN(quality) || double.IsInfinity(quality))
    6549        quality = double.MaxValue;
    6650
    67       // create a variable for the MAPRE
    68       DoubleData mapre = GetVariableValue<DoubleData>("MAPRE", scope, false, false);
    69       if (mapre == null) {
    70         mapre = new DoubleData();
    71         scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("MAPRE"), mapre));
    72       }
    73 
    74       mapre.Data = quality;
     51      return quality;
    7552    }
    7653  }
Note: See TracChangeset for help on using the changeset viewer.