``````

In [1]:

import pandas as pd
import numpy as np
import scipy
import helper as hp
from IPython.display import HTML
from IPython.html import widgets
from IPython.display import display, clear_output

``````
``````

In [155]:

``````
``````

In [2]:

%pylab

``````
``````

Using matplotlib backend: MacOSX
Populating the interactive namespace from numpy and matplotlib

``````
``````

In [12]:

red = 'STAND_POINTING_RIGHT'
blue = 'STAND_POINTING_LEFT'
green = 'STAND_POINTING_FORWARD'

``````
``````

In [25]:

def calculate_params(TP, FP):
prec = map(precission, TP, FP)
rec = map(recall, TP, FP)
F1 = map(f1, TP, FP)
ACC = map(accuracy, TP, FP)

return [["{0:.2f}".format(np.mean(prec)), "{0:.2f}".format(np.std(prec)), "{0:.2f}".format(scipy.stats.sem(prec))],
["{0:.2f}".format(np.mean(rec)), "{0:.2f}".format(np.std(rec)), "{0:.2f}".format(scipy.stats.sem(rec))],
["{0:.2f}".format(np.mean(F1)), "{0:.2f}".format(np.std(F1)), "{0:.2f}".format(scipy.stats.sem(F1))],
["{0:.2f}".format(np.mean(ACC)), "{0:.2f}".format(np.std(ACC)), "{0:.2f}".format(scipy.stats.sem(ACC))]]

``````
``````

In [56]:

def precission(tp,fp):
if (tp+fp)==0:
return 0
return float(tp)/(tp+fp)

def recall(tp,fp): return float(tp)/6

def f1(tp,fp): return float((2*tp))/(2*tp+fp+6-tp)

def accuracy(tp, fp): return float(tp+6-fp)/(12)

``````

## Global Novelties

``````

In [47]:

K_GMM_n = 3*1000
K_KMeans_n = 1

K_GMM_s = 3*1000
K_KMeans_s = 1

Ks = [K_GMM_n, K_KMeans_n, K_GMM_s, K_KMeans_s]

``````
``````

In [48]:

GMM_tp = []
One_tp = []
LSA_tp = []
K_tp = []
GMM_fp = []
One_fp = []
LSA_fp = []
K_fp = []

'''
GLOBAL NOVELTIES
'''

size_train = 10

poses = [red, green, blue]

train_pose = red

for d in range(0,5):

indexes = [i for i in np.arange(30)]
indexes.pop(indexes.index(0))
indexes.pop(indexes.index(6))  # There is no 'user06' data, so we remove it
indexes.pop(indexes.index(12))

users, normal_users, queue = hp.start_users(size_train, train_pose, indexes)
users_normal = list(users)

u = []
for f in users_normal:
u.append(f[0])

GMM_n = []
one_n = []
lsa_n = []
K_n = []
GMM_s = []
one_s = []
lsa_s = []
K_s = []

J = list(set(indexes) - set(u) - set([6]))

for i in range(0,10):
x = random.choice(J)
J.pop(J.index(x))
[GMM_n1, one_n1, lsa_n1, K_n1, GMM_s1, one_s1, lsa_s1, K_s1] = hp.compute_scores(normal_users, queue, Ks)
GMM_s.append(GMM_s1)
one_s.append(one_s1)
lsa_s.append(lsa_s1)
K_s.append(K_s1)

GMM_fp.append(size([x for x in GMM_s if x[0] >= 1]))
One_fp.append(size([x for x in one_s if x[0] >= 1]))
LSA_fp.append(size([x for x in lsa_s if x[0] >= 1]))
K_fp.append(size([x for x in K_s if x[0] >= 1]))

GMM_n = []
one_n = []
lsa_n = []
K_n = []
GMM_s = []
one_s = []
lsa_s = []
K_s = []

J = list(set(range(1,31)) - set([6]))

for i in range(0,5):
x = random.choice(J)
J.pop(J.index(x))
[GMM_n1, one_n1, lsa_n1, K_n1, GMM_s1, one_s1, lsa_s1, K_s1] = hp.compute_scores(normal_users, queue, Ks)
GMM_s.append(GMM_s1)
one_s.append(one_s1)
lsa_s.append(lsa_s1)
K_s.append(K_s1)

for i in range(0,5):
x = random.choice(J)
J.pop(J.index(x))
[GMM_n1, one_n1, lsa_n1, K_n1, GMM_s1, one_s1, lsa_s1, K_s1] = hp.compute_scores(normal_users, queue, Ks)
GMM_s.append(GMM_s1)
one_s.append(one_s1)
lsa_s.append(lsa_s1)
K_s.append(K_s1)

GMM_tp.append(size([x for x in GMM_s if x[0] >= 1]))
One_tp.append(size([x for x in one_s if x[0] >= 1]))
LSA_tp.append(size([x for x in lsa_s if x[0] >= 1]))
K_tp.append(size([x for x in K_s if x[0] >= 1]))

``````
``````

In [49]:

algorithms = [[GMM_tp, GMM_fp],[One_tp, One_fp],[LSA_tp, LSA_fp],[K_tp, K_fp]]

r = []
for a in algorithms:
r.append(calculate_params(a[0], a[1]))

for t in range(0,4):
print str(r[0][t][0])+' & '+str(r[0][t][1])+' & '+str(r[0][t][2])+' & '+str(r[1][t][0])+' & '+str(r[1][t][1])+' & '+str(r[1][t][2])+' & '+str(r[2][t][0])+' & '+str(r[2][t][1])+' & '+str(r[2][t][2])+' & '+str(r[3][t][0])+' & '+str(r[3][t][1])+' & '+str(r[3][t][2])

``````
``````

