Ejemplo n.º 1
0
 def test_error_kernels(self):
     """
     Test of various error cases in the kernels module.
     """
     self.assertRaises(
         TypeError, kernels.RectangularKernel, sigma=2.0)
     self.assertRaises(
         ValueError, kernels.RectangularKernel, sigma=-0.03 * pq.s)
     self.assertRaises(
         ValueError, kernels.AlphaKernel, sigma=2.0 * pq.ms,
         invert=2)
     rec_kernel = kernels.RectangularKernel(sigma=0.3 * pq.ms)
     self.assertRaises(
         TypeError, rec_kernel, [1, 2, 3])
     self.assertRaises(
         TypeError, rec_kernel, [1, 2, 3] * pq.V)
     kernel = kernels.Kernel(sigma=0.3 * pq.ms)
     self.assertRaises(
         NotImplementedError, kernel._evaluate, [1, 2, 3] * pq.V)
     self.assertRaises(
         NotImplementedError, kernel.boundary_enclosing_area_fraction,
         fraction=0.9)
     self.assertRaises(TypeError,
                       rec_kernel.boundary_enclosing_area_fraction, [1, 2])
     self.assertRaises(ValueError,
                       rec_kernel.boundary_enclosing_area_fraction, -10)
     self.assertEqual(kernel.is_symmetric(), False)
     self.assertEqual(rec_kernel.is_symmetric(), True)
Ejemplo n.º 2
0
    def test_wrong_input(self):
        self.assertRaises(TypeError, stds.victor_purpura_distance,
                          [self.array1, self.array2], self.q3)
        self.assertRaises(TypeError, stds.victor_purpura_distance,
                          [self.qarray1, self.qarray2], self.q3)
        self.assertRaises(TypeError, stds.victor_purpura_distance,
                          [self.qarray1, self.qarray2], 5.0 * ms)

        self.assertRaises(TypeError,
                          stds.victor_purpura_distance,
                          [self.array1, self.array2],
                          self.q3,
                          algorithm='intuitive')
        self.assertRaises(TypeError,
                          stds.victor_purpura_distance,
                          [self.qarray1, self.qarray2],
                          self.q3,
                          algorithm='intuitive')
        self.assertRaises(TypeError,
                          stds.victor_purpura_distance,
                          [self.qarray1, self.qarray2],
                          5.0 * ms,
                          algorithm='intuitive')

        self.assertRaises(TypeError, stds.van_rossum_distance,
                          [self.array1, self.array2], self.tau3)
        self.assertRaises(TypeError, stds.van_rossum_distance,
                          [self.qarray1, self.qarray2], self.tau3)
        self.assertRaises(TypeError, stds.van_rossum_distance,
                          [self.qarray1, self.qarray2], 5.0 * Hz)

        self.assertRaises(TypeError, stds.victor_purpura_distance,
                          [self.st11, self.st13], self.tau2)
        self.assertRaises(TypeError, stds.victor_purpura_distance,
                          [self.st11, self.st13], 5.0)
        self.assertRaises(TypeError,
                          stds.victor_purpura_distance, [self.st11, self.st13],
                          self.tau2,
                          algorithm='intuitive')
        self.assertRaises(TypeError,
                          stds.victor_purpura_distance, [self.st11, self.st13],
                          5.0,
                          algorithm='intuitive')
        self.assertRaises(TypeError, stds.van_rossum_distance,
                          [self.st11, self.st13], self.q4)
        self.assertRaises(TypeError, stds.van_rossum_distance,
                          [self.st11, self.st13], 5.0)

        self.assertRaises(NotImplementedError,
                          stds.victor_purpura_distance, [self.st01, self.st02],
                          self.q3,
                          kernel=kernels.Kernel(2.0 / self.q3))
        self.assertRaises(NotImplementedError,
                          stds.victor_purpura_distance, [self.st01, self.st02],
                          self.q3,
                          kernel=kernels.SymmetricKernel(2.0 / self.q3))
        self.assertEqual(
            stds.victor_purpura_distance(
                [self.st01, self.st02],
                self.q1,
                kernel=kernels.TriangularKernel(
                    2.0 / (np.sqrt(6.0) * self.q2)))[0, 1],
            stds.victor_purpura_distance(
                [self.st01, self.st02],
                self.q3,
                kernel=kernels.TriangularKernel(
                    2.0 / (np.sqrt(6.0) * self.q2)))[0, 1])
        self.assertEqual(
            stds.victor_purpura_distance(
                [self.st01, self.st02],
                kernel=kernels.TriangularKernel(
                    2.0 / (np.sqrt(6.0) * self.q2)))[0, 1], 1.0)
        self.assertNotEqual(
            stds.victor_purpura_distance(
                [self.st01, self.st02],
                kernel=kernels.AlphaKernel(2.0 / (np.sqrt(6.0) * self.q2)))[0,
                                                                            1],
            1.0)

        self.assertRaises(NameError,
                          stds.victor_purpura_distance, [self.st11, self.st13],
                          self.q2,
                          algorithm='slow')