In [28]:
import cPickle
import numpy as np
import matplotlib.pyplot as plt

# PARAMS
log_dir = "/home/sforesti/avakas/scratch/sforestier001/logs/PLAY2017/2017-12-06_13-54-22-play"
config_list = ["PC", "C08T05", "C08T2", "C03T05", "C03T2"]

tol = 0.4

data_vocal = {}
for config_name in config_list:
    print config_name
    filename = log_dir + '/results/' + config_name + '_vocal.pickle'
    with open(filename, 'r') as f:
        data_vocal[config_name] = cPickle.load(f)[config_name]


PC
C08T05
C08T2
C03T05
C03T2

In [30]:
%matplotlib inline
import seaborn as sns
import numpy as np

n_trials = 50

plt.rc('text', usetex=True)
plt.rc('font', family='serif')
n_iter = 80000
iter_ds = 100
trial_list = range(1,n_trials + 1) 
config_name = "PC"

x = [iter_ds*i for i in range(n_iter/iter_ds)]

for trial in [2]:
    human_sounds = data_vocal[config_name][trial]["human_sounds"][:6]   
    print human_sounds
    
    #human_sounds = ["yeo", "iuo", "eou", "eyu", "uye", "oey"]   # Sort for better color rendering 
    plots = []
    for hs in human_sounds[:6]:
        p, = plt.plot(x, [data_vocal[config_name][trial]["errors"][i][hs] for i in range(n_iter/iter_ds)], label=hs, lw=3)
        plots.append(p)
        
plt.ylim([0, 1.])       
plt.xlim([0, n_iter])  


plt.xlabel("Time", fontsize=18)
plt.ylabel("Vocal Error", fontsize=18)

#plt.xticks([0, 20000, 40000, 60000, 80000], ["$0$", r"$2\times10^4$", r"$4\times10^4$", r"$6\times10^4$", r"$8\times10^4$"], fontsize = 16)
plt.xticks([0, 20000, 40000, 60000, 80000], ["$0$", "$20000$", "$40000$", "$60000$", "$80000$"], fontsize = 16)
plt.yticks(fontsize = 16)



#pdummy, = plt.plot([0], marker='None',
#           linestyle='None', label='dummy-tophead')

#legend = plt.legend([pdummy, plots[0], plots[1], plots[2], pdummy, plots[3], plots[4], plots[5]],
#              ['Toy names:'] + ["   " + s for s in human_sounds[:3]] + ['Distractors:'] + ["   " + s for s in human_sounds[3:]],
#              ncol=2, frameon=True, fontsize=14) # Two columns, vertical group labels

legend = plt.legend(ncol=2, frameon=True, fontsize=16)

frame = legend.get_frame()
frame.set_facecolor('1.')
frame.set_edgecolor('0.')

plt.plot((0, n_iter), (tol, tol), 'k--', lw=2)

plt.savefig('../figs/fig_vocal_errors_example.pdf', format='pdf', bbox_inches='tight')


['oie', 'yue', 'ueo', 'eyi', 'uoi', 'uey']

In [31]:
for trial in trial_list:
    human_sounds = data_vocal[config_name][trial]["human_sounds"]    
    if data_vocal[config_name][trial]["errors"][-1][human_sounds[0]] > 0.4 or data_vocal[config_name][trial]["errors"][-1][human_sounds[1]] > 0.4 or data_vocal[config_name][trial]["errors"][-1][human_sounds[0]] > 0.4:
        min_hs = 0
        min_error = 1
        for i in range(6):
            if data_vocal[config_name][trial]["errors"][-1][human_sounds[i]] < min_error:
                min_error = data_vocal[config_name][trial]["errors"][-1][human_sounds[0]]
                min_hs = i
        if min_hs < 3:
            print trial


6
8
24
27
32
34
37
39
41
52
57
64
65
66
70
72
75
76
88
89
95

In [31]:
ee_list_s = []
ee_list_ns = []

