Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/24/08 10:31:47 (16 years ago)
Author:
gkronber
Message:

readded trainingsamplesstart and trainingsamplesend parameter for gp evaluation operators

File:
1 edited

Legend:

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

    r332 r334  
    4949      double qualityLimit = GetVariableValue<DoubleData>("QualityLimit", scope, false).Data;
    5050      bool useEstimatedValues = GetVariableValue<BoolData>("UseEstimatedTargetValue", scope, false).Data;
     51      int trainingStart = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data;
     52      int trainingEnd = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data;
     53      int rows = trainingEnd-trainingStart;
    5154      if(useEstimatedValues && backupValues == null) {
    52         backupValues = new double[dataset.Rows];
    53         for(int i = 0; i < dataset.Rows; i++) {
    54           backupValues[i] = dataset.GetValue(i, targetVariable);
     55        backupValues = new double[rows];
     56        for(int i = trainingStart; i < trainingEnd; i++) {
     57          backupValues[i-trainingStart] = dataset.GetValue(i, targetVariable);
    5558        }
    5659      }
    5760      double errorsSquaredSum = 0;
    5861      double targetMean = dataset.GetMean(targetVariable);
    59       for(int sample = 0; sample < dataset.Rows; sample++) {
     62      for(int sample = trainingStart; sample < trainingEnd; sample++) {
    6063        double estimated = functionTree.Evaluate(dataset, sample);
    6164        double original = dataset.GetValue(sample, targetVariable);
     
    7275
    7376        // check the limit and stop as soon as we hit the limit
    74         if(errorsSquaredSum / dataset.Rows >= qualityLimit) {
    75           scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * sample+1;
    76           if(useEstimatedValues) RestoreDataset(dataset, targetVariable, 0, sample);
    77           return errorsSquaredSum / (sample + 1); // return estimated MSE (when the remaining errors are on average the same)
     77        if(errorsSquaredSum / rows >= qualityLimit) {
     78          scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * (sample-trainingStart + 1);
     79          if(useEstimatedValues) RestoreDataset(dataset, targetVariable, trainingStart, sample);
     80          return errorsSquaredSum / (sample-trainingStart + 1); // return estimated MSE (when the remaining errors are on average the same)
    7881        }
    7982        if(useEstimatedValues) {
     
    8184        }
    8285      }
    83       if(useEstimatedValues) RestoreDataset(dataset, targetVariable, 0, dataset.Rows);
    84       errorsSquaredSum /= dataset.Rows;
     86      if(useEstimatedValues) RestoreDataset(dataset, targetVariable, trainingStart, trainingEnd);
     87      errorsSquaredSum /= rows;
    8588      if(double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) {
    8689        errorsSquaredSum = double.MaxValue;
    8790      }
    88       scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * dataset.Rows;
     91      scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * rows;
    8992      return errorsSquaredSum;
    9093    }
     
    9295    private void RestoreDataset(Dataset dataset, int targetVariable, int from, int to) {
    9396      for(int i = from; i < to; i++) {
    94         dataset.SetValue(i, targetVariable, backupValues[i]);
     97        dataset.SetValue(i, targetVariable, backupValues[i-from]);
    9598      }
    9699    }
Note: See TracChangeset for help on using the changeset viewer.