Changeset 672
- Timestamp:
- 10/15/08 17:26:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/ROCAnalyzer.cs
r669 r672 39 39 : base() { 40 40 AddVariableInfo(new VariableInfo("Values", "Item list holding the estimated and orignial values for the ROCAnalyzer", typeof(ItemList), VariableKind.In)); 41 AddVariableInfo(new VariableInfo("ROCValues", "The values of the ROCAnalyzer, namely TPR & FPR", typeof(ItemList ), VariableKind.New | VariableKind.Out));41 AddVariableInfo(new VariableInfo("ROCValues", "The values of the ROCAnalyzer, namely TPR & FPR", typeof(ItemList<ItemList<DoubleArrayData>>), VariableKind.New | VariableKind.Out)); 42 42 } 43 43 44 44 public override IOperation Apply(IScope scope) { 45 45 ItemList values = GetVariableValue<ItemList>("Values", scope, true); 46 ItemList rocValues = GetVariableValue<ItemList>("ROCValues", scope, false, false);46 ItemList<ItemList<DoubleArrayData>> rocValues = GetVariableValue<ItemList<ItemList<DoubleArrayData>>>("ROCValues", scope, false, false); 47 47 if (rocValues == null) { 48 rocValues = new ItemList ();48 rocValues = new ItemList<ItemList<DoubleArrayData>>(); 49 49 IVariableInfo info = GetVariableInfo("ROCValues"); 50 50 if (info.Local) … … 52 52 else 53 53 scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(info.FormalName), rocValues)); 54 } else 54 } else { 55 55 rocValues.Clear(); 56 } 56 57 58 rocValues.Add(new ItemList<DoubleArrayData>()); 57 59 //ROC Curve starts at 0,0 58 ItemList row = new ItemList(); 59 row.Add(new DoubleData(0)); 60 row.Add(new DoubleData(0)); 61 rocValues.Add(row); 60 DoubleArrayData point = new DoubleArrayData(); 61 point.Data = new double[2] { 0, 0 }; 62 rocValues[0].Add(point); 62 63 63 64 //calculate new ROC Values 64 double estimated =0.0;65 double original =0.0;65 double estimated = 0.0; 66 double original = 0.0; 66 67 double positiveClassKey; 67 68 double negativeClassKey; 68 double truePositiveRate =0.0;69 double falsePositiveRate =0.0;69 double truePositiveRate = 0.0; 70 double falsePositiveRate = 0.0; 70 71 71 72 //initialize classes dictionary … … 90 91 positiveClassKey = classes.Keys.Min<double>(); 91 92 negativeClassKey = classes.Keys.Max<double>(); 92 for (int i = 0; i < classes[negativeClassKey].Count; i++) { 93 truePositiveRate = classes[positiveClassKey].Count<double>(value => value < classes[negativeClassKey][i]) / classes[positiveClassKey].Count; 94 falsePositiveRate = i / classes[negativeClassKey].Count; 95 row = new ItemList(); 96 row.Add(new DoubleData(falsePositiveRate)); 97 row.Add(new DoubleData(truePositiveRate)); 98 rocValues.Add(row); 93 foreach (double treshold in classes[negativeClassKey].Distinct<double>()) { 94 truePositiveRate = ((double)classes[positiveClassKey].Count<double>(value => value < treshold)) / classes[positiveClassKey].Count; 95 falsePositiveRate = ((double)classes[negativeClassKey].Count<double>(value => value < treshold)) / classes[negativeClassKey].Count; 96 point = new DoubleArrayData(new double[2] { falsePositiveRate, truePositiveRate }); 97 rocValues[0].Add(point); 99 98 100 99 //stop calculation if truePositiveRate = 1; save runtime … … 105 104 //add case when treshold == max negative class value => falsePositiveRate ==1 106 105 if (truePositiveRate != 1.0) { 107 108 truePositiveRate = classes[positiveClassKey].Count<double>(value => value <= classes[negativeClassKey][classes[negativeClassKey].Count - 1]) / classes[positiveClassKey].Count; 106 truePositiveRate = ((double)classes[positiveClassKey].Count<double>(value => value <= classes[negativeClassKey][classes[negativeClassKey].Count - 1])) / classes[positiveClassKey].Count; 109 107 falsePositiveRate = 1; 110 row = new ItemList(); 111 row.Add(new DoubleData(falsePositiveRate)); 112 row.Add(new DoubleData(truePositiveRate)); 113 rocValues.Add(row); 108 point = new DoubleArrayData(new double[2] { falsePositiveRate, truePositiveRate }); 109 rocValues[0].Add(point); 114 110 } else { 115 111 //ROC ends at 1,1 116 row = new ItemList(); 117 row.Add(new DoubleData(1)); 118 row.Add(new DoubleData(1)); 119 rocValues.Add(row); 112 point = new DoubleArrayData(new double[2] { 1, 1 }); 113 rocValues[0].Add(point); 120 114 } 121 115
Note: See TracChangeset
for help on using the changeset viewer.