Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/29/08 11:21:04 (15 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/EarlyStoppingMeanSquaredErrorEvaluator.cs

    r656 r702  
    3030namespace HeuristicLab.GP.StructureIdentification {
    3131  public class EarlyStoppingMeanSquaredErrorEvaluator : MeanSquaredErrorEvaluator {
    32     private double qualityLimit;
    3332    public override string Description {
    3433      get {
     
    4443    }
    4544
    46     public override IOperation Apply(IScope scope) {
    47       qualityLimit = GetVariableValue<DoubleData>("QualityLimit", scope, false).Data;
    48       return base.Apply(scope);
    49     }
     45    // evaluates the function-tree for the given target-variable and the whole dataset and returns the MSE
     46    public override void Evaluate(IScope scope, BakedTreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
     47      double qualityLimit = GetVariableValue<DoubleData>("QualityLimit", scope, false).Data;
     48      DoubleData mse = GetVariableValue<DoubleData>("MSE", scope, false, false);
     49      if(mse == null) {
     50        mse = new DoubleData();
     51        scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("MSE"), mse));
     52      }
    5053
    51     // evaluates the function-tree for the given target-variable and the whole dataset and returns the MSE
    52     public override void Evaluate(int start, int end) {
    5354      double errorsSquaredSum = 0;
    5455      int rows = end - start;
    5556      for(int sample = start; sample < end; sample++) {
    56         double estimated = GetEstimatedValue(sample);
    57         double original = GetOriginalValue(sample);
    58         SetOriginalValue(sample, estimated);
     57        double estimated = evaluator.Evaluate(sample);
     58        double original = dataset.GetValue(targetVariable, sample);
     59        if(updateTargetValues) {
     60          dataset.SetValue(targetVariable, sample, estimated);
     61        }
    5962        if(!double.IsNaN(original) && !double.IsInfinity(original)) {
    6063          double error = estimated - original;
     
    7174        errorsSquaredSum = double.MaxValue;
    7275      }
     76
    7377      mse.Data = errorsSquaredSum;
    7478    }
Note: See TracChangeset for help on using the changeset viewer.