Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/25/09 18:43:26 (16 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/MeanSquaredErrorEvaluator.cs

    r1891 r1894  
    2828using HeuristicLab.Operators;
    2929using HeuristicLab.DataAnalysis;
     30using HeuristicLab.Modeling;
    3031
    3132namespace HeuristicLab.GP.StructureIdentification {
    32   public class MeanSquaredErrorEvaluator : GPEvaluatorBase {
     33  public class MeanSquaredErrorEvaluator : SimpleGPEvaluatorBase {
     34    public override string OutputVariableName {
     35      get {
     36        return "MSE";
     37      }
     38    }
    3339    public override string Description {
    3440      get {
     
    3844    }
    3945
    40     public MeanSquaredErrorEvaluator()
    41       : base() {
    42       AddVariableInfo(new VariableInfo("MSE", "The mean squared error of the model", typeof(DoubleData), VariableKind.New));
    43     }
     46    public override double Evaluate(double[,] values) {
     47      double quality = SimpleMSEEvaluator.Calculate(values);
    4448
    45     public override void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
    46       double errorsSquaredSum = 0;
    47       int n = 0;
    48       for (int sample = start; sample < end; sample++) {
    49         double original = dataset.GetValue(sample, targetVariable);
    50         double estimated = evaluator.Evaluate(sample);
    51         if (updateTargetValues) {
    52           dataset.SetValue(sample, targetVariable, estimated);
    53         }
    54         if (!double.IsNaN(original) && !double.IsInfinity(original)) {
    55           double error = estimated - original;
    56           errorsSquaredSum += error * error;
    57           n++;
    58         }
     49      if (double.IsNaN(quality) || double.IsInfinity(quality)) {
     50        quality = double.MaxValue;
    5951      }
    6052
    61       errorsSquaredSum /= n;
    62       if (double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) {
    63         errorsSquaredSum = double.MaxValue;
    64       }
    65 
    66       DoubleData mse = GetVariableValue<DoubleData>("MSE", scope, false, false);
    67       if (mse == null) {
    68         mse = new DoubleData();
    69         scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("MSE"), mse));
    70       }
    71 
    72       mse.Data = errorsSquaredSum;
     53      return quality;
    7354    }
    7455  }
Note: See TracChangeset for help on using the changeset viewer.