Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/23/08 19:13:17 (16 years ago)
Author:
gkronber
Message:

implemented #172

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.StructureIdentification/Evaluation/MeanSquaredErrorEvaluator.cs

    r200 r332  
    3232namespace HeuristicLab.StructureIdentification {
    3333  public class MeanSquaredErrorEvaluator : GPEvaluatorBase {
     34    protected double[] backupValues;
    3435    public override string Description {
    3536      get {
     
    4142    public MeanSquaredErrorEvaluator()
    4243      : base() {
     44      AddVariableInfo(new VariableInfo("UseEstimatedTargetValue", "Wether to use the original (measured) or the estimated (calculated) value for the targat variable when doing autoregressive modelling", typeof(BoolData), VariableKind.In));
     45      GetVariableInfo("UseEstimatedTargetValue").Local = true;
     46      AddVariable(new HeuristicLab.Core.Variable("UseEstimatedTargetValue", new BoolData(false)));
    4347    }
    4448
     
    4650      double errorsSquaredSum = 0;
    4751      double targetMean = dataset.GetMean(targetVariable);
     52      bool useEstimatedValues = GetVariableValue<BoolData>("UseEstimatedTargetValue", scope, false).Data;
     53      if(useEstimatedValues && backupValues == null) {
     54        backupValues = new double[dataset.Rows];
     55        for(int i = 0; i < dataset.Rows; i++) {
     56          backupValues[i] = dataset.GetValue(i, targetVariable);
     57        }
     58      }
     59
    4860      for(int sample = 0; sample < dataset.Rows; sample++) {
    49 
    5061        double estimated = functionTree.Evaluate(dataset, sample);
    5162        double original = dataset.GetValue(sample, targetVariable);
     
    5970        double error = estimated - original;
    6071        errorsSquaredSum += error * error;
     72        if(useEstimatedValues) {
     73          dataset.SetValue(sample, targetVariable, estimated);
     74        }
    6175      }
     76
     77      if(useEstimatedValues) RestoreDataset(dataset, targetVariable);
    6278      errorsSquaredSum /= dataset.Rows;
    6379      if(double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) {
     
    6783      return errorsSquaredSum;
    6884    }
     85
     86    private void RestoreDataset(Dataset dataset, int targetVariable) {
     87      for(int i = 0; i < dataset.Rows; i++) {
     88        dataset.SetValue(i, targetVariable, backupValues[i]);
     89      }
     90    }
    6991  }
    7092}
Note: See TracChangeset for help on using the changeset viewer.