Exemplo n.º 1
0
    def get_ideal_observer(dotpos=None, bound=0.8):
        if dotpos is None:
            dotpos = load_dots()
        D = dotpos.shape[0]

        feature_means = np.c_[[-cond, 0], [cond, 0]]
        model = rtmodels.discrete_static_gauss(dt=dotdt,
                                               maxrt=dotdt * D,
                                               toresponse=toresponse,
                                               choices=[-1, 1],
                                               Trials=dotpos,
                                               means=feature_means)

        # set ideal observer parameters
        model.intstd = dotstd
        model.noisestd = 1e-15
        model.prior = 0.5
        model.lapseprob = 0.0
        model.ndtmean = -100
        model.bound = bound

        return model
Exemplo n.º 2
0
cond = helpers.cond

feature_means = np.c_[[-cond, 0], [cond, 0]]

toresponse = helpers.toresponse

# sort trials such that fitind are first, because EP-ABC will only fit the 
# first couple of trials that are stored in the model
fitind = np.setdiff1d(np.arange(L), testind, assume_unique=True)
allind = np.r_[fitind, testind]
Trials = dotpos[:, :, allind]


#%% make basic model and parameters
model = rtmodels.discrete_static_gauss(dt=dotdt, maxrt=dotdt*D, 
                                       toresponse=toresponse, choices=[-1, 1], 
                                       Trials=Trials, means=feature_means, 
                                       intstd=dotstd)


#%% setup EP-ABC

# normalising constant of the uniform distribution over the data space in
# which samples are accepted as defined by distfun and epsilon; for 
# response_dist this is 2*epsilon for the Euclidean distance between true 
# and sampled RT
veps = 2 * epsilon


#%% inference
for mname in models:
    # generate time-stamped file name
Exemplo n.º 3
0
import rtmodels
import numpy as np
from scipy.stats import multivariate_normal

#%% make model
dotstd = 70.0

stimulus = np.random.randint(1, 3, 200)
means = np.c_[[-25., 0], [25, 0]]
features = means[:, stimulus - 1]
features = np.tile(features, (25, 1, 1))
features += np.random.normal(scale=70, size=features.shape)

model = rtmodels.discrete_static_gauss(Trials=features,
                                       dt=0.1,
                                       choices=[1, 2],
                                       means=means,
                                       maxrt=2.5,
                                       toresponse=[0, 5.])

model.noisestd = 1e-10
model.intstd = dotstd
model.bound = 0.99
model.bstretch = 0.2
model.bshape = 0.4
model.lapseprob = 0.0
model.ndtmean = -20
model.prior = 0.34

#%% sample responses from model with numba
ch, rt = model.gen_response(np.arange(200))
model.plot_response_distribution(ch, rt)
Exemplo n.º 4
0
import pandas as pd
import matplotlib.pyplot as plt
import pyEPABC
from pyEPABC.parameters import exponential, gaussprob
import rtmodels

#%% load data
data = pd.read_csv(os.path.join(os.path.dirname(__file__), 'responsedata.csv'))

N = data.shape[0]

#%% create response model with some standard parameter settings
model = rtmodels.discrete_static_gauss(dt=0.05,
                                       maxrt=2.5,
                                       choices=[1, 2],
                                       Trials=data.stimulus.values,
                                       means=np.c_[[-25, 0], [25, 0]],
                                       intstd=70,
                                       noisestd=60)

print(model)

ch_sim, rt_sim = model.gen_response(np.arange(N), 1000)

fig, axes = plt.subplots(2, 1, sharex=True, sharey=True)
model.plot_response_distribution(data.choice, data.RT, ax=axes[0])
model.plot_response_distribution(ch_sim, rt_sim, ax=axes[1])

axes[0].set_ylabel('response data')
axes[1].set_ylabel('model simulations')
axes[1].set_xlabel('RT (s)')
Exemplo n.º 5
0
pars.add_param('ndtspread', -1.5, 1, exponential())
pars.add_param('noisestd', 4, 1.5, exponential())
pars.add_param('bound', 0, 1, gaussprob(0.5, 0.5))
pars.add_param('prior', 0, 1, gaussprob())
pars.add_param('lapseprob', -1, 1, gaussprob())
pars.add_param('lapsetoprob', 0, 1, gaussprob())

# collapsing bound parameters
if collapse:
    pars.add_param('bshape', np.log(1.4), 1.5, exponential())
    pars.add_param('bstretch', 0, 1, gaussprob())

# make model
model = rtmodels.discrete_static_gauss(maxrt=dotdt * D,
                                       choices=[-1, 1],
                                       Trials=Trials,
                                       means=feature_means,
                                       intstd=dotstd)

model.dt = dotdt
model.toresponse = toresponse
# this is ignored when ndtmean is fitted, but makes a difference when
# predicting from the model and not providing a value for ndtmean in the call
model.ndtmean = -10

# plot prior distribution of parameters
if S > 0:
    pars.plot_param_dist(S=S)

#%% setup and run EP-ABC
# wrapper for sampling from model and directly computing distances
Created on Wed Jun  1 16:02:43 2016

@author: Sebastian Bitzer ([email protected])
"""

import numpy as np
import matplotlib.pyplot as plt
import rtmodels

dt = 0.1

N = 2000

# make model
model = rtmodels.discrete_static_gauss(maxrt=2.5, choices=[-1, 1], 
    Trials=(np.random.randint(2, size=N) - 0.5) * 2, 
    means=np.c_[[-25, 0], [25, 0]], intstd=70.)
    
# ignore lapses
model.lapseprob = 0    
    
# set nondecision time distribution with small, but realistic values
model.ndtmean = -0.9
model.ndtspread = 0.41

# noise relatively small
model.noisestd = 70

# simulate from model
choice, rt = model.gen_response(np.arange(N))
Exemplo n.º 7
0
# -*- coding: utf-8 -*-

import numpy as np
import matplotlib.pyplot as plt
import rtmodels

plt.style.use('ggplot')

choices = np.array([-1, 1])
Trials = choices[np.random.randint(2, size=100)]

model = rtmodels.discrete_static_gauss(maxrt=2.5,
                                       choices=choices,
                                       Trials=Trials)

trind = np.random.randint(100, size=10000)
choices, rts = model.gen_response_with_params(trind, params={'ndtspread': 0.3})

model.plot_response_distribution(choices, rts)

print('fraction correct = %6.4f' % np.mean(choices == Trials[trind]))