Beispiel #1
0
 def test_transform_depth3(self):
     # This is to test loop backs in the breadth-first search
     a = Shell(depth=3)
     a.fit(ALL_DATA)
     expected_results = numpy.array([
         [[0, 0, 0, 0], [0, 3, 0, 0], [0, 3, 0, 0], [0, 3, 0, 0],
          [0, 3, 0, 0]],
         [[0, 0, 0, 1], [0, 0, 0, 0], [1, 0, 0, 0], [0, 0, 0, 0],
          [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0],
          [0, 0, 0, 0]],
         [[2, 2, 0, 0], [1, 1, 1, 1], [2, 2, 0, 0], [2, 1, 1, 0],
          [4, 1, 0, 0], [3, 0, 0, 1], [2, 0, 0, 0], [2, 0, 0, 0],
          [1, 0, 1, 0], [1, 0, 0, 0], [2, 0, 0, 0], [3, 1, 0, 0],
          [2, 1, 2, 1], [3, 0, 0, 1], [3, 1, 1, 0], [3, 0, 0, 2],
          [3, 0, 0, 1], [2, 0, 0, 0], [1, 0, 1, 0], [1, 0, 0, 0],
          [2, 3, 0, 0], [1, 0, 0, 0], [0, 2, 0, 1], [0, 2, 0, 1],
          [0, 2, 0, 1], [4, 0, 1, 0], [4, 0, 0, 1], [3, 0, 1, 1],
          [5, 0, 0, 0], [4, 0, 0, 0], [2, 1, 0, 0], [1, 0, 0, 0],
          [1, 0, 0, 0], [1, 0, 0, 0], [2, 0, 0, 0], [3, 2, 0, 0],
          [2, 1, 2, 1], [4, 0, 0, 0], [2, 2, 1, 0], [3, 0, 0, 0],
          [2, 1, 1, 0], [2, 0, 0, 0], [1, 0, 1, 0], [1, 0, 1, 0],
          [1, 1, 0, 0], [1, 1, 0, 0], [2, 1, 0, 0], [1, 0, 0, 0],
          [1, 0, 0, 0]]
     ])
     self.assertTrue((a.transform(ALL_DATA) == expected_results).all())
Beispiel #2
0
 def test_transform_depth3(self):
     # This is to test loop backs in the breadth-first search
     a = Shell(depth=3)
     a.fit(ALL_DATA)
     expected_results = numpy.array([
         [[0, 0, 0, 0], [0, 3, 0, 0], [0, 3, 0, 0], [0, 3, 0, 0],
          [0, 3, 0, 0]],
         [[0, 0, 0, 1], [0, 0, 0, 0], [1, 0, 0, 0], [0, 0, 0, 0],
          [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0],
          [0, 0, 0, 0]],
         [[2, 2, 0, 0], [1, 1, 1, 1], [2, 2, 0, 0], [2, 1, 1, 0],
          [4, 1, 0, 0], [3, 0, 0, 1], [2, 0, 0, 0], [2, 0, 0, 0],
          [1, 0, 1, 0], [1, 0, 0, 0], [2, 0, 0, 0], [3, 1, 0, 0],
          [2, 1, 2, 1], [3, 0, 0, 1], [3, 1, 1, 0], [3, 0, 0, 2],
          [3, 0, 0, 1], [2, 0, 0, 0], [1, 0, 1, 0], [1, 0, 0, 0],
          [2, 3, 0, 0], [1, 0, 0, 0], [0, 2, 0, 1], [0, 2, 0, 1],
          [0, 2, 0, 1], [4, 0, 1, 0], [4, 0, 0, 1], [3, 0, 1, 1],
          [5, 0, 0, 0], [4, 0, 0, 0], [2, 1, 0, 0], [1, 0, 0, 0],
          [1, 0, 0, 0], [1, 0, 0, 0], [2, 0, 0, 0], [3, 2, 0, 0],
          [2, 1, 2, 1], [4, 0, 0, 0], [2, 2, 1, 0], [3, 0, 0, 0],
          [2, 1, 1, 0], [2, 0, 0, 0], [1, 0, 1, 0], [1, 0, 1, 0],
          [1, 1, 0, 0], [1, 1, 0, 0], [2, 1, 0, 0], [1, 0, 0, 0],
          [1, 0, 0, 0]]
     ])
     self.assertTrue((a.transform(ALL_DATA) == expected_results).all())
