% roc_pdf.m
% Generate the ROC curve using PDFs
% Two Gaussian random variables with means being m0 (Class 0) and m1 
% (class 1) and the same variance.
% Dr. David Pan, UAH

clear all;
close all;
D = 1;  % 2D is the distance between two means
sigma = 1;
m0 = -D;
m1 = D;
x = -10:0.01:10;
f0 = 1/(sqrt(2*pi)*sigma)*exp(-(x-m0).^2/(2*sigma^2));
f1 = 1/(sqrt(2*pi)*sigma)*exp(-(x-m1).^2/(2*sigma^2));
plot(x,f0);
hold on;
plot(x,f1);
grid

B = 0;  % B is the decision boundary
% TPR for Class 1
TPR = qfunc((B - m1)/sigma)
% FPR 
FPR = qfunc((B - m0)/sigma)

% Decease B continously to generate the ROC curve
% Both TPR and FPR will be in an increasing order
B = 10: -0.01: -10;
TPR = qfunc((B - m1)/sigma);
FPR = qfunc((B - m0)/sigma);

% Area under the ROC curve
% Note: Both FPR and TPR are going from highest to lowest
AUC = trapz(FPR, TPR)

figure;
plot(FPR, TPR); grid
xlabel('False Positive Rate');
ylabel('True Positive Rate');
title('ROC'); 

    


