コード例 #1
0
    def test_output_transform(self):
        """Check output for extrinsic normalizer with exponential transform."""
        df = self.normalizer(exp=True, **self.kwargs).normalize(self.df.copy())

        self.assertEqual(len(df), len(self.df))

        for speaker in self.df['speaker'].unique():
            actual_df = df[df['speaker'] == speaker]
            expected_df = self.df[self.df['speaker'] == speaker]
            for formant in self.formants:
                mu_log = np.log(expected_df[self.formants]).mean(axis=0).mean()

                actual = actual_df[formant]
                expected = np.exp(np.log(expected_df[formant]) - mu_log)

                assert_series_equal(actual, expected)
コード例 #2
0
    def test_output(self):
        """Check output."""
        df = self.normalizer(**self.kwargs).normalize(self.df.copy())

        self.assertEqual(len(df), len(self.df))

        for speaker in self.df['speaker'].unique():
            actual_df = df[df['speaker'] == speaker]
            expected_df = self.df[self.df['speaker'] == speaker]
            for formant in self.formants:
                mu_log = np.log(expected_df[formant]).mean(axis=0)

                actual = actual_df[formant]
                expected = np.log(expected_df[formant]) - mu_log

                assert_series_equal(actual, expected)
コード例 #3
0
    def test_output(self):
        """Check output."""
        df = self.normalizer().normalize(self.df.copy(), **self.kwargs)

        self.assertEqual(len(df), len(self.df))

        for speaker in self.df['speaker'].unique():
            actual_df = df[df['speaker'] == speaker]
            expected_df = self.df[self.df['speaker'] == speaker]
            for formant in self.formants:
                fmin = expected_df[formant].min(axis=0)
                fmax = expected_df[formant].max(axis=0)

                actual = actual_df[formant]
                expected = 999 * (expected_df[formant] - fmin) / (fmax - fmin)

                assert_series_equal(actual, expected)
コード例 #4
0
    def test_output(self):
        """Check output."""
        df = self.normalizer().normalize(self.df.copy(), **self.kwargs)

        self.assertEqual(len(df), len(self.df))

        for speaker in self.df['speaker'].unique():
            actual_df = df[df['speaker'] == speaker]
            expected_df = self.df[self.df['speaker'] == speaker]
            for formant in self.formants:
                mu = expected_df[formant].mean()
                sigma = expected_df[formant].std() or 0.

                actual = actual_df[formant]
                expected = (expected_df[formant] - mu) / sigma if sigma else 0.

                assert_series_equal(actual, expected)
コード例 #5
0
    def test_get_centroid(self):
        """Test the get_centroid method."""
        df = DataFrame(dict(
            speaker=['s1', 's1'],
            vowel=['e', 'e'],
            f1=[100., 200.],
            f2=[400., 500.]
        ))
        actual = self.normalizer.get_centroid(
            df, dict(letter='e'), vowel='vowel', formants=['f1', 'f2'])

        expected = Series(
            dict(
                f1=(100. + 200.) / 2,
                f2=(400. + 500.) / 2),
            dtype=actual.dtype)

        assert_series_equal(actual, expected)
コード例 #6
0
    def test_get_centroid(self):
        """Test get_centroid method."""
        df = DataFrame(dict(
            speaker=['s1', 's1', 's1', 's1'],
            vowel=['fleece', 'fleece', 'trap', 'trap'],
            f1=[100., 200., 200., 300.],
            f2=[400., 500., 500., 600.]
        ))
        actual = self.normalizer.get_centroid(
            df, dict(fleece='fleece', trap='trap'),
            vowel='vowel', formants=['f1', 'f2'])

        expected = Series(
            dict(
                f1=(150. + 250. + 150.) / 3,
                f2=(450. + 550. + 150.) / 3),
            dtype=actual.dtype)

        assert_series_equal(actual, expected)