Beispiel #3
0
 def test_fit_features(self):
     trans = Shell(input_type="filename")
     feats = trans.fit_transform(ALL)
     a = AtomKernel()
     values = list(zip(feats, ALL_NUMS))
     a.fit(values)
     self.assertEqual(ALL_NUMS, list(a._numbers))
     self.assertEqual(list(ALL_FEATURES), list(a._features))
Beispiel #4
0
 def test_fit_use_coordination(self):
     a = Shell(depth=1, use_coordination=True)
     a.fit(ALL_DATA)
     self.assertEqual(
         a._elements,
         set([
             'H0', 'H1', 'O2', 'C4', 'N1', 'C3', 'C2', 'N2', 'N3', 'C1',
             'O1', 'O0'
         ]))
Beispiel #5
0
 def test_fit_transform_features(self):
     trans = Shell(input_type="filename")
     feats = trans.fit_transform(ALL)
     a = AtomKernel()
     values = list(zip(feats, ALL_NUMS))
     res = a.fit_transform(values)
     try:
         numpy.testing.assert_array_almost_equal(RBF_KERNEL, res)
     except AssertionError as e:
         self.fail(e)
Beispiel #6
0
 def test_add_unknown(self):
     a = Shell(add_unknown=True)
     a.fit([METHANE])
     temp = []
     for mol in BASE_SHELL:
         inner = []
         for atom in mol:
             inner.append(atom[:2] + [atom[2] + atom[3]])
         temp.append(inner)
     expected = numpy.array(temp)
     self.assertTrue((a.transform(ALL_DATA) == expected).all())
Beispiel #7
0
 def test_add_unknown(self):
     a = Shell(add_unknown=True)
     a.fit([METHANE])
     temp = []
     for mol in BASE_SHELL:
         inner = []
         for atom in mol:
             inner.append(atom[:2] + [atom[2] + atom[3]])
         temp.append(inner)
     expected = numpy.array(temp)
     self.assertTrue((a.transform(ALL_DATA) == expected).all())
Beispiel #8
0
 def test_transform_use_coordination(self):
     a = Shell(depth=1, use_coordination=True)
     a.fit([MID])
     expected_results = numpy.array([[[1, 0, 0, 0, 0,
                                       0], [0, 1, 0, 0, 0, 0],
                                      [0, 0, 0, 0, 0,
                                       1], [0, 0, 0, 0, 1, 0],
                                      [0, 0, 0, 0, 0,
                                       1], [0, 0, 0, 0, 0, 1],
                                      [0, 0, 1, 0, 0,
                                       0], [0, 0, 0, 1, 0, 0],
                                      [0, 0, 0, 1, 0, 0]]])
     self.assertTrue((a.transform([MID]) == expected_results).all())
Beispiel #9
0
 def test_transform_use_coordination(self):
     a = Shell(depth=1, use_coordination=True)
     a.fit([MID])
     expected_results = numpy.array([
         [[1, 0, 0, 0, 0, 0],
          [0, 1, 0, 0, 0, 0],
          [0, 0, 0, 0, 0, 1],
          [0, 0, 0, 0, 1, 0],
          [0, 0, 0, 0, 0, 1],
          [0, 0, 0, 0, 0, 1],
          [0, 0, 1, 0, 0, 0],
          [0, 0, 0, 1, 0, 0],
          [0, 0, 0, 1, 0, 0]]
     ])
     self.assertTrue((a.transform([MID]) == expected_results).all())
Beispiel #10
0
 def test_fit_transform_transformer(self):
     trans = Shell(input_type="filename")
     a = AtomKernel(transformer=trans)
     res = a.fit_transform(ALL)
     try:
         numpy.testing.assert_array_almost_equal(RBF_KERNEL, res)
     except AssertionError as e:
         self.fail(e)
Beispiel #11
0
 def test_laplace_kernel(self):
     # Set depth=2 so the comparison is not trivial
     trans = Shell(input_type="filename", depth=2)
     a = AtomKernel(transformer=trans, kernel="laplace", gamma=1.)
     a.fit(ALL)
     res = a.transform(ALL)
     try:
         numpy.testing.assert_array_almost_equal(LAPLACE_KERNEL, res)
     except AssertionError as e:
         self.fail(e)
Beispiel #12
0
 def test_same_element(self):
     # Set depth=2 so the comparison is not trivial
     trans = Shell(input_type="filename", depth=2)
     # Set gamma=1 to make the differences more noticeable
     a = AtomKernel(transformer=trans, same_element=False, gamma=1.)
     res = a.fit_transform(ALL)
     expected = numpy.array([[17.00000033, 14.58016505],
                             [14.58016505, 32.76067832]])
     try:
         numpy.testing.assert_array_almost_equal(expected, res)
     except AssertionError as e:
         self.fail(e)
