- Timestamp:
- 06/24/08 10:31:47 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.StructureIdentification/Evaluation
- Files:
-
- 3 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 } -
trunk/sources/HeuristicLab.StructureIdentification/Evaluation/GPEvaluatorBase.cs
r200 r334 43 43 AddVariableInfo(new VariableInfo("TargetVariable", "Index of the column of the dataset that holds the target variable", typeof(IntData), VariableKind.In)); 44 44 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)); 46 48 AddVariableInfo(new VariableInfo("Quality", "The evaluated quality of the model", typeof(DoubleData), VariableKind.New)); 47 49 } … … 54 56 this.treeSize = scope.GetVariableValue<IntData>("TreeSize", false).Data; 55 57 this.totalEvaluatedNodes = scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data; 56 57 58 double result = Evaluate(scope, functionTree, targetVariable, dataset); 58 59 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("Quality"), new DoubleData(result))); -
trunk/sources/HeuristicLab.StructureIdentification/Evaluation/MeanSquaredErrorEvaluator.cs
r332 r334 51 51 double targetMean = dataset.GetMean(targetVariable); 52 52 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; 53 55 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); 57 59 } 58 60 } 59 61 60 for(int sample = 0; sample < dataset.Rows; sample++) {62 for(int sample = trainingStart; sample < trainingEnd; sample++) { 61 63 double estimated = functionTree.Evaluate(dataset, sample); 62 64 double original = dataset.GetValue(sample, targetVariable); … … 75 77 } 76 78 77 if(useEstimatedValues) RestoreDataset(dataset, targetVariable );78 errorsSquaredSum /= dataset.Rows;79 if(useEstimatedValues) RestoreDataset(dataset, targetVariable, trainingStart, trainingEnd); 80 errorsSquaredSum /= (trainingEnd-trainingStart); 79 81 if(double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) { 80 82 errorsSquaredSum = double.MaxValue; 81 83 } 82 scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * dataset.Rows;84 scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * (trainingEnd-trainingStart); 83 85 return errorsSquaredSum; 84 86 } 85 87 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]); 89 91 } 90 92 }
Note: See TracChangeset
for help on using the changeset viewer.