Пример #1
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 13 15:01:37 2018

@author: bitzer
"""

import numpy as np
import matplotlib.pyplot as plt

import helpers
from rotated_directions import rotated_directions as dirmodel

#%% create model based on experimental data
data = helpers.load_subject(19, exclude_to=False, censor_late=True)
N = data.shape[0]

choices = [1, -1]
ndtdist = 'uniform'
model = dirmodel(data.tarDir / 180. * np.pi,
                 helpers.dt,
                 data.tarDir.unique() / 180. * np.pi,
                 data.critDir / 180. * np.pi,
                 maxrt=helpers.maxrt + helpers.dt,
                 toresponse=helpers.toresponse,
                 choices=choices,
                 ndtdist=ndtdist)

model.bound = 0.7
model.intstd = 0.18
Пример #2
0
    exclude_to = store['scalar_opt'].exclude_to

subjects = samples.index.get_level_values('subject').unique()

#%%
diff_data = pd.DataFrame([], columns=['accuracy', 'median RT'], index=subjects)
diff_post = pd.DataFrame([],
                         columns=['accuracy', 'median RT'],
                         index=pd.MultiIndex.from_product(
                             [subjects, np.arange(S)],
                             names=['subject', 'sample']))

for sub in subjects:
    print('\rprocessing subject %2d ...' % sub, end='')
    data = helpers.load_subject(sub,
                                exclude_to=exclude_to,
                                censor_late=censor_late)
    stim = data.response.copy().astype(int)
    err = data.error.astype(bool)
    stim[err] = -stim[err]

    with pd.HDFStore(result, 'r') as store:
        ppc_data = store.select('ppc_data', 'subject=sub').loc[sub]

    ppc_data.sort_index(inplace=True)
    N = ppc_data.loc[0].shape[0]

    resh = lambda data: data.values.reshape(N, S, order='F')

    diff_post.loc[sub,
                  'accuracy'], diff_post.loc[sub,
Пример #3
0
    eegdir=helpers.eegdir if use_liks else None)
#subjects = [18]

options = dict(use_liks=use_liks,
               censor_late=True,
               exclude_to=False,
               stats='hist')

resdir = os.path.join(helpers.resultsdir, 'snl', 'rotated_directions',
                      pd.datetime.now().strftime('%Y%m%d%H%M'))
os.mkdir(resdir)

for sub in subjects:
    if options['stats'] == 'id':
        data = helpers.load_subject(sub,
                                    exclude_to=options['exclude_to'],
                                    censor_late=options['censor_late'])
        conditions = data.easy
    else:
        conditions = None

    sim, stat, data = snlsim.create_simulator(sub,
                                              pars,
                                              ndtdist=ndtdist,
                                              fix=fix,
                                              **options)

    #    p = pars.sample(10)
    #    stat.calc(sim.sim(p))

    obs_xs = stat.calc(data[['response', 'RT']])
Пример #4
0
@author: bitzer
"""

import numpy as np
#import pandas as pd
import helpers

import rotated_directions as rtmodels

import pyEPABC
from pyEPABC.parameters import exponential, gaussprob
import matplotlib.pyplot as plt

#%% load data
sub = 18
data = helpers.load_subject(sub)

#%% create model
dt = 0.05

# first of these indicates clockwise rotation, second anti-clockwise
choices = [1, -1]

model = rtmodels.rotated_directions(data.tarDir / 180 * np.pi,
                                    dt,
                                    data.tarDir.unique() / 180 * np.pi,
                                    data.critDir / 180 * np.pi,
                                    maxrt=data.dropna().RT.max() + dt,
                                    toresponse=helpers.toresponse,
                                    choices=choices)
Пример #5
0
def create_simulator(sub,
                     pars,
                     use_liks=False,
                     stats='hist',
                     exclude_to=False,
                     censor_late=True,
                     ndtdist='lognorm',
                     fix={}):
    data = helpers.load_subject(sub,
                                exclude_to=exclude_to,
                                censor_late=censor_late)

    # first of these indicates clockwise rotation, second anti-clockwise
    choices = [1, -1]

    # identify the model based on inferred parameters
    modelstr = identify_model(np.r_[pars.names, fix.keys()])
    if modelstr == 'diff':
        if use_liks is None:
            model = dirdiffmodel(
                {
                    'directions': data.tarDir,
                    'criteria': data.critDir
                },
                helpers.dt,
                maxrt=helpers.maxrt + helpers.dt,
                toresponse=helpers.toresponse,
                choices=choices,
                ndtdist=ndtdist,
                **fix)
        else:
            pass
    else:
        if use_liks:
            Trials, trind, channels = helpers.load_subject_eeg(sub)
            directions = -channels % (2 * np.pi)

            data = data.reindex(trind)

            model = dirmodel(Trials,
                             dt=helpers.dt,
                             directions=directions,
                             criteria=data.critDir / 180. * np.pi,
                             maxrt=helpers.maxrt + helpers.dt,
                             toresponse=helpers.toresponse,
                             choices=choices,
                             ndtdist=ndtdist,
                             trial_dirs=data.tarDir / 180. * np.pi,
                             **fix)
        else:
            model = dirmodel(data.tarDir / 180. * np.pi,
                             helpers.dt,
                             data.tarDir.unique() / 180. * np.pi,
                             data.critDir / 180. * np.pi,
                             maxrt=helpers.maxrt + helpers.dt,
                             toresponse=helpers.toresponse,
                             choices=choices,
                             ndtdist=ndtdist,
                             **fix)

    if stats == 'hist':
        stats = Stats_hist(model,
                           pars,
                           data['easy'],
                           rts=data.RT,
                           exclude_to=exclude_to)
    elif stats == 'quant':
        stats = Stats_quant(model, pars, data['easy'], exclude_to=exclude_to)
    elif stats == 'id':
        stats = Stats_id(model, pars, data['easy'])
    else:
        raise ValueError('Unknown type of summary statistics!')

    return Simulator(model, pars), stats, data