Exemplo n.º 1
0
 def test_get_labels(self):
     a = EncodedAngle(segments=2)
     X = a.fit_transform([METHANE])
     labels = a.get_labels()
     self.assertEqual(X.shape[1], len(labels))
     expected = (
         'C-H-C_0.0', 'C-H-C_3.14159',
         'C-H-H_0.0', 'C-H-H_3.14159',
         'H-C-H_0.0', 'H-C-H_3.14159',
         'H-H-H_0.0', 'H-H-H_3.14159',
     )
     self.assertEqual(labels, expected)
Exemplo n.º 2
0
 def test_fit_transform(self):
     a = EncodedAngle()
     # This is a cheap test to prevent needing all the values here
     expected_results = numpy.array([
         0.116708,  # mean
         0.450738,  # std
         0.,  # min
         3.043729,  # max
     ])
     try:
         m = a.fit_transform([METHANE])
         assert_close_statistics(m, expected_results)
     except AssertionError as e:
         self.fail(e)
Exemplo n.º 3
0
    def test_smoothing_function(self):
        a = EncodedAngle(smoothing="norm_cdf")

        # This is a cheap test to prevent needing all the values here
        expected_results = numpy.array([
            1.5891686,  # mean
            2.5907034,  # std
            0.,  # min
            9.8982443,  # max
        ])
        try:
            m = a.fit_transform([METHANE])
            assert_close_statistics(m, expected_results)
        except AssertionError as e:
            self.fail(e)
Exemplo n.º 4
0
 def test_small_to_large_transform(self):
     a = EncodedAngle()
     a.fit([METHANE])
     # This is a cheap test to prevent needing all the values here
     expected_results = numpy.array([
         0.018603,  # mean
         0.130329,  # std
         0.,  # min
         1.568823,  # max
     ])
     try:
         m = a.transform([MID])
         assert_close_statistics(m, expected_results)
     except AssertionError as e:
         self.fail(e)
Exemplo n.º 5
0
 def test_form(self):
     data = (
         #    mean         std   min     max
         (2, [0.155611, 0.581838, 0., 4.395692], 120),
         (1, [0.233417, 0.699744, 0., 4.395692], 80),
         (0, [4.668338e-001, 1.090704e+000, 0., 5.747656e+000], 40),
     )
     for form, expected, size in data:
         a = EncodedAngle(form=form)
         expected_results = numpy.array(expected)
         try:
             m = a.fit_transform([METHANE])
             self.assertEqual(m.shape, (1, size))
             assert_close_statistics(m, expected_results)
         except AssertionError as e:
             self.fail(e)
Exemplo n.º 6
0
    def test_add_unknown(self):
        a = EncodedAngle(add_unknown=True)
        a.fit([METHANE])

        # This is a cheap test to prevent needing all the values here
        expected_results = numpy.array([
            0.117057,  # mean
            0.510819,  # std
            0.,  # min
            6.343512,  # max
        ])
        try:
            m = a.transform([MID])
            self.assertEqual(m.shape, (1, 200))
            assert_close_statistics(m, expected_results)
        except AssertionError as e:
            self.fail(e)
Exemplo n.º 7
0
 def test_max_depth(self):
     a = EncodedAngle(max_depth=3)
     # This is a cheap test to prevent needing all the values here
     data = (
         #       mean          std     min      max
         (-1, [0.0325158765862, 0.132101907024, 0.0, 2.01566683797]),
         (1, [0.00491078348799, 0.0463273875823, 0.0, 0.694568644823]),
         (3, [0.0063668265711, 0.0513782485995, 0.0, 0.694568644823]),
     )
     for max_depth, expected in data:
         a = EncodedAngle(max_depth=max_depth)
         expected_results = numpy.array(expected)
         try:
             m = a.fit_transform([MID])
             assert_close_statistics(m, expected_results)
         except AssertionError as e:
             self.fail(e)
Exemplo n.º 8
0
 def test_fit(self):
     a = EncodedAngle()
     a.fit(ALL_DATA)
     expected = set([('C', 'N', 'C'), ('C', 'C', 'C'), ('H', 'H', 'H'),
                     ('H', 'O', 'O'), ('O', 'N', 'O'), ('H', 'N', 'N'),
                     ('C', 'H', 'H'), ('C', 'O', 'H'), ('C', 'H', 'C'),
                     ('N', 'C', 'N'), ('O', 'O', 'O'), ('H', 'O', 'N'),
                     ('H', 'N', 'O'), ('O', 'H', 'O'), ('H', 'H', 'N'),
                     ('C', 'C', 'N'), ('H', 'N', 'H'), ('C', 'H', 'N'),
                     ('H', 'C', 'O'), ('N', 'O', 'O'), ('N', 'N', 'N'),
                     ('C', 'C', 'H'), ('C', 'O', 'O'), ('C', 'N', 'N'),
                     ('H', 'O', 'H'), ('H', 'H', 'O'), ('C', 'C', 'O'),
                     ('N', 'H', 'N'), ('C', 'H', 'O'), ('O', 'C', 'O'),
                     ('H', 'C', 'N'), ('C', 'O', 'C'), ('N', 'O', 'N'),
                     ('N', 'N', 'O'), ('C', 'N', 'O'), ('C', 'O', 'N'),
                     ('H', 'C', 'H'), ('C', 'N', 'H'), ('N', 'H', 'O'),
                     ('N', 'C', 'O')])
     self.assertEqual(a._groups, expected)
Exemplo n.º 9
0
    def test_smoothing_function_error(self):
        a = EncodedAngle(smoothing="not valid")

        with self.assertRaises(KeyError):
            a.fit_transform([METHANE])
Exemplo n.º 10
0
 def test_transform_before_fit(self):
     a = EncodedAngle()
     with self.assertRaises(ValueError):
         a.transform(ALL_DATA)