def roc_curves(n_samples, p_value=False): """ """ data = generate_data(n_samples=n_samples) X, Y = data[:, :-1], data[:, -1] if p_value: I = np.abs(0.5 - compute_values(X)) else: I = mutual_information(X, Y) tau_min, tau_max = I.min(), I.max() if not p_value and tau_min < 0: tau_min = 0 print "warning - tau_min < 0" step = 500 erange = [tau_min + i * (tau_max - tau_min) * 1. / step for i in range(step)] roc_x = [] roc_y = [] for tau in erange: pos = I > tau tp = pos[1000:].sum() tn = (1 - pos[:1000]).sum() roc_x.append(float(tp) / (200)) roc_y.append(1 - float(tn) / (1000)) return np.array(roc_x), np.array(roc_y), np.array(erange)
def compute_ratios(tau, p_value=False): data = generate_data(n_samples=1000) X, Y = data[:, :-1], data[:, -1] if p_value: I = np.abs(0.5 - compute_values(X)) else: I = mutual_information(X, Y) pos = I > tau fp = pos[:1000].sum() fn = (1 - pos[1000:]).sum() tp = pos[1000:].sum() tn = (1 - pos[:1000]).sum() return fp, fn, tp, tn