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)
def test(debug=True): from spikeplot import plt, mcdata # setup TF = 47 signal, noise, ce, temps = load_input_data(TF) FB = BOTMNode( templates=temps, ce=ce, adapt_templates=10, learn_noise=False, verbose=VERBOSE(debug * 10), ovlp_taus=None, chunk_size=500) x = sp.ascontiguousarray(signal + noise, dtype=sp.float32) # sort FB.plot_xvft() FB(x) FB.plot_sorting() print FB.rval plt.show()
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)