Exemplo n.º 1
0
    def behav_olddata(self):
        self.model_name = 'behav'
        sil = pandas.read_csv('snodgrass/data/sil_human_acc.csv',
                              header=None) / 100.
        df = [
            ('color', .903, .169),
            ('gray', .892, .172),
            #   ('line drawing', .882, .171),
            ('silhouette', sil.mean().values[0], sil.std(ddof=1).values[0])
        ]
        df = pandas.DataFrame(df, columns=['dataset', 'accuracy', 'stdev'])
        n = 260
        ci = df.stdev * 1.96 / np.sqrt(n)
        df['ci_low'] = df.accuracy - ci
        df['ci_high'] = df.accuracy + ci

        sns.factorplot('dataset',
                       'accuracy',
                       data=df,
                       kind='bar',
                       color=self.colors['shape'])
        hue = 'kind' if 'kind' in df else None
        plot.plot_ci(df, what=['Rectangle'], hue=hue)
        self.show(pref='acc')
        self.html.writetable(df)
Exemplo n.º 2
0
    def pred_corr(self):
        pref = 'pred_corr'
        print()
        print('{:=^50}'.format(' ' + pref + ' '))
        value = 'model_accuracy'
        method = 'euclidean'
        df = self.get_data_all(pref, kind='compare', value=value, method=method)

        behav = self.myexp.behav()
        behav = behav.pivot_table(index=['kind', 'subjid'],
                                  columns='no', values='acc')

        df = base._set_ci(df, groupby=['models', 'dataset'])
        g = sns.factorplot(x='dataset', y='consistency', hue='models',
                            data=df, kind='bar',
                            color=self.myexp.colors['shape'])
        hue = 'kind' if 'kind' in df else None
        plot.plot_ci(df, hue=hue)
        sns.plt.ylim([0,1])
        for sno, subset in enumerate(ORDER):
            self.myexp.set_subset(subset)
            rel = self.reliability(behav.loc[subset])
            # import pdb; pdb.set_trace()
            rel = ((1+rel[0])/2., (1+rel[1])/2.)
            sns.plt.axhspan(rel[0], rel[1], xmin=(2*sno+1)/6.-1/7., xmax=(2*sno+1)/6.+1/7., facecolor='0.9', edgecolor='0.9', zorder=0)
        self.show(pref=pref, suffix='all_' + value + '_' + method)
Exemplo n.º 3
0
    def plot_all(self,
                 df,
                 values,
                 dim,
                 pref='',
                 ceiling=None,
                 color=None,
                 ylim=[-.1, 1.1]):

        df = _set_ci(df)
        print(df)

        gray = sns.color_palette('Set2', 8)[-1]
        light = (.3, .3, .3)  #colors[-2]
        # if color is None:
        #     color = self.colors[0]
        # light = sns.light_palette(color, n_colors=3)[1]
        palette = []
        for model in df.models.unique():
            depth = df[df.models == model].depth.iloc[0]
            if depth == 'shallow':
                palette.append(gray)
            elif depth == 'hmax':
                palette.append(light)
            elif depth == 'deep':
                palette.append(color)
        # dims = df.kind.unique()
        # col = None if len(dims) == 1 else 'kind'
        g = sns.factorplot(x='models',
                           y=values,
                           data=df,
                           kind='bar',
                           palette=palette)

        sns.plt.ylim(ylim)
        if 'ci_low' in df.columns:
            hue = 'kind' if 'kind' in df else None
            plot.plot_ci(df, hue=hue)
        if 'accuracy' in df.columns and self.myexp.dims[dim] is not None:
            plot_chance(self.myexp.dims[dim])
        # for ax, dim in zip(g.axes.flat, dims):
        sns.plt.title(dim)
        if ceiling is not None:
            sns.plt.axhspan(ceiling[0],
                            ceiling[1],
                            facecolor='0.9',
                            edgecolor='0.9',
                            zorder=0)

        self.set_vertical_labels(g)
        #pref = kind if pref == '' else pref + '_' + kind
        self.show(pref=pref, suffix='all_' + dim)
Exemplo n.º 4
0
    def behav_olddata(self):
        self.model_name = 'behav'
        sil = pandas.read_csv('snodgrass/data/sil_human_acc.csv', header=None) / 100.
        df = [('color', .903, .169),
              ('gray', .892, .172),
            #   ('line drawing', .882, .171),
              ('silhouette', sil.mean().values[0], sil.std(ddof=1).values[0])]
        df = pandas.DataFrame(df, columns=['dataset', 'accuracy', 'stdev'])
        n = 260
        ci = df.stdev * 1.96 / np.sqrt(n)
        df['ci_low'] = df.accuracy - ci
        df['ci_high'] = df.accuracy + ci

        sns.factorplot('dataset', 'accuracy', data=df,
                        kind='bar', color=self.colors['shape'])
        hue = 'kind' if 'kind' in df else None
        plot.plot_ci(df, what=['Rectangle'], hue=hue)
        self.show(pref='acc')
        self.html.writetable(df)
