def compute_hurst_and_stat(metric='dfa', regu='off', OUTPUT_PATH = '/volatile/hubert/beamer/test_hurst/', plot=False): conn = Hurst_Estimator(metric=metric, mask=dataset.mask,smoothing_fwhm=0, regu=regu, n_jobs=5) os.write(1,'fit\n') fc = conn.fit(dataset.func1) #conn.load_map(INPUT_PATH) os.write(1,'save\n') #stat_function_tst(conn, metric+' '+regu+' ', OUTPUT_PATH) conn.save(save_path=OUTPUT_PATH) if plot: os.write(1,'plot\n') 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) 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 regu=='off': OUTPUT_PATH = os.path.join(OUTPUT_PATH, metric) else: OUTPUT_PATH = os.path.join(OUTPUT_PATH, metric, regu) for i in range(3): title = '_'.join(groups[i]) output_file = os.path.join(OUTPUT_PATH, title) img = conn.masker.inverse_transform(tst[i]) plot_stat_map(img, cut_coords=(3, -63, 36), title=title, output_file=output_file + '.pdf') img = conn.masker.inverse_transform(cot[i]) plot_stat_map(img, title='coef_map ' + title, output_file=output_file + 'coef_map.pdf') title = gr[i] output_file = os.path.join(OUTPUT_PATH, title) 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') 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') 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') plt.figure() plt.boxplot(map(lambda x: x['accuracy'], a)) plt.savefig(os.path.join(OUTPUT_PATH, 'boxplot.pdf'))
def stat_computed_hurst(metric= ['wavelet', 'dfa', 'welch'], regu = ['off', 'tv', 'l2'], INPUT_PATH = '/volatile/hubert/beamer/test_hurst/', OUTPUT_PATH=None): for met in metric: for reg in regu: conn = Hurst_Estimator(metric=met, mask=dataset.mask, regu=reg, n_jobs=5) os.write(1,'load\n') conn.load_map(INPUT_PATH) fc = conn.hurst os.write(1,'stat\n') stat_function_tst(conn, met+' '+reg+' ', OUTPUT_PATH) stat_ttest_function(conn, met+' '+reg+' ', OUTPUT_PATH) plt.show()
def stat(metric='wavelet', regu='off', lbda = 1, OUTPUT_PATH = '/volatile/hubert/beamer/HEES0/'): conn = Hurst_Estimator(metric=metric, lbda = lbda, mask=dataset.mask,smoothing_fwhm=0, regu=regu, n_jobs=5) os.write(1,'load\n') conn.load_map(INPUT_PATH = OUTPUT_PATH, save_file= 'hurstmap_metric_wavelet_regu_tv' +str(lbda)) os.write(1,'stat\n') if regu=='off': OUTPUT_PATH = os.path.join(OUTPUT_PATH, metric) else: OUTPUT_PATH = os.path.join(OUTPUT_PATH, metric, regu) stat_function(conn, prefix = 'lbda' + str(lbda), OUTPUT_PATH=OUTPUT_PATH) return conn
def diff_computed_hurst(metric='wavelet', regu='off', INPUT_PATH = '/volatile/hubert/beamer/test_hurst/', OUTPUT_PATH=''): conn = Hurst_Estimator(metric=metric, mask=dataset.mask, regu=regu, n_jobs=5) os.write(1,'load\n') conn.load_map(INPUT_PATH) fc = conn.hurst os.write(1,'stat\n') tst = ttest_group(['av', 'v'], .05, fc) vmean_avmean = np.mean([fc[i] for i in dataset.group_indices['v']], axis=0) - np.mean([fc[i] for i in dataset.group_indices['av']], axis=0) vmean_avmean[tst == 0] = 0 img = conn.masker.inverse_transform(vmean_avmean) plot_stat_map(img) plt.show()
def compute_hurst_and_stat(metric='wavelet', regu='off', lbda = 1, OUTPUT_PATH = '/volatile/hubert/beamer/HEES0/', plot=False): conn = Hurst_Estimator(metric=metric, lbda = lbda, mask=dataset.mask,smoothing_fwhm=0, regu=regu, n_jobs=5) os.write(1,'fit\n') fc = conn.fit(dataset.func1) #conn.load_map(INPUT_PATH = OUTPUT_PATH, save_file= 'hurstmap_metric_wavelet_regu_l2' +str(lbda)) fc = conn.hurst os.write(1,'save\n') #stat_function_tst(conn, metric+' '+regu+' ', OUTPUT_PATH) conn.save(save_path=OUTPUT_PATH) if plot: os.write(1,'plot\n') if regu=='off': OUTPUT_PATH = os.path.join(OUTPUT_PATH, metric) else: OUTPUT_PATH = os.path.join(OUTPUT_PATH, metric, regu) stat_function(conn, prefix = 'lbda' + str(lbda), OUTPUT_PATH=OUTPUT_PATH) return conn
def stat_computed_hurst(metric=['wavelet', 'dfa', 'welch'], regu=['off', 'tv', 'l2'], INPUT_PATH='/volatile/hubert/beamer/test_hurst/', OUTPUT_PATH=None): for met in metric: for reg in regu: conn = Hurst_Estimator(metric=met, mask=dataset.mask, regu=reg, n_jobs=5) os.write(1, 'load\n') conn.load_map(INPUT_PATH) fc = conn.hurst os.write(1, 'stat\n') stat_function_tst(conn, met + ' ' + reg + ' ', OUTPUT_PATH) stat_ttest_function(conn, met + ' ' + reg + ' ', OUTPUT_PATH) plt.show()
def diff_computed_hurst(metric='wavelet', regu='off', INPUT_PATH='/volatile/hubert/beamer/test_hurst/', OUTPUT_PATH=''): conn = Hurst_Estimator(metric=metric, mask=dataset.mask, regu=regu, n_jobs=5) os.write(1, 'load\n') conn.load_map(INPUT_PATH) fc = conn.hurst os.write(1, 'stat\n') tst = ttest_group(['av', 'v'], .05, fc) vmean_avmean = np.mean( [fc[i] for i in dataset.group_indices['v']], axis=0) - np.mean( [fc[i] for i in dataset.group_indices['av']], axis=0) vmean_avmean[tst == 0] = 0 img = conn.masker.inverse_transform(vmean_avmean) plot_stat_map(img) plt.show()
def comparison(lbdatv = [0.5,1,2,3,4,5,10,15], lbdal2=[5,10,15,20,25,40], OUTPUT_PATH='/volatile/hubert/beamer/HEES0/'): conn = Hurst_Estimator(mask=dataset.mask) for lbda in lbdatv: os.write(1,'tv' +str(lbda)+'\n') conn.load_map(INPUT_PATH = OUTPUT_PATH, save_file= 'hurstmap_metric_wavelet_regu_tv' +str(lbda)) stat_function(conn, prefix = 'lbda' + str(lbda), OUTPUT_PATH=os.path.join(OUTPUT_PATH, 'wavelet', 'tv')) #fc = conn.hurst[0] #fc[fc==0.4] = 0 #img = conn.masker.inverse_transform(fc) #lbda = '_'.join(str(lbda).split('.')) #plot_stat_map(img, output_file=os.path.join(OUTPUT_PATH, 'wavelet', 'tv'+lbda)) for lbda in lbdal2: os.write(1,'l2' +str(lbda)+'\n') conn.load_map(INPUT_PATH = OUTPUT_PATH, save_file= 'hurstmap_metric_wavelet_regu_l2' +str(lbda)) stat_function(conn, prefix = 'lbda' + str(lbda), OUTPUT_PATH=os.path.join(OUTPUT_PATH, 'wavelet', 'l2')) #fc = conn.hurst[0] #fc[fc==0.4] = 0 #img = conn.masker.inverse_transform(fc) #plot_stat_map(img, output_file=os.path.join(OUTPUT_PATH, 'wavelet', 'l2'+str(lbda))) conn.load_map(INPUT_PATH = OUTPUT_PATH, save_file= 'hurstmap_metric_wavelet_regu_off') stat_function(conn, prefix = 'regu_off', OUTPUT_PATH=os.path.join(OUTPUT_PATH, 'wavelet')) #fc = conn.hurst[0] #fc[fc==0.4] = 0 #img = conn.masker.inverse_transform(fc) #plot_stat_map(img, output_file=os.path.join(OUTPUT_PATH, 'wavelet', 'regu_off')) conn.load_map(INPUT_PATH = OUTPUT_PATH, save_file= 'hurstmap_metric_wavelet_regu_off_presmooth6') stat_function(conn, prefix = 'presmooth', OUTPUT_PATH=os.path.join(OUTPUT_PATH, 'wavelet')) #fc = conn.hurst[0] #img = conn.masker.inverse_transform(fc) #plot_stat_map(img, output_file=os.path.join(OUTPUT_PATH, 'wavelet', 'presmooth')) plt.show()
def wavelet4_estimation( INPUT_PATH='/volatile/hubert/beamer/test_hurst/wavelet4'): conn = Hurst_Estimator(metric='wavelet', mask=dataset.mask, regu='tv', nb_vanishmoment=4, j1=3, j2=7, n_jobs=5) conn.fit(dataset.func1) conn.save(INPUT_PATH)
def compute_hurst_and_stat(metric='dfa', regu='off', OUTPUT_PATH='/volatile/hubert/beamer/test_hurst/', plot=False): conn = Hurst_Estimator(metric=metric, mask=dataset.mask, smoothing_fwhm=0, regu=regu, n_jobs=5) os.write(1, 'fit\n') fc = conn.fit(dataset.func1) #conn.load_map(INPUT_PATH) os.write(1, 'save\n') #stat_function_tst(conn, metric+' '+regu+' ', OUTPUT_PATH) conn.save(save_path=OUTPUT_PATH) if plot: os.write(1, 'plot\n') 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) 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 regu == 'off': OUTPUT_PATH = os.path.join(OUTPUT_PATH, metric) else: OUTPUT_PATH = os.path.join(OUTPUT_PATH, metric, regu) for i in range(3): title = '_'.join(groups[i]) output_file = os.path.join(OUTPUT_PATH, title) img = conn.masker.inverse_transform(tst[i]) plot_stat_map(img, cut_coords=(3, -63, 36), title=title, output_file=output_file + '.pdf') img = conn.masker.inverse_transform(cot[i]) plot_stat_map(img, title='coef_map ' + title, output_file=output_file + 'coef_map.pdf') title = gr[i] output_file = os.path.join(OUTPUT_PATH, title) 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') 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') 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') plt.figure() plt.boxplot(map(lambda x: x['accuracy'], a)) plt.savefig(os.path.join(OUTPUT_PATH, 'boxplot.pdf'))
def wavelet4_estimation(INPUT_PATH = '/volatile/hubert/beamer/test_hurst/wavelet4'): conn = Hurst_Estimator(metric='wavelet', mask=dataset.mask, regu='tv', nb_vanishmoment=4, j1 =3, j2=7, n_jobs=5) conn.fit(dataset.func1) conn.save(INPUT_PATH)