def test_fit(self): a = BagOfBonds() a.fit([METHANE]) expected_results = { ('C', 'H'): 4, ('H', 'H'): 6, } self.assertEqual(a._bag_sizes, expected_results)
def test_fit(self): a = BagOfBonds() a.fit([METHANE]) expected_results = ( (('C', 'H'), 4), (('H', 'H'), 6), ) self.assertEqual(a._bag_sizes, expected_results)
def test_get_labels(self): a = BagOfBonds() X = a.fit_transform([METHANE]) labels = a.get_labels() self.assertEqual(X.shape[1], len(labels)) expected = ( 'C-H_0', 'C-H_1', 'C-H_2', 'C-H_3', 'H-H_0', 'H-H_1', 'H-H_2', 'H-H_3', 'H-H_4', 'H-H_5', ) self.assertEqual(labels, expected)
def test_transform(self): a = BagOfBonds() a.fit([METHANE]) expected_results = numpy.array([[ 5.49462885, 5.49459021, 5.4945, 5.49031286, 0.56071947, 0.56071752, 0.56071656, 0.56064089, 0.56064037, 0.56063783 ]]) try: numpy.testing.assert_array_almost_equal(a.transform([METHANE]), expected_results) except AssertionError as e: self.fail(e)
def test_large_to_small_transform(self): a = BagOfBonds() a.fit([BIG]) expected_results = numpy.array([[0.0] * 300 + [ 5.494628848219048, 5.494590213211275, 5.494499999706413, 5.49031286145183 ] + [0.0] * 596 + [ 0.5607194714171738, 0.5607175240809282, 0.5607165613824526, 0.5606408892793993, 0.5606403708987712, 0.560637829974531 ] + [0.0] * 270]) try: numpy.testing.assert_array_almost_equal(a.transform([METHANE]), expected_results) except AssertionError as e: self.fail(e)
def test_fit_multi_mol(self): a = BagOfBonds() a.fit(ALL_DATA) expected_results = { ('H', 'O'): 60, ('C', 'H'): 375, ('H', 'N'): 75, ('C', 'C'): 300, ('H', 'H'): 105, ('O', 'O'): 6, ('C', 'N'): 125, ('N', 'O'): 20, ('C', 'O'): 100, ('N', 'N'): 10, } self.assertEqual(a._bag_sizes, expected_results)
def test_fit_multi_mol(self): a = BagOfBonds() a.fit(ALL_DATA) expected_results = ( (('C', 'C'), 300), (('C', 'H'), 375), (('C', 'N'), 125), (('C', 'O'), 100), (('H', 'H'), 105), (('H', 'N'), 75), (('H', 'O'), 60), (('N', 'N'), 10), (('N', 'O'), 20), (('O', 'O'), 6), ) self.assertEqual(a._bag_sizes, expected_results)
def test_transform_before_fit(self): a = BagOfBonds() with self.assertRaises(ValueError): a.transform(ALL_DATA)
def test_small_to_large_transform_drop_values(self): a = BagOfBonds(drop_values=True) a.fit([METHANE]) self.assertEqual(a.transform(ALL_DATA).shape, (3, 10))
def test_small_to_large_transform(self): a = BagOfBonds() a.fit([METHANE]) with self.assertRaises(ValueError): a.transform(ALL_DATA)