示例#1
0
def stat_function_tst(conn, prefix='', OUTPUT_PATH=None, threshold=0.05):
    fc = conn.hurst

    tst = Parallel(n_jobs=3,
                   verbose=5)(delayed(ttest_group)(group, threshold, fc)
                              for group in groups)

    if OUTPUT_PATH is None:
        font = {'family': 'normal', 'size': 20}
        changefont('font', **font)
        gr = ['v', 'av', 'avn']
        for i in range(3):
            title = prefix + '_'.join(groups[i])
            try:
                img = conn.masker.inverse_transform(tst[i])
                print title
                plot_stat_map(img, cut_coords=(3, -63, 36))
                plt.show()

            except ValueError:
                print "problem with tst " + title
        changefont.func_defaults

    else:
        for i in range(3):
            title = prefix + '_'.join(groups[i])
            output_file = os.path.join(OUTPUT_PATH, title)
            try:
                img = conn.masker.inverse_transform(tst[i])
                plot_stat_map(img,
                              cut_coords=(3, -63, 36),
                              output_file=output_file + '.pdf')
            except ValueError:
                print "problem with tst " + title
示例#2
0
def stat_function_tst(conn, prefix='', OUTPUT_PATH=None, threshold=0.05):
    fc = conn.hurst

    tst = Parallel(n_jobs=3, verbose=5)(delayed(ttest_group)(group, threshold, fc)
                                    for group in groups)
    
    if OUTPUT_PATH is None:
        font = {'family' : 'normal',
            'size'   : 20}
        changefont('font', **font)
        gr = ['v', 'av', 'avn']
        for i in range(3):
            title = prefix + '_'.join(groups[i])
            try:
                img = conn.masker.inverse_transform(tst[i])
                print title
                plot_stat_map(img, cut_coords=(3, -63, 36))
                plt.show()

            except ValueError:
                print "problem with tst " + title
        changefont.func_defaults
            
    else:
        for i in range(3):
            title = prefix + '_'.join(groups[i])
            output_file = os.path.join(OUTPUT_PATH, title)
            try:
                img = conn.masker.inverse_transform(tst[i])
                plot_stat_map(img, cut_coords=(3, -63, 36), output_file=output_file + '.pdf')
            except ValueError:
                print "problem with tst " + title
示例#3
0
def plot_syj_against_j(j1=2, j2=6, wtype=1, theoretical_Hurst=0.8, idx_simulation=0, OUTPUT_FILE=None):
    idx = int(theoretical_Hurst * 10) - 1
    if(idx < 0 or idx > 10):
        idx = 7
    simulation = np.cumsum(opas.get_simulation(), axis=-1)
    
    dico = wtspecq_statlog3(simulation[idx,idx_simulation], 2, 1, np.array(2),
                            int(np.log2(simulation[idx,idx_simulation].shape[0])), 0, 0)
    Elog = dico['Elogmuqj'][0]
    Varlog = dico['Varlogmuqj'][0]
    nj = dico['nj']
    regression = regrespond_det2(Elog, Varlog, nj, j1, j2, wtype)
    font = {'family' : 'normal',
        'weight' : 'bold',
        'size'   : 22}
    changefont('font', **font)
    jmax = len(Elog)

    j_indices = np.arange(0,jmax + 2)
    fig = plt.plot(j_indices, j_indices * regression['Zeta'] + regression['aest'])
    plt.text(j_indices.mean() - 2 * j_indices.var() / jmax, Elog.mean() + Elog.var() / jmax, r'Hurst Exponent = %.2f'%(regression['Zeta']/2))

    j_indices = np.arange(0,jmax) + 1
    plt.plot(j_indices, Elog, 'ro')
    plt.xlabel('scale j')
    plt.ylabel('log Sy(j,2)')
    if not OUTPUT_FILE is None:
        plt.savefig(OUTPUT_FILE)
    plt.show()
示例#4
0
文件: test_ISBI.py 项目: qiz2/ICode
def stat_function(conn, prefix='', OUTPUT_PATH=None):
    fc = conn.hurst

    a = Parallel(n_jobs=3, verbose=5)(delayed(classify_group)(group, fc)
                                        for group in groups)
    #tst = Parallel(n_jobs=3, verbose=5)(delayed(ttest_group)(group, .05, fc)
                                    #for group in groups)

    #save_stat({'a':a, 'tst': tst}, save_file=prefix)
    ##ost = Parallel(n_jobs=3, verbose=5)(delayed(ttest_onesample)(group, 0.05, fc)
                                        ##for group in ['v', 'av', 'avn'])

    ##mht = Parallel(n_jobs=3, verbose=5)(delayed(ttest_onesample_Hmean)(group, 0.05, fc)
                                        ##for group in ['v', 'av', 'avn'])

    ##mpt = Parallel(n_jobs=3, verbose=5)(delayed(mne_permutation_ttest)(group,0.05, fc, 1)
                                        ##for group in ['v', 'av', 'avn'])
    
    
    ##cot = Parallel(n_jobs=3, verbose=5)(delayed(ttest_onesample_coef)(np.reshape(coef['coef'], (coef['coef'].shape[0], coef['coef'].shape[-1])),
                                        ##0.05, fc)
                                        ##for coef in a)
    #gr = ['v', 'av', 'avn']
    if OUTPUT_PATH is None:
        for i in range(3):
            title = prefix + '_'.join(groups[i])
            #try:
                #img = conn.masker.inverse_transform(tst[i])
                #plot_stat_map(img, cut_coords=(3, -63, 36), title=title)

            #except ValueError:
                #print "problem with tst " + title
            ##try:
                ##img = conn.masker.inverse_transform(cot[i])
                ##plot_stat_map(img, title='coef_map ' + title)

            ##except ValueError:
                ##print "problem with cot " + title

            ##title = prefix + gr[i]
            ##try:
                ##img = conn.masker.inverse_transform(ost[i])
                ##plot_stat_map(img, title='t-test H0 : H = 0.5 pvalue in -log10 scale groupe : ' + title)

            ##except ValueError:
                ##print "problem with ost " + title
            ##try:
                ##img = conn.masker.inverse_transform(mht[i])
                ##plot_stat_map(img, title='t-test H0 : H = 0.5 pvalue in -log10 scale groupe : ' + title)

            ##except ValueError:
                ##print "problem with mht " + title
            ##try:
                ##img = conn.masker.inverse_transform(mpt[i])
                ##plot_stat_map(img, title='t-test H0 : H = 0.5 pvalue in -log10 scale groupe : ' + title)

            ##except ValueError:
                ##print "problem with mpt " + title
    else:
        #for i in range(3):
            #title = prefix + '_'.join(groups[i])
            #output_file = os.path.join(OUTPUT_PATH, title)
            #try:
                #img = conn.masker.inverse_transform(tst[i])
                #plot_stat_map(img, cut_coords=(3, -63, 36), title=title, output_file=output_file + '.pdf')

            #except ValueError:
                #print "problem with tst " + title
            ##try:
                ##img = conn.masker.inverse_transform(cot[i])
                ##plot_stat_map(img, title='coef_map ' + title, output_file=output_file + 'coef_map.pdf')

            ##except ValueError:
                ##print "problem with cot " + title

            ##title = prefix + gr[i]
            ##output_file = os.path.join(OUTPUT_PATH, title)
            ##try:
                ##img = conn.masker.inverse_transform(ost[i])
                ##plot_stat_map(img, title='t-test H0 : H = 0.5 pvalue in -log10 scale groupe : ' + title, output_file= output_file + '.pdf')

            ##except ValueError:
                ##print "problem with ost " + title
            ##try:
                ##img = conn.masker.inverse_transform(mht[i])
                ##plot_stat_map(img, title='t-test H0 : H = 0.5 pvalue in -log10 scale groupe : ' + title, output_file= output_file + 'meanH.pdf')

            ##except ValueError:
                ##print "problem with mht " + title
            ##try:
                ##img = conn.masker.inverse_transform(mpt[i])
                ##plot_stat_map(img, title='t-test H0 : H = 0.5 pvalue in -log10 scale groupe : ' + title, output_file= output_file + 'mnepermutH.pdf')

            ##except ValueError:
                ##print "problem with mpt " + title
        font = {'family' : 'normal',
            'size'   : 12}
        changefont('font', **font)
        plt.figure()
        box = plt.boxplot(map(lambda x: x['accuracy'], a))
        #for i,line in enumerate(box['medians']):# get position data for median line
            #x, y = line.get_xydata()[1] # top of median line
            ## overlay median value
            #plt.text(x + 0.1, y - 0.02, '%.2f\n%.2e' % (np.mean(a[i]['accuracy']),
                                                #np.var(a[i]['accuracy'])),
            #horizontalalignment='center') # draw above, centered

        plt.ylim(0.1,1)
        plt.xticks([1,2,3], ['AV-V\n $\mu =$ %.2f\n $\sigma^2 = $%.2e' %(np.mean(a[0]['accuracy'],np.var(a[0]['accuracy'])))
                            , 'AV-AVn\n$\mu =$ %.2f\n $\sigma^2 = $%.2e' %(np.mean(a[1]['accuracy'],np.var(a[1]['accuracy'])))
                            , 'V-AVn\n$\mu =$ %.2f\n $\sigma^2 = $%.2e' %(np.mean(a[2]['accuracy'],np.var(a[2]['accuracy'])))])
        plt.savefig(os.path.join(OUTPUT_PATH, prefix+'boxplot.pdf'))
        changefont.func_defaults