In [1]:
import os
import urllib, cStringIO
import pymongo as pm
from IPython.display import clear_output
import matplotlib
from matplotlib import pylab, mlab, pyplot
%matplotlib inline
from IPython.core.pylabtools import figsize, getfigs
plt = pyplot
import seaborn as sns
sns.set_context('poster')
sns.set_style('white')
import numpy as np
from __future__ import division
import scipy.stats as stats
import pandas as pd
import json
import re
from PIL import Image
import base64
import analysis_helpers as h
reload(h)
## get standardized object list
categories = ['bird','car','chair','dog']
obj_list = []
for cat in categories:
for i,j in h.objcat.iteritems():
if j==cat:
obj_list.append(i)
In [2]:
model_prefixes = ['human']
PP = h.model_comparison_bars(model_prefixes,adaptor_type='human',split_type='balancedavg1')
h.plot_human_bars(PP)
In [3]:
PP
Out[3]:
In [4]:
adaptor_type = 'multimodal_fc6'
split_type = 'balancedavg1'
model_prefixes = [adaptor_type]
PP = h.model_comparison_bars(model_prefixes,adaptor_type=adaptor_type,split_type=split_type)
# h.plot_multimodal_bars(PP)
PP
Out[4]:
In [5]:
adaptor_type = 'multimodal_conv42'
split_type = 'balancedavg1'
model_prefixes = ['multimodal_conv42']
PP = h.model_comparison_bars(model_prefixes,adaptor_type=adaptor_type,split_type=split_type)
# h.plot_multimodal_bars(PP)
PP
Out[5]:
In [6]:
adaptor_type = 'multimodal_pool1'
split_type = 'balancedavg1'
# model_prefixes = ['multimodal_pool1','multimodal_conv42','multimodal_fc6']
model_prefixes = ['multimodal_pool1']
PP = h.model_comparison_bars(model_prefixes,adaptor_type=adaptor_type,split_type=split_type)
# h.plot_multimodal_bars(PP)
PP
Out[6]:
In [7]:
reallyRun = 0
if reallyRun:
h.check_mean_LL_for_cost_vs_nocost(model_prefixes=['multimodal_fc6'],
adaptor_type = 'multimodal_fc6',
split_type='balancedavg1',
plot=True)
In [8]:
### FIRST STEP:
### iterate through Params and write back out in "flattened" form
reload(h)
reallyRun = 0
if reallyRun:
h.flatten_param_posterior(adaptor_types = ['multimodal_pool1','multimodal_conv42','multimodal_fc6', 'human'],
verbosity=1)
In [9]:
#### SECOND STEP: Go to RSA.py and run evaluate on all of the models and splits
### e.g.,
### python RSA.py --wppl evaluate --perception human --pragmatics combined S0 --production cost nocost --split_type balancedavg1 balancedavg2 balancedavg3 balancedavg4 balancedavg5
### python RSA.py --wppl evaluate --perception multimodal_fc6 --pragmatics combined S0 --production cost nocost --split_type balancedavg1 balancedavg2 balancedavg3 balancedavg4 balancedavg5
### python RSA.py --wppl evaluate --perception multimodal_conv42 --pragmatics combined S0 --production cost nocost --split_type balancedavg1 balancedavg2 balancedavg3 balancedavg4 balancedavg5
### python RSA.py --wppl evaluate --perception multimodal_pool1 --pragmatics combined S0 --production cost nocost --split_type balancedavg1 balancedavg2 balancedavg3 balancedavg4 balancedavg5
In [10]:
### OPTIONAL: prior to running bda-enumerate, wouldn't it help to get a sense for the extreme values
### in the param posterior for each model, for each split to make sure our grid covers
### everywhere where there is some mass in the posterior?
reload(h)
reallyRun = 0
if reallyRun:
h.get_sense_for_param_range_across_splits()
./get_all_model_predictions.py
, which is a wrapper around
this script, ./generate_model_predictions.py
to generate csv files that
summarize key statistics of interest (e.g., target rank, cost)
from model predictions, for each model and data split.
In [11]:
import analysis_helpers as h
reload(h)
print h.load_all_model_preds.__doc__
In [12]:
P = h.load_all_model_preds(verbosity=1)
In [13]:
# for i in np.arange(1,6):
# _P = P['human_combined_cost']['balancedavg{}'.format(i)]
# print _P.groupby('condition')['cost'].mean()
split_types = ['balancedavg1','balancedavg2','balancedavg3','balancedavg4','balancedavg5']
model_space = ['human_combined_cost','human_S0_cost','human_combined_nocost','multimodal_fc6_combined_cost',
'multimodal_fc6_S0_cost','multimodal_fc6_combined_nocost','multimodal_conv42_combined_cost',
'multimodal_pool1_combined_cost]
H = human_combined_cost
H0 = human_S0_cost
H1 = human_combined_nocost
M = multimodal_fc6_combined_cost
M0 = multimodal_conv42_combined_cost
M1 = multimodal_fc6_S0_cost
M2 = multimodal_fc6_combined_nocost
M3 = multimodal_pool1_combined_cost
In [14]:
import analysis_helpers as h
reload(h)
sns.set_context('talk')
split_type = 'balancedavg1'
In [ ]:
In [15]:
h.plot_target_vs_foil_rank_by_object(P,split_type=split_type)
In [16]:
import analysis_helpers as h
reload(h)
h.plot_avg_rank_all_models(P,split_type=split_type)
In [17]:
import analysis_helpers as h
reload(h)
h.plot_prop_congruent_all_models(P,split_type=split_type)
In [18]:
reallyRun = 0
if reallyRun:
h.get_top_k_predictions(P,split_type=split_type,verbosity=1)
In [19]:
import analysis_helpers as h
reload(h)
h.plot_topk_all_models()
In [20]:
### show the average cost (time, strokes, ink) for average model prediction
In [21]:
split_type = 'balancedavg1'
In [22]:
import analysis_helpers as h
reload(h)
HU,H0U,H1U,MU,M0U,M1U,M2U,M3U = h.get_avg_cost_all_models(P, split_type=split_type)
In [23]:
saveout=True
sns.set_context('talk')
fig = plt.figure(figsize=(5,8))
ax = fig.add_subplot(111)
U = pd.concat([HU,H0U,H1U,MU,M0U,M1U,M2U,M3U],axis=0)
sns.barplot(data=U,
x='adaptor',
y='cost',
hue='condition',
ci='sd',
order=['human_combined_cost','human_S0_cost','human_combined_nocost','multimodal_fc6_combined_cost',
'multimodal_fc6_S0_cost','multimodal_fc6_combined_nocost','multimodal_conv42_combined_cost', \
'multimodal_pool1_combined_cost'])
plt.ylabel('normalized sketch duration')
plt.ylim([0,0.4])
xticklabels=['Context Cost Human','NoContext Cost Human','Context NoCost Human','Context Cost HighAdaptor',
'NoContext Cost HighAdaptor','Context NoCost HighAdaptor', 'Context Cost MidAdaptor', 'Context Cost LowAdaptor']
plt.xlabel('')
l = ax.set_xticklabels(xticklabels, rotation = 90, ha="left")
plt.legend(bbox_to_anchor=(1., 1.))
plt.tight_layout()
if saveout:
plt.savefig('./plots/prop_congruent_all_models.pdf')
In [ ]:
In [ ]:
In [24]:
import analysis_helpers as h
reload(h)
Out[24]:
In [25]:
## load in boot filelist
boot_files = h.load_and_check_bootstrapped_model_preds()
## generate dataframe from boot filelist
B = h.generate_bootstrap_model_preds_dataframe(boot_files, out_dir='./bootstrap_results')
In [26]:
split_types = ['balancedavg1','balancedavg2','balancedavg3','balancedavg4','balancedavg5']
model_space = ['human_combined_cost','human_S0_cost','human_combined_nocost','multimodal_fc6_combined_cost',\
'multimodal_fc6_S0_cost','multimodal_fc6_combined_nocost','multimodal_conv42_combined_cost',\
'multimodal_pool1_combined_cost']
vois = list(np.unique(B.var_of_interest.values))
In [27]:
import analysis_helpers as h
reload(h)
## make dataframe
R = h.generate_aggregated_estimate_dataframe(B,
condition_list = ['all'],
model_space=model_space,
split_types=split_types,
var_of_interest='target_rank')
## make plot
h.plot_average_target_rank_across_splits(R,
var_of_interest='target_rank',
condition_list = ['all'],
model_space=model_space,
split_types=split_types,
condition='all',
sns_context='talk',
figsize=(6,10),
errbar_multiplier=1.,
ylabel='rank of correct sketch')
In [28]:
reload(h)
## make dataframe
R = h.generate_aggregated_estimate_dataframe(B,
condition_list = ['all'],
model_space=model_space,
split_types=split_types,
var_of_interest='sign_diff_rank')
## make plot
h.plot_prop_congruent_across_splits(R,
var_of_interest='sign_diff_rank',
condition_list = ['all'],
model_space=model_space,
split_types=split_types,
condition='all',
sns_context='talk',
figsize=(6,10),
errbar_multiplier=1.,
ylabel='proportion congruent context preferred')
In [ ]:
In [29]:
reload(h)
## make dataframe
R = h.generate_aggregated_estimate_dataframe(B,
condition_list = ['closer','further'],
model_space=model_space,
split_types=split_types,
var_of_interest='cost')
## make plot
h.plot_cost_by_condition_across_splits(R,
var_of_interest='cost',
condition_list = ['closer','further'],
model_space=model_space,
split_types=split_types,
condition='all',
sns_context='talk',
figsize=(6,10),
errbar_multiplier=1.,
ylabel='predicted sketch cost')
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: