コード例 #1
0
 def test_inserted_spikes_equal_cost_of_one(self):
     num_spikes = 3
     st = neo.SpikeTrain(sp.arange(3) * pq.s, t_stop=num_spikes * pq.s)
     st_empty = create_empty_spike_train()
     expected = sp.array([[0.0, num_spikes], [num_spikes, 0.0]])
     assert_array_almost_equal(
         expected, stm.victor_purpura_dist([st, st_empty]))
コード例 #2
0
    def test_returns_discretization_bins(self):
        start = 2.0 * pq.s
        stop = 5.0 * pq.s
        sampling_rate = 2.0 * pq.Hz
        expected = sp.array([2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0]) * pq.s

        st = create_empty_spike_train(start, stop)
        _, bins = sigproc.st_convolve(
            st, sigproc.GaussianKernel(), sampling_rate=sampling_rate)
        assert_array_almost_equal(expected, bins)
コード例 #3
0
 def test_returns_nan_if_one_spike_train_is_empty(self):
     empty = create_empty_spike_train()
     non_empty = neo.SpikeTrain(sp.array([1.0]) * pq.s, t_stop=2.0 * pq.s)
     k = sigproc.GaussianKernel()
     with warnings.catch_warnings():
         warnings.simplefilter('ignore')
         actual = stm.schreiber_similarity((empty, non_empty), k)
     self.assertTrue(sp.isnan(actual[0, 0]))
     self.assertTrue(sp.isnan(actual[0, 1]))
     self.assertTrue(sp.isnan(actual[1, 0]))
コード例 #4
0
 def test_returns_nan_if_one_spike_train_is_empty(self):
     empty = create_empty_spike_train()
     non_empty = neo.SpikeTrain(sp.array([1.0]) * pq.s, t_stop=2.0 * pq.s)
     sampling_rate = 100 * pq.Hz
     smoothing_filter = sigproc.GaussianKernel()
     with warnings.catch_warnings():
         warnings.simplefilter('ignore')
         self.assertTrue(sp.all(sp.isnan(stm.cs_dist(
             [empty, non_empty], smoothing_filter,
             sampling_rate=sampling_rate))[(0, 0, 1), (0, 1, 0)]))
コード例 #5
0
    def test_returns_discretization_bins(self):
        start = 2.0 * pq.s
        stop = 5.0 * pq.s
        sampling_rate = 2.0 * pq.Hz
        expected = sp.array([2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0]) * pq.s

        st = create_empty_spike_train(start, stop)
        _, bins = sigproc.st_convolve(st,
                                      sigproc.GaussianKernel(),
                                      sampling_rate=sampling_rate)
        assert_array_almost_equal(expected, bins)
コード例 #6
0
    def test_length_of_returned_array_equals_sampling_rate_times_duration(self):
        start = 2.0 * pq.s
        stop = 5.0 * pq.s
        duration = stop - start
        sampling_rate = 12 * pq.Hz
        expected_length = (sampling_rate * duration).simplified

        st = create_empty_spike_train(start, stop)
        result, _ = sigproc.st_convolve(
            st, sigproc.GaussianKernel(), sampling_rate=sampling_rate)
        self.assertEqual(expected_length, result.size)
コード例 #7
0
 def test_returns_norm_if_one_spike_train_is_empty(self):
     empty = create_empty_spike_train()
     non_empty = neo.SpikeTrain(sp.array([1.0]) * pq.s, t_stop=2.0 * pq.s)
     sampling_rate = 100 * pq.Hz
     smoothing_filter = sigproc.GaussianKernel()
     norm = stm.st_norm(
         non_empty, smoothing_filter, sampling_rate=sampling_rate)
     expected = sp.array([[0.0, norm], [norm, 0.0]]) * pq.Hz ** 0.5
     actual = stm.norm_dist(
         [empty, non_empty], smoothing_filter, sampling_rate=sampling_rate)
     assert_array_almost_equal(expected, actual, decimal=3)
