Exemplo n.º 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())
Exemplo n.º 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())
Exemplo n.º 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))
Exemplo n.º 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'
         ]))
Exemplo n.º 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)
Exemplo n.º 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())
Exemplo n.º 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())
Exemplo n.º 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())
Exemplo n.º 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())
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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())
Exemplo n.º 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())
Exemplo n.º 16
0
 def test_transform(self):
     a = Shell()
     a.fit(ALL_DATA)
     self.assertTrue((a.transform(ALL_DATA) == BASE_SHELL).all())
Exemplo n.º 17
0
 def test_fit(self):
     a = Shell(depth=1)
     a.fit(ALL_DATA)
     self.assertEqual(a._elements, ('C', 'H', 'N', 'O'))
Exemplo n.º 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)
Exemplo n.º 19
0
 def test_get_labels(self):
     a = Shell()
     a.fit(ALL_DATA)
     expected = ('C', 'H', 'N', 'O')
     self.assertEqual(a.get_labels(), expected)
Exemplo n.º 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))
Exemplo n.º 21
0
 def test_transform_before_fit(self):
     a = Shell()
     with self.assertRaises(ValueError):
         a.transform(ALL_DATA)
Exemplo n.º 22
0
 def test_get_labels(self):
     a = Shell()
     a.fit(ALL_DATA)
     expected = ('C', 'H', 'N', 'O')
     self.assertEqual(a.get_labels(), expected)
Exemplo n.º 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())
Exemplo n.º 24
0
 def test_transform(self):
     a = Shell()
     a.fit(ALL_DATA)
     self.assertTrue((a.transform(ALL_DATA) == BASE_SHELL).all())
Exemplo n.º 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())
Exemplo n.º 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'))
Exemplo n.º 27
0
 def test_fit(self):
     a = Shell(depth=1)
     a.fit(ALL_DATA)
     self.assertEqual(a._elements, ('C', 'H', 'N', 'O'))
Exemplo n.º 28
0
 def test_large_to_small_transform(self):
     a = Shell()
     a.fit([BIG])
     self.assertTrue((a.transform(ALL_DATA) == BASE_SHELL).all())
Exemplo n.º 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)
Exemplo n.º 30
0
 def test_large_to_small_transform(self):
     a = Shell()
     a.fit([BIG])
     self.assertTrue((a.transform(ALL_DATA) == BASE_SHELL).all())
Exemplo n.º 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)
Exemplo n.º 32
0
 def test_transform_before_fit(self):
     a = Shell()
     with self.assertRaises(ValueError):
         a.transform(ALL_DATA)