Changeset 479 for trunk/sources/HeuristicLab.StructureIdentification/Evaluation/ClassificationMeanSquaredErrorEvaluator.cs
- Timestamp:
- 08/10/08 11:08:07 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.StructureIdentification/Evaluation/ClassificationMeanSquaredErrorEvaluator.cs
r478 r479 32 32 namespace HeuristicLab.StructureIdentification { 33 33 public class ClassificationMeanSquaredErrorEvaluator : GPEvaluatorBase { 34 protected double[] backupValues;35 34 private const double EPSILON = 1.0E-6; 35 private double[] classesArr; 36 36 public override string Description { 37 37 get { … … 46 46 } 47 47 48 public override double Evaluate(IScope scope, IFunctionTree functionTree, int targetVariable, Dataset dataset) { 49 int trainingStart = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data; 50 int trainingEnd = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data; 48 public override IOperation Apply(IScope scope) { 51 49 ItemList<DoubleData> classes = GetVariableValue<ItemList<DoubleData>>("TargetClassValues", scope, true); 52 double[]classesArr = new double[classes.Count];50 classesArr = new double[classes.Count]; 53 51 for(int i = 0; i < classesArr.Length; i++) classesArr[i] = classes[i].Data; 54 52 Array.Sort(classesArr); 53 return base.Apply(scope); 54 } 55 56 public override double Evaluate(int start, int end) { 55 57 56 58 double errorsSquaredSum = 0; 57 double targetMean = dataset.GetMean(targetVariable, trainingStart, trainingEnd); 58 for(int sample = trainingStart; sample < trainingEnd; sample++) { 59 double estimated = evaluator.Evaluate(sample); 60 double original = dataset.GetValue(sample, targetVariable); 61 if(double.IsNaN(estimated) || double.IsInfinity(estimated)) { 62 estimated = targetMean + maximumPunishment; 63 } else if(estimated > targetMean + maximumPunishment) { 64 estimated = targetMean + maximumPunishment; 65 } else if(estimated < targetMean - maximumPunishment) { 66 estimated = targetMean - maximumPunishment; 67 } 68 double error = estimated - original; 69 // between classes use squared error 70 // on the lower end and upper end only add linear error if the absolute error is larger than 1 71 // the error>1.0 constraint is needed for balance because in the interval ]-1, 1[ the squared error is smaller than the absolute error 72 if(error < -1.0 && IsEqual(original, classesArr[0]) && estimated < classesArr[0] || 73 error > 1.0 && IsEqual(original, classesArr[classesArr.Length - 1]) && estimated > classesArr[classesArr.Length - 1]) { 74 errorsSquaredSum += Math.Abs(error); // only add linear error below the smallest class or above the largest class 75 } else { 76 errorsSquaredSum += error * error; 59 for(int sample = start; sample < end; sample++) { 60 double estimated = GetEstimatedValue(sample); 61 double original = GetOriginalValue(sample); 62 if(!double.IsNaN(original) && !double.IsInfinity(original)) { 63 double error = estimated - original; 64 // between classes use squared error 65 // on the lower end and upper end only add linear error if the absolute error is larger than 1 66 // the error>1.0 constraint is needed for balance because in the interval ]-1, 1[ the squared error is smaller than the absolute error 67 if(error < -1.0 && IsEqual(original, classesArr[0]) && estimated < classesArr[0] || 68 error > 1.0 && IsEqual(original, classesArr[classesArr.Length - 1]) && estimated > classesArr[classesArr.Length - 1]) { 69 errorsSquaredSum += Math.Abs(error); // only add linear error below the smallest class or above the largest class 70 } else { 71 errorsSquaredSum += error * error; 72 } 77 73 } 78 74 } 79 75 80 errorsSquaredSum /= ( trainingEnd - trainingStart);76 errorsSquaredSum /= (end - start); 81 77 if(double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) { 82 78 errorsSquaredSum = double.MaxValue; 83 79 } 84 scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * (trainingEnd - trainingStart);85 80 return errorsSquaredSum; 86 81 }
Note: See TracChangeset
for help on using the changeset viewer.