Exemplo n.º 1
0
    def test_from_data(self):
        es = ElementStats.from_data('megnet_1', stats=['moment:None:5'])
        d = es.transform_one('Fe2O3')
        self.assertTrue(d.shape == (1, 80))

        es = ElementStats.from_data(['megnet_1'], stats=['moment:None:5'])
        d = es.transform_one('Fe2O3')
        self.assertTrue(d.shape == (1, 80))

        es2 = ElementStats.from_data(['megnet_1', 'megnet_3'], stats=['moment:None:5'])
        d = es2.transform_one('Fe2O3')
        self.assertTrue(d.shape == (1, 160))
Exemplo n.º 2
0
    def test_from_data(self):
        es = ElementStats.from_data("megnet_1", stats=["moment:None:5"])
        d = es.transform_one("Fe2O3")
        self.assertTrue(d.shape == (1, 80))

        es = ElementStats.from_data(["megnet_1"], stats=["moment:None:5"])
        d = es.transform_one("Fe2O3")
        self.assertTrue(d.shape == (1, 80))

        es2 = ElementStats.from_data(["megnet_1", "megnet_3"],
                                     stats=["moment:None:5"])
        d = es2.transform_one("Fe2O3")
        self.assertTrue(d.shape == (1, 160))
Exemplo n.º 3
0
 def test_initialization(self):
     self.assertRaises(TypeError, ElementStats,
                       element_properties={"H": [1, 2], "O": [1, 2]}, stats=['mean'],
                       property_names=['p1', 'p2'],
                       some_random_variable='test',
                       )
     es = ElementStats(element_properties={"H": [1, 2], "O": [1, 2]}, stats=['mean'],
                       property_names=['p1', 'p2'],
                       n_jobs=-1)
     self.assertTrue(es.n_jobs > 0)
     res = es.transform(["H2O", "H2O", "H2O", "H2O"])
     self.assertTrue(res.shape[0] == 4)
     es.clear_cache()
Exemplo n.º 4
0
 def test_kpca(self):
     es2 = ElementStats.from_data(["megnet_1", "megnet_3"],
                                  stats=["moment:None:5"],
                                  num_dim=2,
                                  reduction_algo="kpca")
     d = es2.transform_one("Fe2O3")
     self.assertTrue(d.shape == (1, 10))
Exemplo n.º 5
0
class TestAtomSets(TestCase):

    x = ["H2O", "Fe2O3"]
    y = [0.1, 0.2]
    model = MLP(describer=ElementStats.from_data("megnet_3"), n_neurons=(2, 2))

    def test_train(self):
        self.model.train(self.x, self.y, epochs=0)
        self.assertTrue(self.model.predict_objs(["H2O"]).shape == (1, 1))
Exemplo n.º 6
0
    def test_element_stats(self):
        test = ElementStats({'H': [4, 2, 3],
                             'O': [2, 3, 4]},
                            stats=['min', 'max', 'moment:1:10'])
        self.assertEqual(test.transform(['H2O']).shape, (1, 36))

        res = test.transform(['H2O', 'H2O'])
        self.assertEqual(res.shape, (2, 36))

        res2 = test.transform([Composition('H2O'), Composition('H2O')])
        np.testing.assert_allclose(res.values, res2.values)

        dummy_h2o = Molecule(['H', 'H', 'O'], [[-0.5, 0, 0], [0.5, 0, 0], [0, 0, 0]])
        res3 = test.transform([dummy_h2o, dummy_h2o])
        np.testing.assert_allclose(res.values, res3.values)

        stats = ['min', 'max', *['moment:%d:None' % i for i in range(1, 11)]]
        p0_names = ['p0_%s' % i for i in stats]
        p1_names = ['p1_%s' % i for i in stats]
        p2_names = ['p2_%s' % i for i in stats]
        all_names = []
        for i, j, k in zip(p0_names, p1_names, p2_names):
            all_names.extend([i, j, k])

        self.assertListEqual(list(res.columns), all_names)
Exemplo n.º 7
0
    def test_element_stats(self):
        test = ElementStats({
            "H": [4, 2, 3],
            "O": [2, 3, 4]
        },
                            stats=["min", "max", "moment:1:10"])
        self.assertEqual(test.transform(["H2O"]).shape, (1, 36))

        res = test.transform(["H2O", "H2O"])
        self.assertEqual(res.shape, (2, 36))

        res2 = test.transform([Composition("H2O"), Composition("H2O")])
        np.testing.assert_allclose(res.values, res2.values)

        dummy_h2o = Molecule(["H", "H", "O"],
                             [[-0.5, 0, 0], [0.5, 0, 0], [0, 0, 0]])
        res3 = test.transform([dummy_h2o, dummy_h2o])
        np.testing.assert_allclose(res.values, res3.values)

        stats = ["min", "max", *["moment:%d:None" % i for i in range(1, 11)]]
        p0_names = ["p0_%s" % i for i in stats]
        p1_names = ["p1_%s" % i for i in stats]
        p2_names = ["p2_%s" % i for i in stats]
        all_names = []
        for i, j, k in zip(p0_names, p1_names, p2_names):
            all_names.extend([i, j, k])

        self.assertListEqual(list(res.columns), all_names)
