def test_deviance_precalc(self): rpar = pSSLBA_modelA.paramspec(*list(np.random.rand(8))) self.mod.set_params_c(rpar) L1 = self.mod.deviance_precalc(self.ds) self.mod.set_params(rpar) L2 = self.mod.deviance(self.ds) assert abs(L1 - L2) < 1e-10, "L1,L2=%f, %f" % (L1, L2)
def test_loglikelihood(self): factors=[{'sleepdep':['normal','deprived']}, {'stimulus':['left', 'right']}] responses=['left','right'] design=Design(factors,responses, 'stimulus') dat=pd.read_csv('./data/sleep_stop_onesubj_test.csv') dat.columns=['sleepdep','stimulus','SSD','response','correct', 'RT'] ds=StopTaskDataSet(design,dat) pars=pSSLBA_modelA.paramspec(.1, .2, .2, .5, .8, 2, 1, 0) mod=pSSLBA_modelA(design, pars) print mod Ls=StopTaskRaceModel.deviance(mod, ds) L2=mod.deviance(ds) assert np.abs(Ls-L2)<1e-8
def setUp(self): self.factors = [{ 'sleepdep': ['normal', 'deprived'] }, { 'stimulus': ['left', 'right'] }] self.responses = ['left', 'right'] self.design = Design(self.factors, self.responses, 'stimulus') self.dat = pd.read_csv('./data/sleep_stop_onesubj_test.csv') assert self.dat.shape[0] == 800 self.dat.columns = [ 'sleepdep', 'stimulus', 'SSD', 'response', 'correct', 'RT' ] self.ds = StopTaskDataSet(self.design, self.dat) pars = pSSLBA_modelA.paramspec(.2, .15, .2, 1.0, 1.0, 2, 1, 0.5) self.mod = pSSLBA_modelA(self.design, pars)
def test_set_params_c(self): #rpar=np.random.rand(8) rpar = pSSLBA_modelA.paramspec(*list(np.random.rand(8))) self.mod.set_params_c(rpar) cp1 = self.mod.cpars self.mod.set_params(rpar) cp2 = self.mod.get_cpars() parnames = [ 'go_v', 'go_ter', 'go_A', 'go_b', 'go_sv', 'stop_v', 'stop_ter', 'stop_A', 'stop_b', 'stop_sv', 'pgf', 'ptf' ] ix = 0 for c1, c2 in zip(cp1, cp2): assert np.all( np.abs(c1 - c2) < 1e-10), "%i (=parameter %s): %s,%s" % ( ix, parnames[ix], str(c1), str(c2)) ix += 1
def test_sslba_likelihood_trials(self): factors=[{'sleepdep':['normal','deprived']}, {'stimulus':['left', 'right']}] responses=['left','right'] design=Design(factors,responses, 'stimulus') dat=pd.read_csv('./data/sleep_stop_onesubj_test.csv') dat.columns=['sleepdep','stimulus','SSD','response','correct', 'RT'] ds=StopTaskDataSet(design,dat) pars=pSSLBA_modelA.paramspec(.1, .2, .2, .5, .8, 2, 1, 0) mod=pSSLBA_modelA(design, pars) print mod Ls=StopTaskRaceModel.likelihood_trials(mod, ds) L2=mod.likelihood_trials(ds) goodix=(np.abs(Ls-L2)<1e-5) badix=np.logical_not(goodix) assert np.sum(badix)==0, "num bad idx=%i"%np.sum(badix)
def test_loglikelihood(self): factors = [{ 'sleepdep': ['normal', 'deprived'] }, { 'stimulus': ['left', 'right'] }] responses = ['left', 'right'] design = Design(factors, responses, 'stimulus') dat = pd.read_csv('./data/sleep_stop_onesubj_test.csv') dat.columns = [ 'sleepdep', 'stimulus', 'SSD', 'response', 'correct', 'RT' ] ds = StopTaskDataSet(design, dat) pars = pSSLBA_modelA.paramspec(.1, .2, .2, .5, .8, 2, 1, 0) mod = pSSLBA_modelA(design, pars) print mod Ls = StopTaskRaceModel.deviance(mod, ds) L2 = mod.deviance(ds) assert np.abs(Ls - L2) < 1e-8
def test_init(self): factors = [{ 'sleepdep': ['normal', 'deprived'] }, { 'stimulus': ['left', 'right'] }] responses = ['left', 'right'] design = Design(factors, responses, 'stimulus') dat = pd.read_csv('./data/sleep_stop_onesubj_test.csv') assert dat.shape[0] == 800 dat.columns = [ 'sleepdep', 'stimulus', 'SSD', 'response', 'correct', 'RT' ] ds = StopTaskDataSet(design, dat) pars = pSSLBA_modelA.paramspec(.2, .15, .2, 1.0, 1.0, 2, 1, 0.5) mod = pSSLBA_modelA(design, pars) print mod.parstring(full=True) print mod print mod.go_accumulators[0] nsamples = 100 x = np.linspace(0.01, 10, nsamples) condition = 0 dens = mod.dens_acc_go(x, condition, 1) cscore = 0 for i in range(design.nresponses()): score = scipy.integrate.quad(mod.dens_acc_go, 0.01, np.infty, args=(condition, i))[0] print "Chance of winning Acc %i (condition=%s): %f" % ( i, str(design.condidx(condition)), score) cscore += score assert abs(cscore - 1) < 1e-6 print cscore L = mod.loglikelihood(ds) assert np.isfinite(L) print "L=", L
def test_sslba_likelihood_trials(self): factors = [{ 'sleepdep': ['normal', 'deprived'] }, { 'stimulus': ['left', 'right'] }] responses = ['left', 'right'] design = Design(factors, responses, 'stimulus') dat = pd.read_csv('./data/sleep_stop_onesubj_test.csv') dat.columns = [ 'sleepdep', 'stimulus', 'SSD', 'response', 'correct', 'RT' ] ds = StopTaskDataSet(design, dat) pars = pSSLBA_modelA.paramspec(.1, .2, .2, .5, .8, 2, 1, 0) mod = pSSLBA_modelA(design, pars) print mod Ls = StopTaskRaceModel.likelihood_trials(mod, ds) L2 = mod.likelihood_trials(ds) goodix = (np.abs(Ls - L2) < 1e-5) badix = np.logical_not(goodix) assert np.sum(badix) == 0, "num bad idx=%i" % np.sum(badix)