- Timestamp:
- 08/10/08 11:08:07 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.StructureIdentification/Evaluation/MCCEvaluator.cs
r453 r479 32 32 namespace HeuristicLab.StructureIdentification { 33 33 public class MCCEvaluator : GPEvaluatorBase { 34 private double limit; 35 private double[] original = new double[1]; 36 private double[] estimated = new double[1]; 34 37 public override string Description { 35 38 get { … … 37 40 } 38 41 } 39 40 42 public MCCEvaluator() 41 43 : base() { … … 43 45 } 44 46 45 p rivate double[] original = new double[1];46 private double[] estimated = new double[1];47 public override double Evaluate(IScope scope, IFunctionTree functionTree, int targetVariable, Dataset dataset) {48 int trainingStart = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data;49 int trainingEnd = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data; 50 int nSamples = trainingEnd-trainingStart;51 double limit = GetVariableValue<DoubleData>("ClassSeparation", scope, true).Data;47 public override IOperation Apply(IScope scope) { 48 limit = GetVariableValue<DoubleData>("ClassSeparation", scope, true).Data; 49 return base.Apply(scope); 50 } 51 52 public override double Evaluate(int start, int end) { 53 int nSamples = end - start; 52 54 if(estimated.Length != nSamples) { 53 55 estimated = new double[nSamples]; … … 57 59 double positive = 0; 58 60 double negative = 0; 59 double targetMean = dataset.GetMean(targetVariable, trainingStart, trainingEnd); 60 for(int sample = trainingStart; sample < trainingEnd; sample++) { 61 double est = evaluator.Evaluate(sample); 62 double orig = dataset.GetValue(sample, targetVariable); 63 if(double.IsNaN(est) || double.IsInfinity(est)) { 64 est = targetMean + maximumPunishment; 65 } else if(est > targetMean + maximumPunishment) { 66 est = targetMean + maximumPunishment; 67 } else if(est < targetMean - maximumPunishment) { 68 est = targetMean - maximumPunishment; 69 } 70 estimated[sample-trainingStart] = est; 71 original[sample-trainingStart] = orig; 61 for(int sample = start; sample < end; sample++) { 62 double est = GetEstimatedValue(sample); 63 double orig = GetOriginalValue(sample); 64 estimated[sample - start] = est; 65 original[sample - start] = orig; 72 66 if(orig >= limit) positive++; 73 67 else negative++; … … 79 73 double tn = negative; 80 74 double fp = 0; 81 for(int i = original.Length -1; i >= 0; i--) {75 for(int i = original.Length - 1; i >= 0; i--) { 82 76 if(original[i] >= limit) { 83 77 tp++; fn--; … … 90 84 } 91 85 } 92 scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * (trainingEnd - trainingStart);93 86 return best_mcc; 94 87 }
Note: See TracChangeset
for help on using the changeset viewer.