예제 #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())
예제 #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())
예제 #3
0
파일: test_kernel.py 프로젝트: zizai/molml
 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))
예제 #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'
         ]))
예제 #5
0
파일: test_kernel.py 프로젝트: zizai/molml
 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)
예제 #6
0
파일: test_atom.py 프로젝트: zizai/molml
 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())
예제 #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())
예제 #8
0
파일: test_atom.py 프로젝트: zizai/molml
 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())
예제 #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())
예제 #10
0
파일: test_kernel.py 프로젝트: zizai/molml
 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)
예제 #11
0
파일: test_kernel.py 프로젝트: zizai/molml
 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)
예제 #12
0
파일: test_kernel.py 프로젝트: zizai/molml
 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)
예제 #13
0
파일: test_kernel.py 프로젝트: zizai/molml
 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)
예제 #14
0
파일: test_atom.py 프로젝트: zizai/molml
 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())
예제 #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())
예제 #16
0
파일: test_atom.py 프로젝트: zizai/molml
 def test_transform(self):
     a = Shell()
     a.fit(ALL_DATA)
     self.assertTrue((a.transform(ALL_DATA) == BASE_SHELL).all())
예제 #17
0
파일: test_atom.py 프로젝트: zizai/molml
 def test_fit(self):
     a = Shell(depth=1)
     a.fit(ALL_DATA)
     self.assertEqual(a._elements, ('C', 'H', 'N', 'O'))
예제 #18
0
파일: test_atom.py 프로젝트: zizai/molml
 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)
예제 #19
0
파일: test_atom.py 프로젝트: zizai/molml
 def test_get_labels(self):
     a = Shell()
     a.fit(ALL_DATA)
     expected = ('C', 'H', 'N', 'O')
     self.assertEqual(a.get_labels(), expected)
예제 #20
0
파일: test_kernel.py 프로젝트: zizai/molml
 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))
예제 #21
0
파일: test_atom.py 프로젝트: zizai/molml
 def test_transform_before_fit(self):
     a = Shell()
     with self.assertRaises(ValueError):
         a.transform(ALL_DATA)
예제 #22
0
 def test_get_labels(self):
     a = Shell()
     a.fit(ALL_DATA)
     expected = ('C', 'H', 'N', 'O')
     self.assertEqual(a.get_labels(), expected)
예제 #23
0
파일: test_atom.py 프로젝트: zizai/molml
 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())
예제 #24
0
 def test_transform(self):
     a = Shell()
     a.fit(ALL_DATA)
     self.assertTrue((a.transform(ALL_DATA) == BASE_SHELL).all())
예제 #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())
예제 #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'))
예제 #27
0
 def test_fit(self):
     a = Shell(depth=1)
     a.fit(ALL_DATA)
     self.assertEqual(a._elements, ('C', 'H', 'N', 'O'))
예제 #28
0
 def test_large_to_small_transform(self):
     a = Shell()
     a.fit([BIG])
     self.assertTrue((a.transform(ALL_DATA) == BASE_SHELL).all())
예제 #29
0
파일: test_kernel.py 프로젝트: zizai/molml
 def test_invalid_kernel(self):
     with self.assertRaises(ValueError):
         trans = Shell(input_type="filename")
         a = AtomKernel(kernel=1, transformer=trans)
         a.fit_transform(ALL)
예제 #30
0
파일: test_atom.py 프로젝트: zizai/molml
 def test_large_to_small_transform(self):
     a = Shell()
     a.fit([BIG])
     self.assertTrue((a.transform(ALL_DATA) == BASE_SHELL).all())
예제 #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)
예제 #32
0
 def test_transform_before_fit(self):
     a = Shell()
     with self.assertRaises(ValueError):
         a.transform(ALL_DATA)