Esempio n. 1
0
 def test_summed_dist_matrix(self):
     kernel = sigproc.Kernel(1.0, normalize=False)
     kernel._evaluate = lambda t, _: sp.absolute(t)
     vectors = [sp.array([2.0, 1.0, 3.0]), sp.array([1.5, 4.0])]
     expected = sp.array([[8.0, 8.5], [8.5, 5.0]])
     actual = kernel.summed_dist_matrix(vectors)
     assert_array_almost_equal(expected, actual)
Esempio n. 2
0
 def test_summed_dist_matrix_with_units(self):
     kernel = sigproc.Kernel(2000 * pq.ms, normalize=False)
     kernel._evaluate = lambda t, size: 1.0 / size / size * sp.absolute(t)
     vectors = [
         sp.array([2.0, 1.0, 3.0]) * pq.s,
         sp.array([1500, 4000]) * pq.ms
     ]
     expected = sp.array([[2.0, 2.125], [2.125, 1.25]]) / pq.s
     actual = kernel.summed_dist_matrix(vectors)
     assert_array_almost_equal(expected, actual.rescale(1.0 / pq.s))
Esempio n. 3
0
    def test_call_returns_result_of_evaluate(self):
        kernel_size = 1.3
        kernel = sigproc.Kernel(kernel_size, normalize=False)
        kernel._evaluate = MagicMock(name='_evaluate')
        kernel._evaluate.return_value = 42

        t = 3.3
        actual = kernel(t)

        kernel._evaluate.assert_called_with(t, kernel_size)
        self.assertEqual(kernel._evaluate.return_value, actual)
Esempio n. 4
0
    def test_discretizes_requested_number_of_bins(self):
        kernel = sigproc.Kernel(1.0, normalize=False)
        kernel._evaluate = lambda x, _: sp.ones(len(x))
        sampling_rate = 1.0
        num_bins = 23
        mock_discretization = sp.ones(num_bins)

        actual = sigproc.discretize_kernel(kernel,
                                           sampling_rate,
                                           num_bins=num_bins)
        assert_array_equal(actual, mock_discretization)
Esempio n. 5
0
    def test_can_normalize_to_unit_area(self):
        kernel = sigproc.Kernel(1.0, normalize=False)
        kernel._evaluate = lambda x, _: sp.ones(len(x))
        sampling_rate = 2.0
        num_bins = 20
        mock_discretization = sp.ones(num_bins) / num_bins * sampling_rate

        actual = sigproc.discretize_kernel(kernel,
                                           sampling_rate,
                                           num_bins=num_bins,
                                           ensure_unit_area=True)
        assert_array_equal(actual, mock_discretization)
Esempio n. 6
0
    def test_call_can_overwrite_kernel_size(self):
        kernel_size = 1.3
        kernel = sigproc.Kernel(5.6, normalize=True)
        kernel._evaluate = MagicMock(name='_evaluate')
        kernel._evaluate.return_value = 42
        kernel.normalization_factor = MagicMock(name='normalization_factor')
        kernel.normalization_factor.return_value = 0.5

        t = 3.3
        actual = kernel(t, kernel_size)

        kernel._evaluate.assert_called_with(t, kernel_size)
        kernel.normalization_factor.assert_called_with(kernel_size)
        self.assertEqual(
            kernel.normalization_factor.return_value *
            kernel._evaluate.return_value, actual)
Esempio n. 7
0
    def test_discretizes_requested_area_with_units(self):
        kernel = sigproc.Kernel(100.0 * pq.ms, normalize=False)
        kernel.boundary_enclosing_at_least = MagicMock(
            name='boundary_enclosing_at_least')
        kernel.boundary_enclosing_at_least.return_value = 100.0 * pq.ms
        kernel._evaluate = lambda x, _: sp.ones(len(x))
        sampling_rate = 10.0 * pq.Hz
        mock_discretization = sp.ones(3)

        kernel_area_fraction = 0.5
        actual = sigproc.discretize_kernel(kernel, sampling_rate,
                                           kernel_area_fraction)

        kernel.boundary_enclosing_at_least.assert_called_with(
            kernel_area_fraction)
        assert_array_equal(actual, mock_discretization)