Beispiel #13
0
 def test_custom_kernel(self):
     # Set depth=2 so the comparison is not trivial
     trans = Shell(input_type="filename", depth=2)
     # Simple linear kernel
     a = AtomKernel(transformer=trans,
                    kernel=lambda x, y: numpy.dot(x, numpy.transpose(y)))
     a.fit(ALL)
     res = a.transform(ALL)
     try:
         numpy.testing.assert_array_almost_equal(LINEAR_KERNEL, res)
     except AssertionError as e:
         self.fail(e)
Beispiel #14
0
 def test_transform_depth2(self):
     a = Shell(depth=2)
     a.fit(ALL_DATA)
     expected_results = numpy.array([[[0, 4, 0, 0], [1, 0, 0, 0],
                                      [1, 0, 0, 0], [1, 0, 0, 0],
                                      [1, 0, 0, 0]],
                                     [[1, 0, 0, 0], [1, 0, 0, 1],
                                      [1, 0, 0, 0], [0, 0, 0, 0],
                                      [0, 0, 0, 1], [0, 0, 0, 1],
                                      [0, 0, 0, 0], [0, 1, 0, 0],
                                      [0, 1, 0, 0]],
                                     [[1, 0, 1, 1], [2, 1, 0, 0],
                                      [2, 1, 0, 0], [2, 1, 0, 0],
                                      [2, 0, 1, 0], [2, 0, 0, 0],
                                      [1, 0, 0, 0], [1, 0, 0, 0],
                                      [1, 1, 0, 0], [0, 0, 0, 1],
                                      [1, 0, 0, 0], [1, 0, 1, 1],
                                      [3, 0, 0, 0], [2, 1, 0, 0],
                                      [2, 0, 0, 1], [2, 0, 1, 0],
                                      [2, 0, 0, 0], [1, 0, 0, 0],
                                      [1, 1, 0, 0], [0, 0, 0, 1],
                                      [2, 0, 0, 0], [0, 3, 0, 1],
                                      [1, 0, 0, 0], [1, 0, 0, 0],
                                      [1, 0, 0, 0], [2, 0, 0, 1],
                                      [3, 0, 0, 0], [3, 0, 0, 0],
                                      [2, 0, 0, 1], [2, 0, 0, 0],
                                      [2, 0, 0, 0], [1, 1, 0, 0],
                                      [1, 0, 0, 0], [1, 0, 0, 0],
                                      [1, 0, 1, 0], [1, 0, 2, 0],
                                      [3, 0, 0, 0], [2, 1, 0, 0],
                                      [3, 0, 0, 0], [1, 1, 1, 0],
                                      [2, 0, 0, 0], [1, 0, 0, 0],
                                      [1, 0, 0, 0], [1, 2, 0, 0],
                                      [0, 0, 1, 0], [0, 0, 1, 0],
                                      [2, 0, 0, 0], [1, 1, 0, 0],
                                      [1, 0, 0, 0]]])
     self.assertTrue((a.transform(ALL_DATA) == expected_results).all())
