Free cookie consent management tool by TermsFeed Policy Generator

Changeset 334 for trunk


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

readded trainingsamplesstart and trainingsamplesend parameter for gp evaluation operators

Location:
trunk/sources/HeuristicLab.StructureIdentification/Evaluation
Files:
3 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    }
  • trunk/sources/HeuristicLab.StructureIdentification/Evaluation/GPEvaluatorBase.cs

    r200 r334  
    4343      AddVariableInfo(new VariableInfo("TargetVariable", "Index of the column of the dataset that holds the target variable", typeof(IntData), VariableKind.In));
    4444      AddVariableInfo(new VariableInfo("PunishmentFactor", "Punishment factor for invalid estimations", typeof(DoubleData), VariableKind.In));
    45       AddVariableInfo(new VariableInfo("TotalEvaluatedNodes", "Number of evaluated nodes", typeof(DoubleData), VariableKind.In | VariableKind.Out));
     45      AddVariableInfo(new VariableInfo("TotalEvaluatedNodes", "Number of evaluated nodes", typeof(DoubleData), VariableKind.In | VariableKind.Out));
     46      AddVariableInfo(new VariableInfo("TrainingSamplesStart", "Start index of training samples in dataset", typeof(IntData), VariableKind.In));
     47      AddVariableInfo(new VariableInfo("TrainingSamplesEnd", "End index of training samples in dataset", typeof(IntData), VariableKind.In));
    4648      AddVariableInfo(new VariableInfo("Quality", "The evaluated quality of the model", typeof(DoubleData), VariableKind.New));
    4749    }
     
    5456      this.treeSize = scope.GetVariableValue<IntData>("TreeSize", false).Data;
    5557      this.totalEvaluatedNodes = scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data;
    56 
    5758      double result = Evaluate(scope, functionTree, targetVariable, dataset);
    5859      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("Quality"), new DoubleData(result)));
  • trunk/sources/HeuristicLab.StructureIdentification/Evaluation/MeanSquaredErrorEvaluator.cs

    r332 r334  
    5151      double targetMean = dataset.GetMean(targetVariable);
    5252      bool useEstimatedValues = GetVariableValue<BoolData>("UseEstimatedTargetValue", scope, false).Data;
     53      int trainingStart = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data;
     54      int trainingEnd = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data;
    5355      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);
     56        backupValues = new double[trainingEnd - trainingStart];
     57        for(int i = trainingStart; i < trainingEnd; i++) {
     58          backupValues[i-trainingStart] = dataset.GetValue(i, targetVariable);
    5759        }
    5860      }
    5961
    60       for(int sample = 0; sample < dataset.Rows; sample++) {
     62      for(int sample = trainingStart; sample < trainingEnd; sample++) {
    6163        double estimated = functionTree.Evaluate(dataset, sample);
    6264        double original = dataset.GetValue(sample, targetVariable);
     
    7577      }
    7678
    77       if(useEstimatedValues) RestoreDataset(dataset, targetVariable);
    78       errorsSquaredSum /= dataset.Rows;
     79      if(useEstimatedValues) RestoreDataset(dataset, targetVariable, trainingStart, trainingEnd);
     80      errorsSquaredSum /= (trainingEnd-trainingStart);
    7981      if(double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) {
    8082        errorsSquaredSum = double.MaxValue;
    8183      }
    82       scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * dataset.Rows;
     84      scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * (trainingEnd-trainingStart);
    8385      return errorsSquaredSum;
    8486    }
    8587
    86     private void RestoreDataset(Dataset dataset, int targetVariable) {
    87       for(int i = 0; i < dataset.Rows; i++) {
    88         dataset.SetValue(i, targetVariable, backupValues[i]);
     88    private void RestoreDataset(Dataset dataset, int targetVariable, int from, int to) {
     89      for(int i = from; i < to; i++) {
     90        dataset.SetValue(i, targetVariable, backupValues[i-from]);
    8991      }
    9092    }
Note: See TracChangeset for help on using the changeset viewer.