In [1]:
%pylab inline

from tools import *
from dataset import *
from database import *
from PythonWrapper.descriptors import *
from search import *


Populating the interactive namespace from numpy and matplotlib

In [2]:
mapping = loadMapping()
descriptors = np.load("descriptors/ulbp_pca_lda_normalized_data_lbf_alignment_68_landmarks.npy")
database = loadDatabase(desc="ulbp_pca_lda", db="normalized_data_lbf_alignment_68_landmarks")

In [3]:
%timeit nnList(descriptors[0], database, 20)


10 loops, best of 3: 39.5 ms per loop

In [4]:
scores = []

for name, i in mapping:
    index = mapping[(name, i)]
    nn_scores, best_scores = nnSearch(descriptors[index], database, 21)
    for label, score in nn_scores:
        if label == name:
            scores.append((name, label, True, score))
            #scores.append((True, score - best_scores[0][1]))
        else:
            scores.append((name, label, False, score))
            
scores.sort(key=lambda x: x[-1], reverse=True)

In [5]:
precision = []
recall = []


tn = fp = 0
tp = fn = 0
for _, _, is_match, score in scores:
    if is_match:
        fn += 1
    else:
        tn += 1


for i in range(0, len(scores)):
    for (_, _, is_match, score) in scores[i:(i+1)]:
        if is_match:
            tp += 1
            fn -= 1 
        else:
            fp += 1
            tn -= 1
            
    precision.append(tp / float(tp + fp))
    recall.append(tp / float(tp + fn))

In [6]:
plot(recall, precision)
xlabel("Recall")
ylabel("Precision")


Out[6]:
<matplotlib.text.Text at 0x6902fd0>

In [7]:
print np.argmin(precision)


0

In [8]:
print np.max(precision)


0.0245901639344

In [9]:
for t in scores[:50]:
    print t


('Maria_Soledad_Alvear_Valenzuela', 'Winona_Ryder', False, 2.2791362924015397)
('Candice_Bergen', 'Naomi_Watts', False, 2.2530519002391838)
('Helen_Alvare', 'Laura_Bush', False, 2.2291835827216326)
('Melissa_Gilbert', 'Salma_Hayek', False, 2.2169119835908413)
('Ricardo_Lagos', 'Ariel_Sharon', False, 2.1926706551719648)
('Angela_Bassett', 'Halle_Berry', False, 2.1774721511412807)
('Charles_Moose', 'George_W_Bush', False, 2.1463076331517112)
('Angela_Bassett', 'Amelia_Vega', False, 2.1436357349420661)
('Bridget_Fonda', 'George_W_Bush', False, 2.1325797557133694)
('Ricardo_Lagos', 'Ariel_Sharon', False, 2.0990733176677701)
('Carlos_Paternina', 'Amelie_Mauresmo', False, 2.0981016081717052)
('Evan_Rachel_Wood', 'Laura_Bush', False, 2.0880585396229727)
('Angela_Bassett', 'Halle_Berry', False, 2.0792051748135529)
('Yukiko_Okudo', 'Laura_Bush', False, 2.0699812293481856)
('Kim_Clijsters', 'Tiger_Woods', False, 2.0694565408787686)
('Kristin_Davis', 'Naomi_Watts', False, 2.0598398993751448)
('Amelia_Vega', 'George_W_Bush', False, 2.0345181298712345)
('Norah_Jones', 'George_W_Bush', False, 2.0288811597828169)
('Francis_Collins', 'Bill_Gates', False, 2.0262335192903889)
('Hu_Maoyuan', 'Colin_Powell', False, 2.0250065203671079)
('Ann_Veneman', 'Laura_Bush', False, 2.0242830245829091)
('Kang_Gum-sil', 'Salma_Hayek', False, 2.0215466087404868)
('Princess_Caroline', 'George_W_Bush', False, 2.011331457344856)
('Annette_Lu', 'Yoriko_Kawaguchi', False, 2.0110505553081293)
('Oxana_Fedorova', 'Laura_Bush', False, 2.0086439285996414)
('Amram_Mitzna', 'George_W_Bush', False, 2.0011335345508177)
('Amelia_Vega', 'George_W_Bush', False, 1.9998353235811939)
('Woody_Allen', 'Hans_Blix', False, 1.9858240125782884)
('Chelsea_Clinton', 'George_W_Bush', False, 1.984946918790182)
('Richard_Rodriguez', 'Mark_Philippoussis', False, 1.9803398248835355)
('Talisa_Bratt', 'George_W_Bush', False, 1.9793776279576076)
('Ellen_Pompeo', 'George_W_Bush', False, 1.9790986307797382)
('Robin_Tunney', 'Laura_Bush', False, 1.977881704135815)
('Samira_Makhmalbaf', 'George_W_Bush', False, 1.9774987416237666)
('Norah_Jones', 'George_W_Bush', False, 1.9764969013357994)
('Lloyd_Novick', 'Ariel_Sharon', False, 1.9762006118093958)
('Jeb_Bush', 'George_W_Bush', False, 1.9748238333978383)
('Raquel_Welch', 'George_W_Bush', False, 1.9741388811653298)
('Elodie_Bouchez', 'George_W_Bush', False, 1.9666210190405164)
('Boris_Jordan', 'Ariel_Sharon', False, 1.9623327708100473)
('Norah_Jones', 'George_W_Bush', False, 1.9615645253073068)
('Harold_Brown', 'John_Negroponte', False, 1.9597512231477705)
('Ricardo_Lagos', 'Ariel_Sharon', False, 1.9595909235035085)
('William_Martin', 'Hans_Blix', False, 1.9547277735099948)
('Maria_Garcia', 'Megawati_Sukarnoputri', False, 1.9543916695019543)
('Penelope_Cruz', 'George_W_Bush', False, 1.9516707332933572)
('Melina_Kanakaredes', 'Amelia_Vega', False, 1.9514275054008603)
('Martina_McBride', 'George_W_Bush', False, 1.9507934005861258)
('Ryan_Newman', 'Ariel_Sharon', False, 1.9488323561093197)
('Paul_McCartney', 'Tony_Blair', False, 1.9463988185059169)

In [ ]: