Ejemplo n.º 1
0
 def test_estimate_gaussian_from_supervectors_with_no_variance_at_all(self):
     svectors = [
         SuperVector([4, 4, 4]),
         SuperVector([4, 4, 4]),
         SuperVector([4, 4, 4]),
     ]
     with self.assertRaises(em.NoVarianceException):
         em.estimate_n_gaussians(svectors, 1, 20)
Ejemplo n.º 2
0
 def test_estimate_gaussian_from_supervectors_with_same_one_dimension(self):
     svectors = [
         SuperVector([4, 0, 3]),
         SuperVector([4, 2, 4]),
         SuperVector([4, 3, 4]),
         SuperVector([4, 1, 2]),
         SuperVector([4, 5, 1]),
     ]
     with self.assertRaises(em.NoVarianceException):
         em.estimate_n_gaussians(svectors, 1, 20)
Ejemplo n.º 3
0
    def test_correct_number_of_estimated_gaussians(self):
        svectors = [SuperVector([1, 3, 2, 4]), SuperVector([3, 5, 5, 3])]

        gaussians = em.estimate_n_gaussians(svectors, 1, 1)
        self.assertEqual(len(gaussians), 1,
                         "Invalid number of estimated gaussians!")

        gaussians = em.estimate_n_gaussians(svectors, 3, 1)
        self.assertEqual(len(gaussians), 3,
                         "Invalid number of estimated gaussians!")

        gaussians = em.estimate_n_gaussians(svectors, 18, 1)
        self.assertEqual(len(gaussians), 18,
                         "Invalid number of estimated gaussians!")
Ejemplo n.º 4
0
 def init_from_mfccphrase(cls, mfccphrase, em_gaussians, em_iterations):
     vectors = []
     for i in range(mfccphrase.count_mfccs()):
         vectors.append(SuperVector.init_from_mfcc(mfccphrase.get_mfcc(i)))
     gaussians = em.estimate_n_gaussians(vectors, em_gaussians,
                                         em_iterations)
     return Command(mfccphrase.get_name(), gaussians)
Ejemplo n.º 5
0
    def test_estimating_two_2d_gaussians(self):
        svectors = [
            SuperVector([0, 0]),
            SuperVector([0, 2]),
            SuperVector([2, 0]),
            SuperVector([2, 2]),
            SuperVector([5, 5]),
            SuperVector([5, 4]),
            SuperVector([5, 6]),
            SuperVector([4, 5]),
            SuperVector([6, 5]),
        ]
        gaussians = em.estimate_n_gaussians(svectors, 2, 40)

        expected_first_mean = np.array([1, 1], dtype=float)
        expected_second_mean = np.array([5, 5], dtype=float)

        expected_first_cov = np.array([1, 1], dtype=float)
        expected_second_cov = np.array([0.4, 0.4], dtype=float)

        expected_gaussians = [
            Gaussian(expected_first_mean, expected_first_cov),
            Gaussian(expected_second_mean, expected_second_cov)
        ]

        self.assertTrue(are_gaussians_equal(gaussians, expected_gaussians))
Ejemplo n.º 6
0
    def test_estimating_one_gaussian(self):
        svectors = [SuperVector([1, 3, 2]), SuperVector([3, 5, 1])]
        gaussians = em.estimate_n_gaussians(svectors, 1, 1)

        expected_mean = np.array([2, 4, 1.5], dtype=float)
        expected_cov = np.array([1, 1, 0.25], dtype=float)

        expected_gaussians = [Gaussian(expected_mean, expected_cov)]

        self.assertTrue(are_gaussians_equal(gaussians, expected_gaussians))
Ejemplo n.º 7
0
    def test_estimating_three_2d_gaussians(self):
        svectors = [
            SuperVector([0, 0]),
            SuperVector([0, 2]),
            SuperVector([2, 0]),
            SuperVector([2, 2]),
            SuperVector([7, 9]),
            SuperVector([9, 7]),
            SuperVector([7, 7]),
            SuperVector([9, 9]),
            SuperVector([5, 5]),
            SuperVector([5, 4]),
            SuperVector([5, 6]),
            SuperVector([4, 5]),
            SuperVector([6, 5]),
        ]
        gaussians = em.estimate_n_gaussians(svectors, 3, 13)

        expected_first_mean = np.array([1, 1], dtype=float)
        expected_second_mean = np.array([8, 8], dtype=float)
        expected_third_mean = np.array([5, 5], dtype=float)

        expected_first_cov = np.array([1, 1], dtype=float)
        expected_second_cov = np.array([1, 1], dtype=float)
        expected_third_cov = np.array([0.4, 0.4], dtype=float)

        expected_gaussians = [
            Gaussian(expected_first_mean, expected_first_cov),
            Gaussian(expected_second_mean, expected_second_cov),
            Gaussian(expected_third_mean, expected_third_cov)
        ]

        print("expected")
        print(expected_gaussians[0].get_mean())
        print(expected_gaussians[0].get_covariance())

        print("actual")
        print(gaussians[0].get_mean())
        print(gaussians[0].get_covariance())

        self.assertTrue(are_gaussians_equal(gaussians, expected_gaussians))
Ejemplo n.º 8
0
 def extract_gaussians(self, n_gaussians, iterations):
     """
     If limit is not none it will set to 0 each value which is lower than limit value.
     """
     return em.estimate_n_gaussians(self.__data, n_gaussians, iterations)
Ejemplo n.º 9
0
 def test_estimate_gaussian_from_single_supervector(self):
     svectors = [SuperVector([0, 0])]
     with self.assertRaises(em.NotEnoughSuperVectorsException):
         em.estimate_n_gaussians(svectors, 1, 20)
Ejemplo n.º 10
0
 def test_estimating_from_supervectors_with_different_amount_of_dimensions(
         self):
     svectors = [SuperVector([0, 0]), SuperVector([0, 2, 4])]
     with self.assertRaises(em.DifferentNumberOfDimensionsException):
         em.estimate_n_gaussians(svectors, 1, 20)
Ejemplo n.º 11
0
 def test_estimating_from_empty_supervectors(self):
     with self.assertRaises(em.NoSuperVectorsException):
         em.estimate_n_gaussians([], 1, 20)