コード例 #1
0
ファイル: parse_hdf.py プロジェクト: pkhanna104/fa_analysis
def test_xz_KF_CL(kf_decoder, dim_red_dict, enc_fname, wts, input_type, extra_suff='', session_length=90.,task='co', dec_method=''):

    kw_dict =dict(n_neurons=kf_decoder.n_units, encoder_name=enc_fname,
        fa_dict=dim_red_dict, input_type=input_type, assist_level=(0., 0.), decoder=kf_decoder, wts=wts)

    if task == 'co':    
        task2 = sim_fa_decoding.main_xz_CL(session_length, task_kwargs=kw_dict)
    elif task == 'obs':
        task2 = sim_fa_decoding.main_xz_CL_obstacles(session_length, task_kwargs=kw_dict)

    try:
        save_dict = dict(fit_qr=dim_red_dict['fit_qr'])
    except:
        save_dict = {}

    encoder_index = enc_fname[-5]

    pnm_test = sim_fa_decoding.save_stuff(task2, suffix=input_type+task+'_'+extra_suff+'_encoder_'+encoder_index+'_'+dec_method, 
        save_dict=save_dict)

    print 'done with ', input_type, ', saved to: ', pnm_test

    #run hdf metrics file: 
    get_sim_tuning.all_hdf_mets(pnm_test[:-4]+'.hdf', input_type)

    return pnm_test
コード例 #2
0
def all_exec(figs_only = False, filenames_only = False, vfb_files=False):
    '''
    Summary: 
    Input param: figs_only:
    Input param: filenames_only:
    Input param: vfb_files:
    Output param: 
    '''

    if vfb_files:
        input_types = ['vfb']
    else:
        input_types = input_types_master

    if filenames_only:
        file_dict = {}

    #Type of decoder fitting:

    for enc_name in master_encoder_fname:

        #type of priv noise
        for punt in p_unt:

            #type of priv to shar tuning:
            for priv_frac in frac_of_tun_priv:

                #Calculate weights for priv and shared tuning: 

                #Tuned
                tun = 1 - (s_unt + punt)

                #Private: 
                p_tun = priv_frac*tun
                s_tun = tun - p_tun

                #Weights array: priv_untuned, private_tuned, shared_untuned, shared_tuned
                w = np.array([punt, p_tun , s_unt, s_tun])
                w_adj = []
                for wi in w:
                    w_adj.append(float(str(wi)))

                #Make sure w is correct, and sum(w) = 1:
                assert int(np.sum(np.array(w)*1000)) == 1000


                #If actually running simulation, run visual feedback: 
                if (not figs_only) and (not filenames_only):
                    pnm_train = main_sim_gen.vfb(w_adj, encoder_fname=enc_name, task_name=master_task, session_length=vfb_session_length)

                for dec_fit in decoder_fit_method:

                    for j in input_types:
                        
                        print 'Input: ', j
                        
                        if figs_only or filenames_only:
                            #try:
                            hdf_fname, error = less_ridiculous_fname_fcn(w_adj, j, enc_name, dec_fit, task=master_task)
                            # except:
                            #     error = True       
                            #     print 'ERROR'
                            #     print moose   

                            if filenames_only:
                                if not error:
                                    file_dict[punt, priv_frac, j, enc_name, dec_fit] = hdf_fname
                            elif figs_only:
                                if not error:
                                    get_sim_tuning.all_hdf_mets(hdf_fname, j)

                        else:
                            os.environ['w0'] = str(w[0])
                            os.environ['w1'] = str(w[1])
                            os.environ['w2'] = str(w[2])
                            os.environ['w3'] = str(w[3])
                            os.environ['input_tp'] = j
                            os.environ['p_trn'] = pnm_train
                            os.environ['tsk'] = master_task
                            os.environ['dec_mth'] = dec_fit
                            os.environ['enc_nm'] = enc_name
                            os.environ['sesh_len'] = bmi_session_length
                            
                            #os.environ['p_trn']  = os.path.expandvars('$FA_GROM_DATA/sims/figs_v3/enc031116_2029vfb60_15_15_10_.pkl')

                            subprocess.Popen(['python main_sim_gen.py $w0 $w1 $w2 $w3 $input_tp $p_trn $tsk $dec_mth $enc_nm $sesh_len'],shell=True)
                            #Wait ten secs before spawning the next one: 
                            time.sleep(10.)
    if filenames_only:
        return file_dict