about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/KPMtools/computeROC.m
diff options
context:
space:
mode:
authorziejd22017-09-28 15:04:40 -0500
committerziejd22017-09-28 15:04:40 -0500
commit8070dc963753142bb86c4ed698d91fd623ed28e7 (patch)
treed0f6dd8fc46a49b819aa55c1a90faa14d8448883 /sourcecodes/bnt-master/KPMtools/computeROC.m
parent7cc31810d53176e805532b2789955f4eedbce6bb (diff)
downloadBNW-8070dc963753142bb86c4ed698d91fd623ed28e7.tar.gz
BNW using Octave instead of Matlab.
This version of BNW should perform the same as the original version. The only difference is that it uses Octave instead of Matlab when running BayesNet Toolbox during parameter learning.

I am calling this BNW_1.02. It can be accessed at:
compbio.uthsc.edu/BNW_1.02
Diffstat (limited to 'sourcecodes/bnt-master/KPMtools/computeROC.m')
-rw-r--r--sourcecodes/bnt-master/KPMtools/computeROC.m64
1 files changed, 64 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/KPMtools/computeROC.m b/sourcecodes/bnt-master/KPMtools/computeROC.m
new file mode 100644
index 00000000..3b35332c
--- /dev/null
+++ b/sourcecodes/bnt-master/KPMtools/computeROC.m
@@ -0,0 +1,64 @@
+function [FPrate, TPrate, AUC, thresholds] = computeROC(confidence, testClass)
+% function [FPrate, TPrate, AUC, thresholds] = computeROC(confidence, testClass)
+%
+% computeROC computes the data for an ROC curve based on a classifier's confidence output.
+% It returns the false positive rate and the true positive rate along with
+% the area under the ROC curve, and the list of thresholds.
+%
+% Inputs: 
+%           - confidence(i) is proportional to the probability that
+%             testClass(i) is positive
+%
+% testClass = 0 => target absent
+% testClass = 1 => target present
+%
+% Based on algorithms 2 and 4 from Tom Fawcett's paper "ROC Graphs: Notes and
+% Practical Considerations for Data Mining Researchers" (2003)
+% http://www.hpl.hp.com/techreports/2003/HPL-2003-4.pdf"
+%
+% Vlad Magdin, 21 Feb 2005
+
+% break ties in scores
+S = rand('state');
+rand('state',0);
+confidence = confidence + rand(size(confidence))*10^(-10);
+rand('state',S)
+[thresholds order] = sort(confidence, 'descend');
+testClass = testClass(order);
+
+%%% -- calculate TP/FP rates and totals -- %%%
+AUC = 0;
+faCnt = 0;
+tpCnt = 0;
+falseAlarms = zeros(1,size(thresholds,2));
+detections = zeros(1,size(thresholds,2));
+fPrev = -inf;
+faPrev = 0;
+tpPrev = 0;
+
+P = max(size(find(testClass==1)));
+N = max(size(find(testClass==0)));
+
+for i=1:length(thresholds)
+    if thresholds(i) ~= fPrev
+        falseAlarms(i) = faCnt;
+        detections(i) = tpCnt;
+
+        AUC = AUC + polyarea([faPrev faPrev faCnt/N faCnt/N],[0 tpPrev tpCnt/P 0]);
+
+        fPrev = thresholds(i);
+        faPrev = faCnt/N;
+        tpPrev = tpCnt/P;
+    end
+    
+    if testClass(i) == 1
+        tpCnt = tpCnt + 1;
+    else
+        faCnt = faCnt + 1;
+    end
+end
+
+AUC = AUC + polyarea([faPrev faPrev 1 1],[0 tpPrev 1 0]);
+
+FPrate = falseAlarms/N;
+TPrate = detections/P;