- Timestamp:
- 08/09/08 00:31:27 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.StructureIdentification/Evaluation/AccuracyEvaluator.cs
r453 r474 32 32 namespace HeuristicLab.StructureIdentification { 33 33 public class AccuracyEvaluator : GPEvaluatorBase { 34 private const double EPSILON = 1.0E-6; 34 35 public override string Description { 35 36 get { … … 40 41 public AccuracyEvaluator() 41 42 : base() { 42 AddVariableInfo(new VariableInfo(" ClassSeparation", "The value of separation between negative and positive target classification values (for instance 0.5 if negative=0 and positive=1).", typeof(DoubleData), VariableKind.In));43 AddVariableInfo(new VariableInfo("TargetClassValues", "The original class values of target variable (for instance negative=0 and positive=1).", typeof(ItemList<DoubleData>), VariableKind.In)); 43 44 } 44 45 … … 49 50 int trainingEnd = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data; 50 51 int nSamples = trainingEnd-trainingStart; 51 double limit = GetVariableValue<DoubleData>("ClassSeparation", scope, true).Data; 52 double TP = 0; 53 double TN = 0; 54 double targetMean = dataset.GetMean(targetVariable, trainingStart, trainingEnd); 52 ItemList<DoubleData> classes = GetVariableValue<ItemList<DoubleData>>("TargetClassValues", scope, true); 53 double[] classesArr = new double[classes.Count]; 54 for(int i=0;i<classesArr.Length;i++) classesArr[i] = classes[i].Data; 55 Array.Sort(classesArr); 56 double[] thresholds = new double[classes.Count - 1]; 57 for(int i=0;i<classesArr.Length-1;i++) { 58 thresholds[i] = (classesArr[i]+classesArr[i+1]) / 2.0; 59 } 60 61 int nCorrect = 0; 55 62 for(int sample = trainingStart; sample < trainingEnd; sample++) { 56 63 double est = evaluator.Evaluate(sample); 57 double orig = dataset.GetValue(sample, targetVariable); 58 if(double.IsNaN(est) || double.IsInfinity(est)) { 59 est = targetMean + maximumPunishment; 60 } else if(est > targetMean + maximumPunishment) { 61 est = targetMean + maximumPunishment; 62 } else if(est < targetMean - maximumPunishment) { 63 est = targetMean - maximumPunishment; 64 double origClass = dataset.GetValue(sample, targetVariable); 65 double estClass = double.NaN; 66 if(est < classesArr[0]) estClass = classesArr[0]; 67 else if(est > classesArr[classesArr.Length - 1]) estClass = classesArr[classesArr.Length - 1]; 68 else { 69 for(int k = 0; k < thresholds.Length; k++) { 70 if(thresholds[k] > est) { 71 estClass = classesArr[k + 1]; 72 break; 73 } 74 } 64 75 } 65 if(orig >= limit && est>=limit) TP++; 66 if(orig < limit && est < limit) TN++; 76 if(Math.Abs(estClass - origClass) < EPSILON) nCorrect++; 67 77 } 68 78 scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * nSamples; 69 return (TP+TN) /nSamples;79 return nCorrect / (double)nSamples; 70 80 } 71 81 }
Note: See TracChangeset
for help on using the changeset viewer.