#!/usr/bin/python import sys import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl import math from sets import ImmutableSet mpl.rcParams['font.size'] = 5 mpl.rcParams['lines.linewidth'] = 0.5 mpl.rcParams['figure.figsize'] = 2.2,2.2 mpl.rcParams['legend.fontsize'] = 5 mpl.rcParams['axes.linewidth'] = 0.5 mpl.rcParams['figure.subplot.hspace'] = 0.4 mpl.rcParams['figure.subplot.wspace'] = 0.4 legend_width = 0.2 def distance(a,b): return math.sqrt(np.square(a-b).sum()) def gen_pairs(var,sk_data): np.random.shuffle(sk_data) sk_data = sk_data[:,1:] noise1 = np.random.normal(0,var,sk_data.shape) noise2 = np.random.normal(0,var,sk_data.shape) sk1 = sk_data+noise1 sk2 = sk_data+noise2 randoms = np.random.randint(0,sk_data.shape[0],(2000,2)) dict = {} u_pairs = [] i = 0 while len(u_pairs) < sk_data.shape[0]: pair = randoms[i] key = ImmutableSet(pair) i += 1 if pair[0] != pair[1] and key not in dict: dict[key] = True u_pairs += [(pair[0],pair[1])] m_pairs = zip(range(sk_data.shape[0]),range(sk_data.shape[0])) result = [] for j in range(sk_data.shape[0]): result += [(distance(sk1[m_pairs[j][0]],sk2[m_pairs[j][1]]), distance(sk1[u_pairs[j][0]],sk2[u_pairs[j][1]]))] return result if __name__ == "__main__": plt.figure(figsize=(3,2.2)) ap = np.loadtxt("associatepredict.txt",delimiter=",") indices = [i for i in range(ap.shape[0]) if ap[i,1]<0.1] ap_false = ap[:,1][indices] ap_true = ap[:,0][indices] plt.plot(100*ap_false,100*ap_true,label="Face recognition") plt.xlabel("False positive rate [%]") plt.ylabel("True positive rate [%]") np.random.seed() std = map(float,sys.argv[2].split(",")) sk_data = np.loadtxt(sys.argv[1],comments="#",delimiter=",") for s in std: result = gen_pairs(s,sk_data) thresholds = np.square(np.arange(0,10,0.001)) true_pos = [] false_pos = [] for threshold in thresholds: true = 0 false = 0 for j in range(len(result)): if result[j][0] < threshold: true += 1 if result[j][1] < threshold: false += 1 true_pos += [float(true)/len(result)] false_pos += [float(false)/len(result)] indices = [i for i in range(len(false_pos)) if false_pos[i]<0.1] false_pos = np.array(false_pos) false_pos = false_pos[indices] true_pos = np.array(true_pos) true_pos = true_pos[indices] plt.plot(100*false_pos,100*true_pos,label="$\sigma$ = "+str(s)) leg = plt.legend(loc="lower right") leg.get_frame().set_linewidth(legend_width) plt.savefig("roc.pdf",bbox_inches="tight",pad_inches=0.05)