for trial in trial_list:
    if data_vocal[config_name][trial].has_key("human_sounds"):
        human_sounds = data_vocal[config_name][trial]["human_sounds"]    
        for hs in human_sounds[:3]:
            ee_list_s += [[data_vocal[config_name][trial]["errors"][i][hs] for i in range(n_iter/iter_ds)]]

        for hs in human_sounds[3:]:
            ee_list_ns += [[data_vocal[config_name][trial]["errors"][i][hs] for i in range(n_iter/iter_ds)]]
        
        
x = [iter_ds*i for i in range(n_iter/iter_ds)]
plt.errorbar(x, np.mean(ee_list_s, axis=0)[:n_iter/iter_ds], np.std(ee_list_s, axis=0)[:n_iter/iter_ds], label="toy names", lw=2, errorevery=50)
plt.errorbar(x, np.mean(ee_list_ns, axis=0)[:n_iter/iter_ds], np.std(ee_list_ns, axis=0)[:n_iter/iter_ds], label="distractors", lw=2, errorevery=50)

plt.xlabel("Time", fontsize=20)
plt.ylabel("Vocal Error", fontsize=20)
plt.ylim([0, 0.7])       
plt.xlim([0, n_iter])  
plt.plot((0, n_iter), (tol, tol), 'k--', lw=2)
legend=plt.legend(frameon=True, fontsize=20)
frame = legend.get_frame()
frame.set_facecolor('1.')
frame.set_edgecolor('0.')



In [32]:
def vocal_error_evolution(config_name, n_trials):


    ta = 500
    tb = 50
    var="std"

    import numpy as np
    import seaborn as sns
    import brewer2mpl
    bmap = brewer2mpl.get_map('Dark2', 'qualitative', 4)
    colors = bmap.mpl_colors

    def time_limit(error_evolution):
        tl = len(error_evolution)-1
        while tl > 0 and error_evolution[tl] < tol:
            tl -= 1
        return tl

    def synchro(ee_list):
        l = []
        for ee in ee_list:
            tl_ee = time_limit(ee)
            if tl_ee < n_iter/iter_ds-ta and tl_ee > tb:
                l += [ee[tl_ee-tb:tl_ee+ta]]
        return l



    ee_list_s = []
    ee_list_ns = []

    for trial in trial_list:
        if data_vocal[config_name][trial].has_key("human_sounds"):
            human_sounds = data_vocal[config_name][trial]["human_sounds"]    
            for hs in human_sounds[:3]:
                ee_list_s += [[data_vocal[config_name][trial]["errors"][i][hs] for i in range(n_iter/iter_ds)]]

            for hs in human_sounds[3:]:
                ee_list_ns += [[data_vocal[config_name][trial]["errors"][i][hs] for i in range(n_iter/iter_ds)]]

    ee_s_synchro = synchro(ee_list_s)
    ee_ns_synchro = synchro(ee_list_ns)

    print len(ee_s_synchro)
    print len(ee_ns_synchro)


    x = [iter_ds*(i - tb) for i in range(ta+tb)]

    y = np.percentile(ee_s_synchro, 50, axis=0)
    #error = np.std(ee_s_synchro, axis=0)
    plt.plot(x, y, label="Toy Names", lw=2, color=colors[1])
    plt.fill_between(x, np.percentile(ee_s_synchro, 25, axis=0), np.percentile(ee_s_synchro, 75, axis=0), color=colors[1], alpha=0.2)
    #plt.plot(x, np.percentile(ee_s_synchro, 75, axis=0), color=colors[1], alpha=0.25)
    #plt.plot(x, np.percentile(ee_s_synchro, 25, axis=0), color=colors[1], alpha=0.25)

    y = np.median(ee_ns_synchro, axis=0)
    #error = np.std(ee_ns_synchro, axis=0)
    plt.plot(x, y, label="Distractors", lw=2, color=colors[2])
    plt.fill_between(x, np.percentile(ee_ns_synchro, 25, axis=0), np.percentile(ee_ns_synchro, 75, axis=0), color=colors[2], alpha=0.2)
    #plt.plot(x, np.percentile(ee_ns_synchro, 75, axis=0), color=colors[2], alpha=0.25, lw=2)
    #plt.plot(x, np.percentile(ee_ns_synchro, 25, axis=0), color=colors[2], alpha=0.25, lw=2)

    print "Avg diff", abs(np.mean(ee_s_synchro, axis=0)[-1] - np.mean(ee_ns_synchro, axis=0)[-1])
    print "Std", np.std(ee_s_synchro, axis=0)[-1], np.std(ee_ns_synchro, axis=0)[-1]


    plt.rc('text', usetex=True)
    plt.rc('font', family='serif')

    plt.xlabel("Time after recognition", fontsize=16)
    plt.ylabel("Vocal Error", fontsize=16)
    plt.ylim([0, 1])       
    plt.xlim([-iter_ds*tb, iter_ds*ta])  
    plt.plot((-iter_ds*tb, iter_ds*ta), (tol, tol), 'k--', lw=2)
    legend = plt.legend(frameon=True, fontsize=16)

    plt.xticks(fontsize = 14)
    plt.yticks(fontsize = 14)

    frame = legend.get_frame()
    frame.set_facecolor('1.')
    frame.set_edgecolor('0.')

    plt.savefig('../figs/fig_vocal_errors_' + config_name.replace(".", "") + '.pdf', format='pdf', bbox_inches='tight')