Beispiel #15
0
 def test_transform_depth2(self):
     a = Shell(depth=2)
     a.fit(ALL_DATA)
     expected_results = numpy.array([
         [[0, 4, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0],
          [1, 0, 0, 0]],
         [[1, 0, 0, 0], [1, 0, 0, 1], [1, 0, 0, 0], [0, 0, 0, 0],
          [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 0], [0, 1, 0, 0],
          [0, 1, 0, 0]],
         [[1, 0, 1, 1], [2, 1, 0, 0], [2, 1, 0, 0], [2, 1, 0, 0],
          [2, 0, 1, 0], [2, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0],
          [1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [1, 0, 1, 1],
          [3, 0, 0, 0], [2, 1, 0, 0], [2, 0, 0, 1], [2, 0, 1, 0],
          [2, 0, 0, 0], [1, 0, 0, 0], [1, 1, 0, 0], [0, 0, 0, 1],
          [2, 0, 0, 0], [0, 3, 0, 1], [1, 0, 0, 0], [1, 0, 0, 0],
          [1, 0, 0, 0], [2, 0, 0, 1], [3, 0, 0, 0], [3, 0, 0, 0],
          [2, 0, 0, 1], [2, 0, 0, 0], [2, 0, 0, 0], [1, 1, 0, 0],
          [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 1, 0], [1, 0, 2, 0],
          [3, 0, 0, 0], [2, 1, 0, 0], [3, 0, 0, 0], [1, 1, 1, 0],
          [2, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 2, 0, 0],
          [0, 0, 1, 0], [0, 0, 1, 0], [2, 0, 0, 0], [1, 1, 0, 0],
          [1, 0, 0, 0]]
     ])
     self.assertTrue((a.transform(ALL_DATA) == expected_results).all())
Beispiel #16
0
 def test_transform(self):
     a = Shell()
     a.fit(ALL_DATA)
     self.assertTrue((a.transform(ALL_DATA) == BASE_SHELL).all())
Beispiel #17
0
 def test_fit(self):
     a = Shell(depth=1)
     a.fit(ALL_DATA)
     self.assertEqual(a._elements, ('C', 'H', 'N', 'O'))
Beispiel #18
0
 def test_get_labels_unknown(self):
     a = Shell(add_unknown=True)
     a.fit(ALL_DATA)
     expected = ('C', 'H', 'N', 'O', UNKNOWN)
     self.assertEqual(a.get_labels(), expected)
Beispiel #19
0
 def test_get_labels(self):
     a = Shell()
     a.fit(ALL_DATA)
     expected = ('C', 'H', 'N', 'O')
     self.assertEqual(a.get_labels(), expected)
Beispiel #20
0
 def test_fit_transformer(self):
     trans = Shell(input_type="filename")
     a = AtomKernel(transformer=trans)
     a.fit(ALL)
     self.assertEqual(ALL_NUMS, [x.tolist() for x in a._numbers])
     self.assertEqual(list(ALL_FEATURES), list(a._features))
Beispiel #21
0
 def test_transform_before_fit(self):
     a = Shell()
     with self.assertRaises(ValueError):
         a.transform(ALL_DATA)
Beispiel #22
0
 def test_get_labels(self):
     a = Shell()
     a.fit(ALL_DATA)
     expected = ('C', 'H', 'N', 'O')
     self.assertEqual(a.get_labels(), expected)
Beispiel #23
0
 def test_small_to_large_transform(self):
     a = Shell()
     a.fit([METHANE])
     expected = numpy.array(
         [numpy.array(x)[:, :2].tolist() for x in BASE_SHELL])
     self.assertTrue((a.transform(ALL_DATA) == expected).all())
Beispiel #24
0
 def test_transform(self):
     a = Shell()
     a.fit(ALL_DATA)
     self.assertTrue((a.transform(ALL_DATA) == BASE_SHELL).all())
Beispiel #25
0
 def test_small_to_large_transform(self):
     a = Shell()
     a.fit([METHANE])
     expected = numpy.array([numpy.array(x)[:, :2].tolist()
                             for x in BASE_SHELL])
     self.assertTrue((a.transform(ALL_DATA) == expected).all())
Beispiel #26
0
 def test_fit_use_coordination(self):
     a = Shell(depth=1, use_coordination=True)
     a.fit(ALL_DATA)
     self.assertEqual(a._elements, ('C1', 'C2', 'C3', 'C4', 'H0', 'H1',
                                    'N1', 'N2', 'N3', 'O0', 'O1', 'O2'))
Beispiel #27
0
 def test_fit(self):
     a = Shell(depth=1)
     a.fit(ALL_DATA)
     self.assertEqual(a._elements, ('C', 'H', 'N', 'O'))
Beispiel #28
0
 def test_large_to_small_transform(self):
     a = Shell()
     a.fit([BIG])
     self.assertTrue((a.transform(ALL_DATA) == BASE_SHELL).all())
Beispiel #29
0
 def test_invalid_kernel(self):
     with self.assertRaises(ValueError):
         trans = Shell(input_type="filename")
         a = AtomKernel(kernel=1, transformer=trans)
         a.fit_transform(ALL)
Beispiel #30
0
 def test_large_to_small_transform(self):
     a = Shell()
     a.fit([BIG])
     self.assertTrue((a.transform(ALL_DATA) == BASE_SHELL).all())
Beispiel #31
0
 def test_get_labels_unknown(self):
     a = Shell(add_unknown=True)
     a.fit(ALL_DATA)
     expected = ('C', 'H', 'N', 'O', 'UNKNOWN')
     self.assertEqual(a.get_labels(), expected)
Beispiel #32
0
 def test_transform_before_fit(self):
     a = Shell()
     with self.assertRaises(ValueError):
         a.transform(ALL_DATA)