コード例 #8
0
    def test_length_of_returned_array_equals_sampling_rate_times_duration(
            self):
        start = 2.0 * pq.s
        stop = 5.0 * pq.s
        duration = stop - start
        sampling_rate = 12 * pq.Hz
        expected_length = (sampling_rate * duration).simplified

        st = create_empty_spike_train(start, stop)
        result, _ = sigproc.st_convolve(st,
                                        sigproc.GaussianKernel(),
                                        sampling_rate=sampling_rate)
        self.assertEqual(expected_length, result.size)
コード例 #9
0
    def test_mode_allows_valid_convolution(self):
        start = 2.0 * pq.s
        stop = 5.0 * pq.s
        sampling_rate = 2.0 * pq.Hz
        kernel = sigproc.RectangularKernel(0.6 * pq.s)
        st = create_empty_spike_train(start, stop)

        expected_length = (stop - start) * sampling_rate - 2
        expected_bins = sp.array([2.5, 3.0, 3.5, 4.0, 4.5]) * pq.s

        binned, bins = sigproc.st_convolve(
            st, kernel, mode='valid', sampling_rate=sampling_rate)
        self.assertEqual(binned.size, expected_length)
        assert_array_almost_equal(expected_bins, bins)
コード例 #10
0
 def test_returns_zero_if_any_spike_train_is_empty(self):
     empty = create_empty_spike_train()
     non_empty = neo.SpikeTrain(sp.array([1.0]) * pq.s, t_stop=2.0 * pq.s)
     smoothing_filter = sigproc.GaussianKernel()
     sampling_rate = 1 * pq.Hz
     expected = sp.array([0.0]) * pq.Hz
     self.assertAlmostEqual(
         expected, stm.st_inner(
             [empty], [empty], smoothing_filter, sampling_rate))
     self.assertAlmostEqual(
         expected, stm.st_inner(
             [empty], [non_empty], smoothing_filter, sampling_rate))
     self.assertAlmostEqual(
         expected, stm.st_inner(
             [non_empty], [empty], smoothing_filter, sampling_rate))
コード例 #11
0
    def test_mode_allows_valid_convolution(self):
        start = 2.0 * pq.s
        stop = 5.0 * pq.s
        sampling_rate = 2.0 * pq.Hz
        kernel = sigproc.RectangularKernel(0.6 * pq.s)
        st = create_empty_spike_train(start, stop)

        expected_length = (stop - start) * sampling_rate - 2
        expected_bins = sp.array([2.5, 3.0, 3.5, 4.0, 4.5]) * pq.s

        binned, bins = sigproc.st_convolve(st,
                                           kernel,
                                           mode='valid',
                                           sampling_rate=sampling_rate)
        self.assertEqual(binned.size, expected_length)
        assert_array_almost_equal(expected_bins, bins)
コード例 #12
0
 def test_convolution_with_empty_spike_train_returns_array_of_zeros(self):
     st = create_empty_spike_train()
     result, _ = sigproc.st_convolve(st, sigproc.GaussianKernel(),
                                     1 * pq.Hz)
     self.assertTrue(sp.all(result == 0.0))
コード例 #13
0
 def test_convolution_with_empty_spike_train_returns_array_of_zeros(self):
     st = create_empty_spike_train()
     result, _ = sigproc.st_convolve(st, sigproc.GaussianKernel(), 1 * pq.Hz)
     self.assertTrue(sp.all(result == 0.0))
コード例 #14
0
 def test_raises_exception_if_number_of_trials_differs(self):
     st = create_empty_spike_train()
     with self.assertRaises(ValueError):
         stm.victor_purpura_multiunit_dist({0: [st], 1: [st, st]}, 1.0)
コード例 #15
0
 def test_returns_zero_if_spike_train_is_empty(self):
     empty = create_empty_spike_train()
     smoothing_filter = sigproc.GaussianKernel()
     self.assertAlmostEqual(0.0, stm.st_norm(
         empty, smoothing_filter, 1 * pq.Hz))
コード例 #16
0
 def test_spike_trains_may_be_empty(self):
     empty = create_empty_spike_train()
     non_empty = neo.SpikeTrain(sp.array([1.0]) * pq.s, t_stop=3.0 * pq.s)
     expected = sp.array([[1.0, 0.0], [0.0, 1.0]])
     actual = stm.hunter_milton_similarity([empty, non_empty])
     assert_array_almost_equal(expected, actual)