In [33]:
vocal_error_evolution("PC", 50)


38
421
Avg diff 0.0863030043568
Std 0.0629973729057 0.0492347352444

In [35]:
vocal_error_evolution("C08T2", 50)


30
469
Avg diff 0.0803708366472
Std 0.0741783524727 0.0483588179502

In [11]:
import seaborn as sns
from scipy import stats
import numpy as np


plt.rc('text', usetex=True)
plt.rc('font', family='serif')

sns.distplot([ee[-1] for ee in ee_list_s], bins=np.arange(0., 1., 0.025), color=colors[1], hist_kws={'edgecolor':'gray'}, kde_kws={"lw":3}, label="Toy Names")
sns.distplot([ee[-1] for ee in ee_list_ns], bins=np.arange(0., 1., 0.025), color=colors[2], hist_kws={'edgecolor':'gray'}, kde_kws={"lw":3}, label="Distractors")
legend = plt.legend(frameon=True, fontsize=14)
plt.xlabel("Vocal error", fontsize=16)
plt.ylabel("Density", fontsize=16)
plt.plot((tol, tol), (0, 5), 'k--', lw=2)

plt.xticks(fontsize = 16)
plt.yticks(fontsize = 16)

frame = legend.get_frame()
frame.set_facecolor('1.')
frame.set_edgecolor('0.')

print np.median([ee[-1] for ee in ee_list_s])
print np.median([ee[-1] for ee in ee_list_ns])

print "Data points:", len(ee_list_s), "per condition"

plt.savefig('../figs/fig_vocal_errors_distribution.pdf', format='pdf', bbox_inches='tight')


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-11-3fafacce1014> in <module>()
      7 plt.rc('font', family='serif')
      8 
----> 9 sns.distplot([ee[-1] for ee in ee_list_s], bins=np.arange(0., 1., 0.025), color=colors[1], hist_kws={'edgecolor':'gray'}, kde_kws={"lw":3}, label="Toy Names")
     10 sns.distplot([ee[-1] for ee in ee_list_ns], bins=np.arange(0., 1., 0.025), color=colors[2], hist_kws={'edgecolor':'gray'}, kde_kws={"lw":3}, label="Distractors")
     11 legend = plt.legend(frameon=True, fontsize=14)

NameError: name 'colors' is not defined

In [26]:
# STATS
import scipy

data1 = [ee[-1] for ee in ee_list_s]
data2 = [ee[-1] for ee in ee_list_ns]

z, p = scipy.stats.mannwhitneyu(data1, data2)
p_value = p * 2
print p_value


1.38703353668e-73

In [29]:
n_under = len([error for error in data1 + data2 if error < 0.4])
print n_under
print n_under / float(len(data1) + len(data2))


2611
0.880904183536

