- Timestamp:
- 06/23/08 19:13:17 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.StructureIdentification/Evaluation
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.StructureIdentification/Evaluation/EarlyStoppingMeanSquaredErrorEvaluator.cs
r200 r332 45 45 } 46 46 47 // evaluates the function-tree for the given target-variable and the whole dataset and returns the MSE 47 48 public override double Evaluate(IScope scope, IFunctionTree functionTree, int targetVariable, Dataset dataset) { 48 49 double qualityLimit = GetVariableValue<DoubleData>("QualityLimit", scope, false).Data; 50 bool useEstimatedValues = GetVariableValue<BoolData>("UseEstimatedTargetValue", scope, false).Data; 51 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 } 56 } 49 57 double errorsSquaredSum = 0; 50 58 double targetMean = dataset.GetMean(targetVariable); … … 59 67 estimated = targetMean - maximumPunishment; 60 68 } 69 61 70 double error = estimated - original; 62 71 errorsSquaredSum += error * error; … … 65 74 if(errorsSquaredSum / dataset.Rows >= qualityLimit) { 66 75 scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * sample+1; 76 if(useEstimatedValues) RestoreDataset(dataset, targetVariable, 0, sample); 67 77 return errorsSquaredSum / (sample + 1); // return estimated MSE (when the remaining errors are on average the same) 68 78 } 79 if(useEstimatedValues) { 80 dataset.SetValue(sample, targetVariable, estimated); 81 } 69 82 } 83 if(useEstimatedValues) RestoreDataset(dataset, targetVariable, 0, dataset.Rows); 70 84 errorsSquaredSum /= dataset.Rows; 71 85 if(double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) { … … 75 89 return errorsSquaredSum; 76 90 } 91 92 private void RestoreDataset(Dataset dataset, int targetVariable, int from, int to) { 93 for(int i = from; i < to; i++) { 94 dataset.SetValue(i, targetVariable, backupValues[i]); 95 } 96 } 77 97 } 78 98 } -
trunk/sources/HeuristicLab.StructureIdentification/Evaluation/MeanSquaredErrorEvaluator.cs
r200 r332 32 32 namespace HeuristicLab.StructureIdentification { 33 33 public class MeanSquaredErrorEvaluator : GPEvaluatorBase { 34 protected double[] backupValues; 34 35 public override string Description { 35 36 get { … … 41 42 public MeanSquaredErrorEvaluator() 42 43 : 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))); 43 47 } 44 48 … … 46 50 double errorsSquaredSum = 0; 47 51 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 48 60 for(int sample = 0; sample < dataset.Rows; sample++) { 49 50 61 double estimated = functionTree.Evaluate(dataset, sample); 51 62 double original = dataset.GetValue(sample, targetVariable); … … 59 70 double error = estimated - original; 60 71 errorsSquaredSum += error * error; 72 if(useEstimatedValues) { 73 dataset.SetValue(sample, targetVariable, estimated); 74 } 61 75 } 76 77 if(useEstimatedValues) RestoreDataset(dataset, targetVariable); 62 78 errorsSquaredSum /= dataset.Rows; 63 79 if(double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) { … … 67 83 return errorsSquaredSum; 68 84 } 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 } 69 91 } 70 92 }
Note: See TracChangeset
for help on using the changeset viewer.