Exemplo n.º 5
0
    def func_wrapper(self, df, values, ylim=[0, 1]):
        g = plot_func(self, df, values, ylim=ylim)

        if 'ci_low' in df.columns:
            hue = 'kind' if 'kind' in df else None
            plot.plot_ci(df, hue=hue)

        if 'accuracy' in df.columns:
            for value in self.dims.values():
                plot_chance(value)

        if self.model_name in ['googlenet', 'vgg-19']:
            labels = g.axes.flat[0].get_xticklabels()
            for label in labels:
                if len(label.get_text()) > 3:
                    label.set_ha('right')
                    label.set_rotation(30)
            # if self.model_name == 'googlenet':
            #     sns.plt.subplots_adjust(bottom=.25)
        self.show(values)
Exemplo n.º 6
0
    def func_wrapper(self, df, values, ylim=[0, 1]):
        g = plot_func(self, df, values, ylim=ylim)

        if "ci_low" in df.columns:
            hue = "kind" if "kind" in df else None
            plot.plot_ci(df, hue=hue)

        if "accuracy" in df.columns:
            for value in self.dims.values():
                plot_chance(value)

        if self.model_name in ["googlenet", "vgg-19"]:
            labels = g.axes.flat[0].get_xticklabels()
            for label in labels:
                if len(label.get_text()) > 3:
                    label.set_ha("right")
                    label.set_rotation(30)
            # if self.model_name == 'googlenet':
            #     sns.plt.subplots_adjust(bottom=.25)
        self.show(values)
Exemplo n.º 7
0
    def pred_corr(self):
        pref = 'pred_corr'
        print()
        print('{:=^50}'.format(' ' + pref + ' '))
        value = 'model_accuracy'
        method = 'euclidean'
        df = self.get_data_all(pref,
                               kind='compare',
                               value=value,
                               method=method)

        behav = self.myexp.behav()
        behav = behav.pivot_table(index=['kind', 'subjid'],
                                  columns='no',
                                  values='acc')

        df = base._set_ci(df, groupby=['models', 'dataset'])
        g = sns.factorplot(x='dataset',
                           y='consistency',
                           hue='models',
                           data=df,
                           kind='bar',
                           color=self.myexp.colors['shape'])
        hue = 'kind' if 'kind' in df else None
        plot.plot_ci(df, hue=hue)
        sns.plt.ylim([0, 1])
        for sno, subset in enumerate(ORDER):
            self.myexp.set_subset(subset)
            rel = self.reliability(behav.loc[subset])
            # import pdb; pdb.set_trace()
            rel = ((1 + rel[0]) / 2., (1 + rel[1]) / 2.)
            sns.plt.axhspan(rel[0],
                            rel[1],
                            xmin=(2 * sno + 1) / 6. - 1 / 7.,
                            xmax=(2 * sno + 1) / 6. + 1 / 7.,
                            facecolor='0.9',
                            edgecolor='0.9',
                            zorder=0)
        self.show(pref=pref, suffix='all_' + value + '_' + method)
Exemplo n.º 8
0
    def plot_all(self, df, values, dim, pref="", ceiling=None, color=None, ylim=[-0.1, 1.1]):

        df = _set_ci(df)
        print(df)

        gray = sns.color_palette("Set2", 8)[-1]
        light = (0.3, 0.3, 0.3)  # colors[-2]
        # if color is None:
        #     color = self.colors[0]
        # light = sns.light_palette(color, n_colors=3)[1]
        palette = []
        for model in df.models.unique():
            depth = df[df.models == model].depth.iloc[0]
            if depth == "shallow":
                palette.append(gray)
            elif depth == "hmax":
                palette.append(light)
            elif depth == "deep":
                palette.append(color)
        # dims = df.kind.unique()
        # col = None if len(dims) == 1 else 'kind'
        g = sns.factorplot(x="models", y=values, data=df, kind="bar", palette=palette)

        sns.plt.ylim(ylim)
        if "ci_low" in df.columns:
            hue = "kind" if "kind" in df else None
            plot.plot_ci(df, hue=hue)
        if "accuracy" in df.columns and self.myexp.dims[dim] is not None:
            plot_chance(self.myexp.dims[dim])
        # for ax, dim in zip(g.axes.flat, dims):
        sns.plt.title(dim)
        if ceiling is not None:
            sns.plt.axhspan(ceiling[0], ceiling[1], facecolor="0.9", edgecolor="0.9", zorder=0)

        self.set_vertical_labels(g)
        # pref = kind if pref == '' else pref + '_' + kind
        self.show(pref=pref, suffix="all_" + dim)