コード例 #1
0
ファイル: run.py プロジェクト: mageed/conv-exp
    def corr_models(self):
        df = self._acc()
        df = df[df.sel]
        corr = lambda x,y: 1 - scipy.spatial.distance.sqeuclidean(x,y) / len(x)

        cr = []
        for m1 in df.model.unique():
            d1 = df[df.model==m1]
            for s1 in df.dataset.unique():
                for m2 in df.model.unique():
                    d2 = df[df.model==m2]
                    for s2 in df.dataset.unique():
                        if m1==m2 and s1==s2:
                            r = np.nan
                        else:
                            r = corr(d1[d1.dataset==s1].model_accuracy.values,
                                     d2[d2.dataset==s2].model_accuracy.values)
                        cr.append([m1,s1,m2,s2,r])
        cr = pandas.DataFrame(cr, columns=['model1', 'dataset1',
                              'model2', 'dataset2', 'lr'])
        cr = stats.factorize(cr)
        crs = cr.set_index(['model1', 'dataset1', 'model2', 'dataset2'])
        crs = crs.unstack(['model2', 'dataset2'])
        sns.plt.figure()
        sns.heatmap(crs)
        print(crs)
        print(cr.groupby(['dataset1', 'dataset2']).mean())
        self.show(pref='mcorr')

        if self.myexp.html is not None:
            self.myexp.html.writetable(crs, caption='proportion of matching responses')
            g = cr.groupby(['dataset1', 'dataset2']).mean()
            self.myexp.html.writetable(g, caption='mean proportion of matching responses')
コード例 #2
0
def corr_models(mods1_dis, mods2_dis):
    df = []
    for mods1_label, mods1_data in mods1_dis.items():
        inds = np.triu_indices(mods1_data.shape[0], k=1)
        for mods2_label, mods2_data in mods2_dis.items():
            corr = np.corrcoef(mods1_data[inds], mods2_data[inds])[0,1]
            df.append([mods1_label, mods2_label, corr])
    df = pandas.DataFrame(df, columns=['perception', 'models', 'correlation'])
    df = stats.factorize(df)
    sns.factorplot('perception', 'correlation', 'models',
                   data=df, kind='bar')
    return df
コード例 #3
0
def corr_neural_model(neural_dis, mod_dis):
    df = []

    for mod_label, mod_data in mod_dis.items():
        for k in xrange(neural_dis.values()[0].shape[-1]):
            nd_avg = []
            for neural_label, neural_data in neural_dis.items():
                inds = np.triu_indices(mod_data.shape[0], k=1)
                corr = np.corrcoef(neural_data[:,:,k][inds],
                                   mod_data[inds])[0,1]

                df.append([neural_label, mod_label, k, corr])
    df = pandas.DataFrame(df, columns=['neural', 'model',
                                       'subjid', 'correlation'])
    df = stats.factorize(df)
    sns.factorplot('neural', 'correlation', 'model', data=df, kind='bar')
    return df
コード例 #4
0
    def avg_hop2008(self, dis, plot=True):
        # dis = self.dissimilarity()

        df = []
        for layer, dis in dis.items():

            df.extend(self._avg(dis, layer, 'px'))
            df.extend(self._avg(dis, layer, 'shape'))

            other = dis.copy()
            for sh in np.unique(self.dims['px']):
                ss = self.dims['px'] == sh
                other.T[ss].T[ss] = np.nan

            for sh in np.unique(self.dims['shape']):
                ss = self.dims['shape'] == sh
                other.T[ss].T[ss] = np.nan

            inds = range(len(other))
            n = 0
            for si, s1 in enumerate(inds):
                for s2 in inds[si + 1:]:
                    if not np.isnan(other[s1, s2]):
                        df.append([layer, 'other', n, s1, s2, other[s1, s2]])
                        n += 1

        df = pandas.DataFrame(
            df, columns=['layer', 'kind', 'n', 'i', 'j', 'dissimilarity'])
        if plot:
            df = stats.factorize(df, order={'kind': ['px', 'shape', 'other']})
            # df = df[df.feature != 'other']
            # agg = stats.aggregate(df, values='dissimilarity', rows='layer',
            #                  cols='feature', yerr='n')
            agg = df.pivot_table(index='n',
                                 columns=['layer', 'kind'],
                                 values='dissimilarity')
            sns.factorplot('layer',
                           'dissimilarity',
                           'kind',
                           data=df,
                           kind='bar')
            self.show(pref='avg')
        return df
