Esempio n. 1
0
    def testMainSingle(self, verbose=VERBOSE.PLOT):
        import time

        # setup
        V = VERBOSE(verbose)
        TF = 21
        NC = 2
        spike_proto_sc = sp.cos(sp.linspace(-sp.pi, 3 * sp.pi, TF))
        spike_proto_sc *= sp.hanning(TF)
        scale = sp.linspace(0, 2, TF)
        xi1 = sp.vstack(
            (spike_proto_sc * 5 * scale, spike_proto_sc * 4 * scale)).T
        xi2 = sp.vstack((spike_proto_sc * .5 * scale[::-1],
                         spike_proto_sc * 9 * scale[::-1])).T
        templates = sp.asarray([xi1, xi2])
        LEN = 2000
        noise = sp.randn(LEN, NC)
        ce = TimeSeriesCovE(tf_max=TF, nc=NC)
        ce.update(noise)
        FB = BOTMNode(templates=templates, ce=ce, verbose=V, ovlp_taus=None)
        signal = sp.zeros_like(noise)
        NPOS = 4
        POS = [(int(i * LEN / (NPOS + 1)), 100) for i in xrange(1, NPOS + 1)]
        POS.append((100, 2))
        POS.append((150, 2))
        for pos, tau in POS:
            signal[pos:pos + TF] += xi1
            signal[pos + tau:pos + tau + TF] += xi2
        x = sp.ascontiguousarray(signal + noise, dtype=sp.float32)

        # test against
        if V.has_print:
            print '### constructed spike times ###'
        test_u0 = sorted([t_tpl[0] for t_tpl in POS])
        test_u1 = sorted([t_tpl[0] + t_tpl[1] for t_tpl in POS])
        test_rval = {
            0: sp.array(test_u0) + TF / 2,
            1: sp.array(test_u1) + TF / 2
        }
        if V.has_print:
            print test_rval

        # sort
        tic_o = time.clock()
        FB(x)
        toc_o = time.clock()
        if V.has_print:
            print '### sorting spike times ###'
            print FB.rval

        if V.has_plot:
            FB.plot_template_set(show=False)
            FB.plot_sorting(show=True)

        if V.has_print:
            print '###'
            print 'duration:', toc_o - tic_o

        for k in FB.rval:
            assert_array_almost_equal(FB.rval[k], test_rval[k], decimal=0)
Esempio n. 2
0
 def setUp(self):
     self.dlen = 250000
     self.tf = 65
     self.nc = 4
     self.white_noise = sp.randn(self.dlen, self.nc)
     self.CE = TimeSeriesCovE(tf_max=self.tf, nc=self.nc)
     self.CE.new_chan_set((1, 2))
     self.CE.update(self.white_noise)
Esempio n. 3
0
 def setUp(self):
     self.tf = 10
     self.nc = 2
     self.xi = sp.vstack(
         [sp.arange(self.tf).astype(sp.float32)] * self.nc).T * 0.5
     self.len = 1000
     self.pos = [int(i * self.len / 4.0) for i in xrange(1, 4)]
     self.noise = sp.randn(self.len, self.nc)
     self.ce = TimeSeriesCovE(tf_max=self.tf, nc=self.nc)
     self.ce.update(self.noise)