Changeset 334 for trunk/sources/HeuristicLab.StructureIdentification/Evaluation/EarlyStoppingMeanSquaredErrorEvaluator.cs
- Timestamp:
- 06/24/08 10:31:47 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.StructureIdentification/Evaluation/EarlyStoppingMeanSquaredErrorEvaluator.cs
r332 r334 49 49 double qualityLimit = GetVariableValue<DoubleData>("QualityLimit", scope, false).Data; 50 50 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; 51 54 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); 55 58 } 56 59 } 57 60 double errorsSquaredSum = 0; 58 61 double targetMean = dataset.GetMean(targetVariable); 59 for(int sample = 0; sample < dataset.Rows; sample++) {62 for(int sample = trainingStart; sample < trainingEnd; sample++) { 60 63 double estimated = functionTree.Evaluate(dataset, sample); 61 64 double original = dataset.GetValue(sample, targetVariable); … … 72 75 73 76 // 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) 78 81 } 79 82 if(useEstimatedValues) { … … 81 84 } 82 85 } 83 if(useEstimatedValues) RestoreDataset(dataset, targetVariable, 0, dataset.Rows);84 errorsSquaredSum /= dataset.Rows;86 if(useEstimatedValues) RestoreDataset(dataset, targetVariable, trainingStart, trainingEnd); 87 errorsSquaredSum /= rows; 85 88 if(double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) { 86 89 errorsSquaredSum = double.MaxValue; 87 90 } 88 scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * dataset.Rows;91 scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * rows; 89 92 return errorsSquaredSum; 90 93 } … … 92 95 private void RestoreDataset(Dataset dataset, int targetVariable, int from, int to) { 93 96 for(int i = from; i < to; i++) { 94 dataset.SetValue(i, targetVariable, backupValues[i ]);97 dataset.SetValue(i, targetVariable, backupValues[i-from]); 95 98 } 96 99 }
Note: See TracChangeset
for help on using the changeset viewer.