Exemplo n.º 1
0
def test_convergence(run_model, chains, saveplots=False):
    """
    Uses ipyparallel client to run <chains> model fits, then runs r-hat (gelman-rubin) statistic
    on the resulting traces. Finally, the models are concatenated and their posteriors are plotted for assessing
    convergence.
    """
    from ipyparallel import Client
    c = Client()[:] # create the ipython client
    jobs = c.map(run_model, range(chains)) # c.map(function, number of CPUs)
    models = jobs.get() # run the jobs
    
    # Calculate convergence statistics
    from kabuki.analyze import gelman_rubin
    rhat = gelman_rubin(models)
    
    # Create a new model that contains all traces concatenated from the individual models
    from kabuki.utils import concat_models
    combined_model = concat_models(models)
    
    # Plot posteriors
    combined_model.plot_posteriors(save=saveplots)
    return rhat
Exemplo n.º 2
0
# =============================================== #
# For loop to run the grid search and save output
# =============================================== #


model_name = 'stimcoding_z_SW'
    

def parloop():
    # Create a list for the model variables
    nEs = list(mydata.columns[10:14])
    modelCount = 0

    for nE in nEs:
        print('***** WORKING ON ELEC ' + nE + ' *****\n\n\n')
        modelCount = modelCount + 1
        try:
            print('We are up to model ', modelCount,'!')
            run_model(mypath, model_name, nE, 8000, 2000, 1)
        except:
            print('Failing to run model ', modelCount,'!')
        continue


from ipyparallel import Client
rc = Client(profle='default')

v = Client()[:]
jobs = v.map(parloop, range(4))

Exemplo n.º 3
0
    "---------------------------------------------------------------------------------------------"


# =============================================== #
# For loop to run the grid search and save output
# =============================================== #

model_name = 'stimcoding_z_SW'


def parloop():
    # Create a list for the model variables
    nEs = list(mydata.columns[10:73])
    modelCount = 0

    for nE in nEs:
        print('***** WORKING ON ELEC ' + nE + ' *****\n\n\n')
        modelCount = modelCount + 1
        try:
            print('We are up to model ', modelCount, '!')
            run_model(mypath, model_name, nE, 8000, 2000, 1)
        except:
            print('Failing to run model ', modelCount, '!')
        continue


from ipyparallel import Client
v = Client()[:]
# Edit this for numer of cpus (x)
jobs = v.map(parloop, range(x))