Exemplo n.º 1
0
def run_svc(X, y, k, n_perm, model, fileName):
    y_rand = np.random.permutation(y)
    predict, dec, y_sorted, weight = model.main_svc_rfe_cv(X, y_rand, k)
    #    # write h5py
    #    write_h5py(fileName,'perm'+str(n_perm),['predict','dec','y_sorted','weight'],\
    #          [predict,dec,y_sorted,weight])
    #     write mat
    write_mat(os.path.join(fileName,str(n_perm)),\
              dataset_name=['predict','dec','y_sorted','weight'],\
             dataset=[predict,dec,y_sorted,weight])
Exemplo n.º 2
0
    def run_svc(self, X, y, n_perm):
        #        print('we have processing {} permutation'.format(n_perm))
        y_rand = np.random.permutation(y)
        predict,dec,y_sorted,weight=\
        self.model.main_svc_rfe_cv(X,y_rand,self.k)

        #     write mat
        write_mat(os.path.join(self.fileName,str(n_perm)),\
                  dataset_name=['predict','dec','y_sorted','weight'],\
                 dataset=[predict,dec,y_sorted,weight])
Exemplo n.º 3
0
    def load_allmat(sel):
        # 多线程
        s = time.time()
        print('loading all mat...\n')

        # 判断是否有FC mat文件
        if os.path.exists(os.path.join(sel.save_path, sel.feature + '.mat')):
            sel.mat = pd.DataFrame(
                read_mat(os.path.join(sel.save_path, sel.feature + '.mat'),
                         None))
            print(
                'Already have {}\nloaded all mat!\nrunning time={:.2f}'.format(
                    sel.feature + '.mat',
                    time.time() - s))
        else:

            sel.all_mat = os.listdir(sel.file_path)
            all_mat_path = [
                os.path.join(sel.file_path, all_mat_)
                for all_mat_ in sel.all_mat
            ]

            cores = multiprocessing.cpu_count()
            if sel.n_processess > cores:
                sel.n_processess = cores - 1

            len_all = len(all_mat_path)
            sel.mat = pd.DataFrame([])

            # 特征用std还是mean
            if sel.feature == 'mean':
                ith = 1
            elif sel.feature == 'std':
                ith = 0
            elif sel.feature == 'staticFC':
                ith = 0
            else:
                print('###还未添加其他衡量dFC的指标,默认使用std###\n')
                ith = 0

            # load mat...
            with ThreadPoolExecutor(sel.n_processess) as executor:
                for i, all_mat_ in enumerate(all_mat_path):
                    task = executor.submit(sel.load_onemat_and_processing, i,
                                           all_mat_, len_all, s)
                    sel.mat = pd.concat(
                        [sel.mat, pd.DataFrame(task.result()[ith]).T], axis=0)

            # 保存后处理后的mat文件
            if sel.if_save_post_mat:
                write_mat(fileName=os.path.join(sel.save_path,
                                                sel.feature + '.mat'),
                          dataset_name=sel.feature,
                          dataset=np.mat(sel.mat.values))
                print('saved all {} mat!\n'.format(sel.feature))
Exemplo n.º 4
0
	Transform the .1D file to .mat file
	TODO: to other file type
	
	Args:
		file_path: .1D file path
	Return:
		data: .mat file 
	"""
    data = pd.read_csv(file_path)
    data = data.values
    data = [list(d)[0].split('\t') for d in data]
    data =[np.array(d, dtype=np.float).T for d in data]
    data = pd.DataFrame(data)
    data = pd.DataFrame(data)
    return data
    

if __name__ == '__main__':
    dir = r'F:\Data\ASD\Outputs\dparsf\filt_global\rois_dosenbach160'
    save_path = r'F:\Data\ASD\Outputs\dparsf\filt_global\rois_dosenbach160_m'
    file_name = os.listdir(dir)
    file_path = [os.path.join(dir, fn) for fn in file_name]
    nfile = len(file_path)
    for i, file in enumerate(zip(file_path, file_name)):
        print(f'{i+1}/{nfile}')
        data = read_1D(file[0])
        fn = os.path.join(save_path, file[1].split('.')[0] + '.mat')
        write_mat(fileName=fn, dataset_name='timeseries', dataset=data.values)