0.73 & 0.03 & 0.02 & 0.73 & 0.12 & 0.06 & 0.77 & 0.11 & 0.06 & 0.84 & 0.12 & 0.06
0.98 & 0.04 & 0.02 & 1.00 & 0.00 & 0.00 & 0.72 & 0.22 & 0.11 & 0.74 & 0.19 & 0.09
0.84 & 0.03 & 0.02 & 0.84 & 0.08 & 0.04 & 0.73 & 0.17 & 0.09 & 0.78 & 0.15 & 0.07
0.81 & 0.04 & 0.02 & 0.79 & 0.13 & 0.07 & 0.76 & 0.12 & 0.06 & 0.80 & 0.11 & 0.05

``````

## In class novelties

``````

In [183]:

K_GMM_n = 3*10000
K_KMeans_n = 1

K_GMM_s = 30000
K_KMeans_s = 1

Ks = [K_GMM_n, K_KMeans_n, K_GMM_s, K_KMeans_s]

``````
``````

In [186]:

GMM_tp = []
One_tp = []
LSA_tp = []
K_tp = []
GMM_fp = []
One_fp = []
LSA_fp = []
K_fp = []

'''
IN CLASS
'''

size_train = 5

poses = [red, green, blue]

train_pose = blue

for d in range(0,5):

indexes = [1,8,11,12,14,16,17,18,19,20,26]

users, normal_users, queue = hp.start_users(size_train+1, train_pose, indexes)
users_normal = list(users)

u = []
for f in users_normal:
u.append(f[0])

GMM_n = []
one_n = []
lsa_n = []
K_n = []
GMM_s = []
one_s = []
lsa_s = []
K_s = []

J = list(set(indexes) - set(u))

for i in range(0,6):
x = random.choice(J)
J.pop(J.index(x))
[GMM_n1, one_n1, lsa_n1, K_n1, GMM_s1, one_s1, lsa_s1, K_s1] = hp.compute_scores(normal_users, queue, Ks)
GMM_s.append(GMM_s1)
one_s.append(one_s1)
lsa_s.append(lsa_s1)
K_s.append(K_s1)

GMM_fp.append(size([x for x in GMM_s if x[0] >= 1]))
One_fp.append(size([x for x in one_s if x[0] >= 1]))
LSA_fp.append(size([x for x in lsa_s if x[0] >= 1]))
K_fp.append(size([x for x in K_s if x[0] >= 1]))

GMM_n = []
one_n = []
lsa_n = []
K_n = []
GMM_s = []
one_s = []
lsa_s = []
K_s = []

J = list(set(range(1,31)) - set([6]))
J_1 = list(set(range(1,31)) - set([6]) - set(indexes))

for i in range(0,2):
x = random.choice(J_1)
J_1.pop(J_1.index(x))
[GMM_n1, one_n1, lsa_n1, K_n1, GMM_s1, one_s1, lsa_s1, K_s1] = hp.compute_scores(normal_users, queue, Ks)
GMM_s.append(GMM_s1)
one_s.append(one_s1)
lsa_s.append(lsa_s1)
K_s.append(K_s1)

for i in range(0,2):
x = random.choice(J)
J.pop(J.index(x))
[GMM_n1, one_n1, lsa_n1, K_n1, GMM_s1, one_s1, lsa_s1, K_s1] = hp.compute_scores(normal_users, queue, Ks)
GMM_s.append(GMM_s1)
one_s.append(one_s1)
lsa_s.append(lsa_s1)
K_s.append(K_s1)

for i in range(0,2):
x = random.choice(J)
J.pop(J.index(x))
[GMM_n1, one_n1, lsa_n1, K_n1, GMM_s1, one_s1, lsa_s1, K_s1] = hp.compute_scores(normal_users, queue, Ks)
GMM_s.append(GMM_s1)
one_s.append(one_s1)
lsa_s.append(lsa_s1)
K_s.append(K_s1)

GMM_tp.append(size([x for x in GMM_s if x[0] >= 1]))
One_tp.append(size([x for x in one_s if x[0] >= 1]))
LSA_tp.append(size([x for x in lsa_s if x[0] >= 1]))
K_tp.append(size([x for x in K_s if x[0] >= 1]))

``````
``````

In [187]:

algorithms = [[GMM_tp, GMM_fp],[One_tp, One_fp],[LSA_tp, LSA_fp],[K_tp, K_fp]]

r = []
for a in algorithms:
r.append(calculate_params(a[0], a[1]))

for t in range(0,4):
print str(r[0][t][0])+' & '+str(r[0][t][1])+' & '+str(r[0][t][2])+' & '+str(r[1][t][0])+' & '+str(r[1][t][1])+' & '+str(r[1][t][2])+' & '+str(r[2][t][0])+' & '+str(r[2][t][1])+' & '+str(r[2][t][2])+' & '+str(r[3][t][0])+' & '+str(r[3][t][1])+' & '+str(r[3][t][2])

``````
``````

0.91 & 0.07 & 0.03 & 0.58 & 0.05 & 0.02 & 0.94 & 0.07 & 0.03 & 0.70 & 0.06 & 0.03
0.97 & 0.07 & 0.03 & 1.00 & 0.00 & 0.00 & 0.97 & 0.07 & 0.03 & 0.97 & 0.07 & 0.03
0.94 & 0.03 & 0.02 & 0.73 & 0.04 & 0.02 & 0.95 & 0.04 & 0.02 & 0.81 & 0.04 & 0.02
0.93 & 0.03 & 0.02 & 0.63 & 0.07 & 0.03 & 0.95 & 0.04 & 0.02 & 0.77 & 0.06 & 0.03

``````
``````

In [ ]:

``````