コード例 #5
0
ファイル: run.py プロジェクト: mageed/conv-exp
    def avg_hop2008(self, dis, plot=True):
        # dis = self.dissimilarity()

        df = []
        for layer, dis in dis.items():

            df.extend(self._avg(dis, layer, 'px'))
            df.extend(self._avg(dis, layer, 'shape'))

            other = dis.copy()
            for sh in np.unique(self.dims['px']):
                ss = self.dims['px'] == sh
                other.T[ss].T[ss] = np.nan

            for sh in np.unique(self.dims['shape']):
                ss = self.dims['shape'] == sh
                other.T[ss].T[ss] = np.nan

            inds = range(len(other))
            n = 0
            for si, s1 in enumerate(inds):
                for s2 in inds[si+1:]:
                    if not np.isnan(other[s1,s2]):
                        df.append([layer, 'other', n, s1, s2, other[s1,s2]])
                        n += 1

        df = pandas.DataFrame(df, columns=['layer', 'kind', 'n', 'i', 'j', 'dissimilarity'])
        if plot:
            df = stats.factorize(df, order={'kind': ['px', 'shape', 'other']})
            # df = df[df.feature != 'other']
            # agg = stats.aggregate(df, values='dissimilarity', rows='layer',
            #                  cols='feature', yerr='n')
            agg = df.pivot_table(index='n', columns=['layer', 'kind'],
                           values='dissimilarity')
            sns.factorplot('layer', 'dissimilarity', 'kind', data=df,
                            kind='bar')
            self.show(pref='avg')
        return df
コード例 #6
0
def corr_neural_model_avg(neural_dis, mod_dis):
    df = []
    avg = [['pixelwise',
            ('BA17', 'BA18', 'TOS', 'postPPA',
            'LOTCobject', 'LOTCface')],

            ['shape',
            ('LOTCbody', 'LOTChand',
            'VOTCobject', 'VOTCbody/face')],

            ['animate/inanimate',
            ('LOTCobject', 'LOTCface', 'LOTCbody', 'LOTChand',
            'VOTCobject', 'VOTCbody/face')],

            ['nat/artifact', ('IPS', 'SPL',
             'IPL', 'DPFC')]
           ]

    for a, rois in avg:
        for mod_label, mod_data in mod_dis.items():
            for k in xrange(neural_dis.values()[0].shape[-1]):
                nd_avg = []
                for neural_label, neural_data in neural_dis.items():
                    if neural_label in rois:
                        nd_avg.append(neural_data[:,:,k])
                nd_avg = np.average(nd_avg, axis=0)

                inds = np.triu_indices(nd_avg.shape[0], k=1)
                corr = np.corrcoef(nd_avg[inds],
                                   mod_data[inds])[0,1]

                df.append([a, mod_label, k, corr])
    df = pandas.DataFrame(df, columns=['neural', 'model',
                                       'subjid', 'correlation'])
    df = stats.factorize(df)
    sns.factorplot('neural', 'correlation', 'model', data=df, kind='bar')
    return df
コード例 #7
0
    def corr_models(self):
        df = self._acc()
        df = df[df.sel]
        corr = lambda x, y: 1 - scipy.spatial.distance.sqeuclidean(x, y) / len(
            x)

        cr = []
        for m1 in df.model.unique():
            d1 = df[df.model == m1]
            for s1 in df.dataset.unique():
                for m2 in df.model.unique():
                    d2 = df[df.model == m2]
                    for s2 in df.dataset.unique():
                        if m1 == m2 and s1 == s2:
                            r = np.nan
                        else:
                            r = corr(
                                d1[d1.dataset == s1].model_accuracy.values,
                                d2[d2.dataset == s2].model_accuracy.values)
                        cr.append([m1, s1, m2, s2, r])
        cr = pandas.DataFrame(
            cr, columns=['model1', 'dataset1', 'model2', 'dataset2', 'lr'])
        cr = stats.factorize(cr)
        crs = cr.set_index(['model1', 'dataset1', 'model2', 'dataset2'])
        crs = crs.unstack(['model2', 'dataset2'])
        sns.plt.figure()
        sns.heatmap(crs)
        print(crs)
        print(cr.groupby(['dataset1', 'dataset2']).mean())
        self.show(pref='mcorr')

        if self.myexp.html is not None:
            self.myexp.html.writetable(
                crs, caption='proportion of matching responses')
            g = cr.groupby(['dataset1', 'dataset2']).mean()
            self.myexp.html.writetable(
                g, caption='mean proportion of matching responses')