% roc_randn.m
% Generate the ROC curve using perfcurve function.
% Datasets generated using randn function
% 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;
N = 100000;    % Number of samples for each class
% Class 0 data
X0 = m0 + sigma*randn(1,N);

% Class 1 data
X1 = m1 + sigma*randn(1,N);

histogram(X0);
hold on;
histogram(X1);



% Decease the decision boundary B continously to generate the ROC curve
% Both TPR and FPR will be in an increasing order
% B = 10: -0.01: -10;

labels = zeros(1, N);
scores = zeros(1, N);

B = 0;

% Scores are posterior probabilities

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'); 

    


