~ubuntu-branches/ubuntu/precise/brian/precise

« back to all changes in this revision

Viewing changes to brian/tests/testinterface/test_monitor.py

  • Committer: Package Import Robot
  • Author(s): Yaroslav Halchenko
  • Date: 2012-01-02 12:49:11 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20120102124911-6r1rmqgt5vr22ro3
Tags: 1.3.1-1
* Fresh upstream release
* Boosted policy compliance to 3.9.2 (no changes)
* Added up_skip_tests_with_paths patch to avoid test failures on custom 
  test scripts with hardcoded paths

Show diffs side-by-side

added added

removed removed

Lines of Context:
124
124
        assert (mi == i)
125
125
        assert (is_approx_equal(mt, t))
126
126
 
 
127
    # test that the spiketimes are saved and accessed correctly
 
128
    
 
129
    assert(len(M[0]) == len(M.spiketimes[0]) == 2 and 
 
130
           len(M[1]) == len(M.spiketimes[1]) == 1)
 
131
    assert((M.spiketimes[0] == M[0]).all() and (M.spiketimes[1] == M[1]).all())
 
132
 
 
133
    # test that spiketimes are cleared on reinit
 
134
    
 
135
    M.reinit()
 
136
    assert (M.nspikes == 0)
 
137
    assert (len(M.spikes) == 0)
 
138
    assert (len(M[0]) == 0 and len(M[1]) == 0)
 
139
    assert (len(M.spiketimes[0]) == 0 and len(M.spiketimes[1]) == 0)
 
140
 
127
141
    # test that SpikeMonitor function calling usage does what you'd expect    
128
142
 
129
143
    f_spikes = []
139
153
    net.run(10 * ms)
140
154
    assert (f_spikes == [0, 1, 0])
141
155
 
 
156
    # test that SpikeMonitors in MultiConnection objects do reinitialize
 
157
    # properly
 
158
    G = SpikeGeneratorGroup(2, spikes, clock=defaultclock)
 
159
    G2 = NeuronGroup(1, model='dv/dt = -v / (5*ms) : 1')
 
160
    C = Connection(G, G2, 'v', weight=0)
 
161
    M = SpikeMonitor(G)
 
162
    # Note: Because M and C share the source (G), they are replaced by a 
 
163
    #       MultiConnection 
 
164
    net = Network(G, G2, C, M)
 
165
    net.run(10 * ms)
 
166
    
 
167
    net.reinit() # make sure that the reinit propagates to the SpikeMonitor
 
168
    assert (M.nspikes == 0)
 
169
    assert (len(M.spikes) == 0)
 
170
    assert (len(M[0]) == 0 and len(M[1]) == 0)
 
171
    assert (len(M.spiketimes[0]) == 0 and len(M.spiketimes[1]) == 0)
 
172
    
 
173
    
 
174
    
 
175
 
142
176
    # test interface for StateMonitor object
143
177
 
144
178
    dV = 'dV/dt = 0*Hz : 1.'
202
236
 
203
237
    reinit_default_clock() # for next test
204
238
 
 
239
def test_counter():
 
240
    '''
 
241
    Tests the consistency of :class:`SpikeCounter`,
 
242
    :class:`PopulationSpikeCounter` and :class:`SpikeMonitor`.
 
243
    '''
 
244
    
 
245
    reinit_default_clock()
 
246
    
 
247
    # Test whether all monitors count the same number of spikes
 
248
    
 
249
    spikes = [(0, 3 * ms), (1, 4 * ms), (0, 7 * ms)]
 
250
 
 
251
    G = SpikeGeneratorGroup(2, spikes, clock=defaultclock)
 
252
    M = SpikeMonitor(G)
 
253
    C = SpikeCounter(G)
 
254
    P = PopulationSpikeCounter(G)
 
255
    net = Network(G, M, C, P)
 
256
    net.run(10 * ms)
 
257
    
 
258
    # total number of spikes
 
259
    assert(M.nspikes == C.nspikes == P.nspikes == 3)
 
260
    # spikes per neuron
 
261
    assert(len(M[0]) == C[0] == C.count[0] == 2)
 
262
    assert(len(M[1]) == C[1] == C.count[1] == 1)
 
263
    # check for correct reinit
 
264
    net.reinit()
 
265
    assert(M.nspikes == C.nspikes == P.nspikes == 0)
 
266
    assert(len(M[0]) == C[0] == C.count[0] == 0)
 
267
    assert(len(M[1]) == C[1] == C.count[1] == 0)
 
268
    
 
269
    reinit_default_clock() # for next test
 
270
    
 
271
 
205
272
def test_coincidencecounter():
206
273
    """
207
274
    Simulates an IF model with constant input current and checks
406
473
 
407
474
if __name__ == '__main__':
408
475
    test_spikemonitor()
 
476
    test_counter()
409
477
#    test_coincidencecounter()