Example #1
0
    #---------------------------------------------------------------------------

    return trial

# Performance measure: two-alternative forced choice
performance = tasktools.performance_2afc

# Terminate training when psychometric performance exceeds 85%
def terminate(performance_history):
    return np.mean(performance_history[-5:]) > 85

# Validation dataset size
n_validation = 100*(nconditions + 1)

#///////////////////////////////////////////////////////////////////////////////

if __name__ == '__main__':
    # Train model
    model = Model(Nin=Nin, N=N, Nout=Nout, ei=ei, Cout=Cout,
                  generate_trial=generate_trial,
                  performance=performance, terminate=terminate,
                  n_validation=n_validation)
    model.train('savefile.pkl')

    # Run the trained network with 16*3.2% = 51.2% coherence for choice 1
    rnn        = RNN('savefile.pkl', {'dt': 0.5})
    trial_func = generate_trial
    trial_args = {'name': 'test', 'catch': False, 'coh': 16, 'left_right': 1}
    info       = rnn.run(inputs=(trial_func, trial_args))
Example #2
0
File: do.py Project: grahamas/pycog
    cmd     = 'python {} {} {}{}'.format(join(here, 'do.py'), modelfile, action, sargs)
    pbspath = join(workpath, 'pbs')
    jobfile = pbstools.write_jobfile(cmd, jobname, pbspath, scratchpath,
                                     ppn=ppn, gpus=gpus, queue='s48')
    subprocess.call(['qsub', jobfile])

#=========================================================================================
# Train
#=========================================================================================

elif action == 'train':
    from pycog import Model

    # Model specification
    model = Model(modelfile=modelfile)

    # Avoid locks on the cluster
    compiledir = join(theanopath, '{}-{}'.format(name, int(time.time())))

    # Train
    model.train(savefile, seed=seed, compiledir=compiledir, gpus=gpus)

#=========================================================================================
# Test resting state
#=========================================================================================

elif action == 'restingstate':
    import numpy as np

    from pycog          import RNN
Example #3
0

min_error = 0.07

mode = 'continuous'
n_validation = 50

if __name__ == '__main__':
    from pycog import Model

    model = Model(N=N,
                  Nout=Nout,
                  ei=ei,
                  tau=tau,
                  dt=dt,
                  train_brec=train_brec,
                  train_bout=train_bout,
                  var_rec=var_rec,
                  generate_trial=generate_trial,
                  mode=mode,
                  n_validation=n_validation,
                  min_error=min_error)
    model.train('savefile.pkl', seed=100, recover=False)

    #-------------------------------------------------------------------------------------
    # Plot
    #-------------------------------------------------------------------------------------

    from pycog import RNN
    from pycog.figtools import Figure

    rnn = RNN('savefile.pkl', {'dt': 0.5, 'var_rec': 0.01**2})
#min_error = 0.15

# Termination criterion
TARGET_PERFORMANCE = 90
def terminate(performance_history):
    return np.mean(performance_history[-3:]) >= TARGET_PERFORMANCE

# Validation dataset
n_validation = 100*(nconditions + 1)

if __name__ == '__main__':
    from pycog import Model
    
    model = Model(N=N, Nin=Nin, Nout=Nout, ei=ei, Crec=Crec, Cout=Cout,
                  generate_trial=generate_trial, 
                  n_validation=n_validation, performance=performance, terminate=terminate)
    model.train('workingMemory_savefile.pkl', seed=100, recover=False)

   #-------------------------------------------------------------------------------------
   # Plot
   #-------------------------------------------------------------------------------------

    from pycog          import RNN
    from pycog.figtools import Figure

    rng = np.random.RandomState(1066)
    rnn  = RNN('workingMemory_savefile.pkl', {'dt': 2})

    trial_args = {'name':  'test', 'catch': False, 'pair': (15, 30)}
# Performance measure
performance = tasktools.performance_2afc_min_condition

# Termination criterion
TARGET_PERFORMANCE = 85
def terminate(performance_history):
    return np.mean(performance_history[-1:]) >= TARGET_PERFORMANCE

# Validation dataset
n_validation = 100*(nconditions + 1)

if __name__ == '__main__':
    from pycog import Model
    
    model = Model(N=N, Nin=Nin, Nout=Nout, ei=ei, Crec=Crec, Cout=Cout,
                  generate_trial=generate_trial, 
                  n_validation=n_validation, performance=performance, terminate=terminate)
    model.train('romoOne_savefile.pkl', seed=100, recover=False)

   #-------------------------------------------------------------------------------------
   # Plot
   #-------------------------------------------------------------------------------------

    from pycog          import RNN
    from pycog.figtools import Figure

    rng = np.random.RandomState(1066)
    rnn  = RNN('romoOne_savefile.pkl', {'dt': 2})

    trial_args = {'name':  'test', 'catch': False, 'fpair': (34, 26), 'gt_lt': '>'}
Example #6
0
                                     pbspath,
                                     scratchpath,
                                     ppn=ppn,
                                     gpus=gpus,
                                     queue='s48')
    subprocess.call(['qsub', jobfile])

#=========================================================================================
# Train
#=========================================================================================

elif action == 'train':
    from pycog import Model

    # Model specification
    model = Model(modelfile=modelfile)

    # Avoid locks on the cluster
    compiledir = join(theanopath, '{}-{}'.format(name, int(time.time())))

    # Train
    model.train(savefile, seed=seed, compiledir=compiledir, gpus=gpus)

#=========================================================================================
# Test resting state
#=========================================================================================

elif action == 'restingstate':
    import numpy as np

    from pycog import RNN
    #---------------------------------------------------------------------------

    return trial

# Performance measure: two-alternative forced choice
performance = tasktools.performance_2afc

# Terminate training when psychometric performance exceeds 85%
def terminate(performance_history):
    return np.mean(performance_history[-5:]) > 85

# Validation dataset size
n_validation = 100*(nconditions + 1)

#///////////////////////////////////////////////////////////////////////////////

if __name__ == '__main__':
    # Train model
    model = Model(Nin=Nin, N=N, Nout=Nout, ei=ei, Cout=Cout,
                  generate_trial=generate_trial,
                  performance=performance, terminate=terminate,
                  n_validation=n_validation)
    model.train('savefile.pkl')

    # Run the trained network with 16*3.2% = 51.2% coherence for choice 1
    rnn        = RNN('savefile.pkl', {'dt': 0.5})
    trial_func = generate_trial
    trial_args = {'name': 'test', 'catch': False, 'coh': 16, 'left_right': 1}
    info       = rnn.run(inputs=(trial_func, trial_args))
    cmd     = 'python {} {} {}{}'.format(join(here, 'do.py'), modelfile, action, sargs)
    pbspath = join(workpath, 'pbs')
    jobfile = pbstools.write_jobfile(cmd, jobname, pbspath, scratchpath,
                                     ppn=ppn, gpus=gpus, queue='s48')
    subprocess.call(['qsub', jobfile])

#=========================================================================================
# Train
#=========================================================================================

elif action == 'train':
    from pycog import Model

    # Model specification
    model = Model(modelfile=modelfile) #the input is literally the .py model
    
    #Check the Model class for more information
    
    # Avoid locks on the cluster
    compiledir = join(theanopath, '{}-{}'.format(name, int(time.time())))

    # Train
    model.train(savefile, seed=seed, compiledir=compiledir, gpus=gpus) 

#=========================================================================================
# Test resting state
#=========================================================================================

elif action == 'restingstate':
    import numpy as np