Exemplo n.º 8
0
    def test_error(self):
        with self.assertRaises(ValueError):
            _ = ElementStats(element_properties={"H": [1, 2], "O": [1, 2, 3]}, stats=['mean'])

        with self.assertRaises(ValueError):
            _ = ElementStats(element_properties={"H": [1, 2], "O": [1, 2]}, stats=['mean'],
                             property_names=['p1'])

        with self.assertRaises(ValueError):
            _ = ElementStats(element_properties={"H": [1, 2], "O": [1, 2]}, stats=['super_std'],
                             property_names=['p1', 'p2'])

        with self.assertRaises(ValueError):
            _ = ElementStats(element_properties={"H": [1, 2], "O": [1, 2]}, stats=['super_std:-1'],
                             property_names=['p1', 'p2'])

        with self.assertRaises(ValueError):
            ElementStats.from_file(os.path.join(CWD, 'test_data/wrong_dummy_property.json'), stats=['max'])

        with self.assertRaises(ValueError):
            ElementStats.from_data('megnet_22', stats=['max'])
Exemplo n.º 9
0
    def test_error(self):
        with self.assertRaises(ValueError):
            _ = ElementStats(element_properties={
                "H": [1, 2],
                "O": [1, 2, 3]
            },
                             stats=["mean"])

        with self.assertRaises(ValueError):
            _ = ElementStats(element_properties={
                "H": [1, 2],
                "O": [1, 2]
            },
                             stats=["mean"],
                             property_names=["p1"])

        with self.assertRaises(ValueError):
            _ = ElementStats(element_properties={
                "H": [1, 2],
                "O": [1, 2]
            },
                             stats=["super_std"],
                             property_names=["p1", "p2"])

        with self.assertRaises(ValueError):
            _ = ElementStats(element_properties={
                "H": [1, 2],
                "O": [1, 2]
            },
                             stats=["super_std:-1"],
                             property_names=["p1", "p2"])

        with self.assertRaises(ValueError):
            ElementStats.from_file(os.path.join(
                CWD, "test_data/wrong_dummy_property.json"),
                                   stats=["max"])

        with self.assertRaises(ValueError):
            ElementStats.from_data("megnet_22", stats=["max"])
Exemplo n.º 10
0
 def test_keys(self):
     es = ElementStats.from_file(os.path.join(CWD, 'test_data/dummy_property.json'), stats=['max'])
     self.assertListEqual(es.stats, ['mean'])
Exemplo n.º 11
0
 def test_geometric_mean(self):
     es2 = ElementStats.from_data(['megnet_1', 'megnet_3'], stats=['shifted_geometric_mean:100'])
     d = es2.transform_one('Fe2O3')
     self.assertTrue(d.shape == (1, 32))
Exemplo n.º 12
0
 def test_pca(self):
     es2 = ElementStats.from_data(["megnet_1", "megnet_3"],
                                  stats=["moment:None:5"],
                                  num_dim=4)
     d = es2.transform_one("Fe2O3")
     self.assertTrue(d.shape == (1, 20))
Exemplo n.º 13
0
 def setUpClass(cls) -> None:
     cls.x = ['H2O', 'Fe2O3']
     cls.y = [0.1, 0.2]
     cls.model = MLP(describer=ElementStats.from_data("megnet_3"), n_neurons=(2, 2))
Exemplo n.º 14
0
 def test_geometric_mean(self):
     es2 = ElementStats.from_data(["megnet_1", "megnet_3"],
                                  stats=["shifted_geometric_mean:100"])
     d = es2.transform_one("Fe2O3")
     self.assertTrue(d.shape == (1, 32))
Exemplo n.º 15
0
 def test_pca(self):
     es2 = ElementStats.from_data(['megnet_1', 'megnet_3'], stats=['moment:None:5'], num_dim=4)
     d = es2.transform_one('Fe2O3')
     self.assertTrue(d.shape == (1, 20))
Exemplo n.º 16
0
 def test_kpca(self):
     es2 = ElementStats.from_data(['megnet_1', 'megnet_3'], stats=['moment:None:5'], num_dim=2,
                                  reduction_algo='kpca')
     d = es2.transform_one('Fe2O3')
     self.assertTrue(d.shape == (1, 10))
Exemplo n.º 17
0
 def test_keys(self):
     es = ElementStats.from_file(os.path.join(
         CWD, "test_data/dummy_property.json"),
                                 stats=["max"])
     self.assertListEqual(es.stats, ["mean"])