示例#1
0
class testDataSet(unittest.TestCase):
    def setUp(self):
        self.factors=[{'sleepdep':['normal','deprived']},
                      {'stimulus':['left', 'right']}]
        self.responses=['left','right']
        self.design=Design(self.factors,self.responses, 'stimulus')
        
    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)
        assert ds.check(verbose=True)
        assert len(ds.RT)==len(ds.condition)
        assert len(ds.SSD)==len(ds.RT)
        assert len(ds.response)==len(ds.RT)

    def test_factorval(self):
        assert self.design.factorval(0,'sleepdep')=='normal'
        assert self.design.factorval(0,'stimulus')=='left'

        assert self.design.factorval(1,'sleepdep')=='normal'
        assert self.design.factorval(1,'stimulus')=='right'

        assert self.design.factorval(2,'sleepdep')=='deprived'
        assert self.design.factorval(2,'stimulus')=='left'

        assert self.design.factorval(3,'sleepdep')=='deprived'
        assert self.design.factorval(3,'stimulus')=='right'
示例#2
0
 def setUp(self):
     self.factors = [{
         'sleepdep': ['normal', 'deprived']
     }, {
         'stimulus': ['left', 'right']
     }]
     self.responses = ['left', 'right']
     self.design = Design(self.factors, self.responses, 'stimulus')
示例#3
0
 def test_init(self):
     factors=[{'sleepdep':['normal','deprived']},
              {'stimulus':['left', 'right']}]
     responses=['left','right']
     design=Design(factors,responses, 'stimulus')
     assert design.nresponses()==len(responses)
     assert design.nconditions()==4
     assert len(design.factors_to_int)==len(design.factors_from_int)
     k=['deprived','left']
     assert design.condidx(  k )==2
示例#4
0
 def test_init(self):
     factors = [{
         'sleepdep': ['normal', 'deprived']
     }, {
         'stimulus': ['left', 'right']
     }]
     responses = ['left', 'right']
     design = Design(factors, responses, 'stimulus')
     assert design.nresponses() == len(responses)
     assert design.nconditions() == 4
     assert len(design.factors_to_int) == len(design.factors_from_int)
     k = ['deprived', 'left']
     assert design.condidx(k) == 2
示例#5
0
 def setUp(self):
     self.factors = [{
         'TUT': ['tut', 'on-task']
     }, {
         'stimulus': ['left', 'right']
     }]
     self.responses = ['left', 'right']
     self.design = Design(self.factors, self.responses, 'stimulus')
     self.truepar = pSSLBA_modelB.paramspec(ster=.1,
                                            ter=.2,
                                            A=.2,
                                            Bs=.5,
                                            B=.8,
                                            Vs=2.0,
                                            Vtut=.5,
                                            Vont=1.0,
                                            v=0.0)
     self.mod = pSSLBA_modelB(self.design, self.truepar)
示例#6
0
 def test_repr(self):
     factors = [{
         'sleepdep': ['normal', 'deprived']
     }, {
         'stimulus': ['left', 'right']
     }]
     responses = ['left', 'right']
     design = Design(factors, responses, 'stimulus', name="blubber")
     design2 = eval(repr(design))
     assert design.__dict__ == design2.__dict__, "%s vs %s" % (
         repr(design), repr(design2))
示例#7
0
class testDataSet(unittest.TestCase):
    def setUp(self):
        self.factors = [{
            'sleepdep': ['normal', 'deprived']
        }, {
            'stimulus': ['left', 'right']
        }]
        self.responses = ['left', 'right']
        self.design = Design(self.factors, self.responses, 'stimulus')

    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)
        assert ds.check(verbose=True)
        assert len(ds.RT) == len(ds.condition)
        assert len(ds.SSD) == len(ds.RT)
        assert len(ds.response) == len(ds.RT)

    def test_factorval(self):
        assert self.design.factorval(0, 'sleepdep') == 'normal'
        assert self.design.factorval(0, 'stimulus') == 'left'

        assert self.design.factorval(1, 'sleepdep') == 'normal'
        assert self.design.factorval(1, 'stimulus') == 'right'

        assert self.design.factorval(2, 'sleepdep') == 'deprived'
        assert self.design.factorval(2, 'stimulus') == 'left'

        assert self.design.factorval(3, 'sleepdep') == 'deprived'
        assert self.design.factorval(3, 'stimulus') == 'right'
示例#8
0
    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
示例#9
0
 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)
示例#10
0
class testpSSLBA_modelB(unittest.TestCase):
    def setUp(self):
        self.factors = [{
            'TUT': ['tut', 'on-task']
        }, {
            'stimulus': ['left', 'right']
        }]
        self.responses = ['left', 'right']
        self.design = Design(self.factors, self.responses, 'stimulus')
        self.truepar = pSSLBA_modelB.paramspec(ster=.1,
                                               ter=.2,
                                               A=.2,
                                               Bs=.5,
                                               B=.8,
                                               Vs=2.0,
                                               Vtut=.5,
                                               Vont=1.0,
                                               v=0.0)
        self.mod = pSSLBA_modelB(self.design, self.truepar)

    def test_trans(self):
        for i in range(50):
            rpar = pSSLBA_modelB.paramspec().random()
            assert np.all(
                np.abs(rpar - self.mod.untrans(self.mod.trans(rpar)))) < 1e-5

    def test_setparam(self):
        tutcond = [
            i for i in range(self.design.nconditions())
            if self.design.factorval(i, 'TUT') == 'tut'
        ]
        ontcond = [
            i for i in range(self.design.nconditions())
            if self.design.factorval(i, 'TUT') != 'tut'
        ]
        rpar = self.mod.paramspec().random()
        self.mod.set_params(rpar)

        for tc in tutcond:
            correct = self.design.correct_response(tc)
            for ir, resp in enumerate(self.design.responses):
                if resp == correct:
                    assert self.mod.go_accumulators[tc][ir].v == rpar.Vtut
                else:
                    assert self.mod.go_accumulators[tc][ir].v == rpar.v

        for oc in ontcond:
            correct = self.design.correct_response(oc)
            for ir, resp in enumerate(self.design.responses):
                if resp == correct:
                    assert self.mod.go_accumulators[oc][ir].v == rpar.Vont
                else:
                    assert self.mod.go_accumulators[oc][ir].v == rpar.v
示例#11
0
 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)
     assert ds.check(verbose=True)
     assert len(ds.RT) == len(ds.condition)
     assert len(ds.SSD) == len(ds.RT)
     assert len(ds.response) == len(ds.RT)
示例#12
0
    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
示例#13
0
    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)
示例#14
0
 def setUp(self):
     self.factors=[{'sleepdep':['normal','deprived']},
                   {'stimulus':['left', 'right']}]
     self.responses=['left','right']
     self.design=Design(self.factors,self.responses, 'stimulus')