In [36]:
def vocal_error_distribution(config_name, n_trials):

    trial_list = range(1, n_trials + 1)
    n_iter = 80000
    iter_ds = 100

    %matplotlib inline
    import seaborn as sns
    from scipy import stats
    import numpy as np

    import brewer2mpl
    bmap = brewer2mpl.get_map('Dark2', 'qualitative', 4)
    colors = bmap.mpl_colors

    plt.rc('text', usetex=True)
    plt.rc('font', family='serif')



    ee_list_s = []
    ee_list_ns = []

    for trial in trial_list:
        if data_vocal[config_name][trial].has_key("human_sounds"):
            human_sounds = data_vocal[config_name][trial]["human_sounds"]    
            for hs in human_sounds[:3]:
                ee_list_s += [[data_vocal[config_name][trial]["errors"][i][hs] for i in range(n_iter/iter_ds)]]

            for hs in human_sounds[3:]:
                ee_list_ns += [[data_vocal[config_name][trial]["errors"][i][hs] for i in range(n_iter/iter_ds)]]



    sns.distplot([ee[-1] for ee in ee_list_s], bins=np.arange(0., 1., 0.025), color=colors[1], hist_kws={'edgecolor':'gray'}, kde_kws={"lw":3}, label="Toy Names")
    sns.distplot([ee[-1] for ee in ee_list_ns], bins=np.arange(0., 1., 0.025), color=colors[2], hist_kws={'edgecolor':'gray'}, kde_kws={"lw":3}, label="Distractors")
    legend = plt.legend(frameon=True, fontsize=14)
    plt.xlabel("Vocal error", fontsize=16)
    plt.ylabel("Density", fontsize=16)
    
    plt.plot((tol, tol), (0, 4.5), 'k--', lw=2)

    plt.xlim([0, 0.9])
    plt.ylim([0, 5])
    plt.xticks(fontsize = 14)
    plt.yticks([0, 1, 2, 3, 4], fontsize = 14)

    frame = legend.get_frame()
    frame.set_facecolor('1.')
    frame.set_edgecolor('0.')


    print "# Toy names:", len(ee_list_s)
    print "# Distractors:", len(ee_list_ns)
    
    print "# Toy names median error:", np.median([ee[-1] for ee in ee_list_s])
    print "# Distractors median error:", np.median([ee[-1] for ee in ee_list_ns])
    print "# Toy names mean error:", np.mean([ee[-1] for ee in ee_list_s])
    print "# Distractors mean error:", np.mean([ee[-1] for ee in ee_list_ns])
    
    plt.savefig('../figs/fig_vocal_errors_distribution_' + config_name.replace(".", "") + '.pdf', format='pdf', bbox_inches='tight')
    
    return np.median([ee[-1] for ee in ee_list_s]), np.percentile([ee[-1] for ee in ee_list_s], 25), np.percentile([ee[-1] for ee in ee_list_s], 75)

In [38]:
med_05, q25_05, q75_05 = vocal_error_distribution("PC", 50)


# Toy names: 138
# Distractors: 2622
# Toy names median error: 0.383834182622
# Distractors median error: 0.43110598124
# Toy names mean error: 0.367380959233
# Distractors mean error: 0.432727700994

In [39]:
med_075, q25_075, q75_075 = vocal_error_distribution("C03T05", 50)


# Toy names: 141
# Distractors: 2679
# Toy names median error: 0.430265200773
# Distractors median error: 0.43044919431
# Toy names mean error: 0.403573196091
# Distractors mean error: 0.430463693388

In [40]:
med_1, q25_1, q75_1 = vocal_error_distribution("C03T2", 50)


# Toy names: 150
# Distractors: 2850
# Toy names median error: 0.42970205907
# Distractors median error: 0.428830444771
# Toy names mean error: 0.405283207587
# Distractors mean error: 0.4287138923

In [41]:
med_15, q25_15, q75_15 = vocal_error_distribution("C08T05", 50)


# Toy names: 141
# Distractors: 2679
# Toy names median error: 0.414973112189
# Distractors median error: 0.431500391383
# Toy names mean error: 0.386866906407
# Distractors mean error: 0.431294400989

In [42]:
med_2, q25_2, q75_2 = vocal_error_distribution("C08T2", 50)


# Toy names: 144
# Distractors: 2736
# Toy names median error: 0.395912982616
# Distractors median error: 0.428486627468
# Toy names mean error: 0.365672215346
# Distractors mean error: 0.430468693514

In [ ]:


In [ ]: