Example #1
0
 def test_get_labels_reduced(self):
     a = LocalCoulombMatrix(max_occupancy=1, use_reduced=True)
     X = a.fit_transform([METHANE])
     labels = a.get_labels()
     self.assertEqual(X.shape[2], len(labels))
     expected = ('local-coul_0-0', 'local-coul_0-1', 'local-coul_1-1')
     self.assertEqual(labels, expected)
Example #2
0
 def test_transform_alpha(self):
     a = LocalCoulombMatrix(max_occupancy=1, alpha=2., use_reduced=True)
     a.fit([METHANE, MID])
     m = a.transform([METHANE, MID])
     expected_results = numpy.array([
         [
             [36.8581052, 5.03182436, 0.5],
             [0.5, 5.0317536, 36.8581052],
             [0.5, 5.03182436, 36.8581052],
             [0.5, 5.03158837, 36.8581052],
             [0.5, 5.02392255, 36.8581052],
         ],
         [
             [36.8581052, 18.18762711, 36.8581052],
             [36.8581052, 24.62755378, 73.51669472],
             [73.51669472, 32.84431333, 73.51669472],
             [73.51669472, 32.84431333, 73.51669472],
             [73.51669472, 35.25529211, 73.51669472],
             [73.51669472, 35.25529211, 73.51669472],
             [0.5, 0.35524858, 0.5],
             [0.5, 1., 0.5],
             [0.5, 1., 0.5]
         ]
     ])
     try:
         mm = [numpy.linalg.norm(x) for x in (expected_results - m)]
         numpy.testing.assert_array_almost_equal(
             mm,
             [0.0, 0.0])
     except AssertionError as e:
         self.fail(e)
Example #3
0
 def test_get_labels_reduced(self):
     a = LocalCoulombMatrix(max_occupancy=1, use_reduced=True)
     X = a.fit_transform([METHANE])
     labels = a.get_labels()
     self.assertEqual(X.shape[2], len(labels))
     expected = ('local-coul_0-0', 'local-coul_0-1', 'local-coul_1-1')
     self.assertEqual(labels, expected)
Example #4
0
 def test_transform_reduced(self):
     a = LocalCoulombMatrix(max_occupancy=1, use_reduced=True)
     a.fit([METHANE, MID])
     m = a.transform([METHANE, MID])
     expected_results = numpy.array([
         [
             [36.8581052, 3.53894587, 0.5],
             [0.5, 3.53879657, 36.8581052],
             [0.5, 3.53894587, 36.8581052],
             [0.5, 3.53844797, 36.8581052],
             [0.5, 3.52229971, 36.8581052],
         ],
         [
             [36.85810519942594, 4.642192257970912, 36.85810519942594],
             [36.85810519942594, 6.483079598556282, 73.51669471981023],
             [73.51669471981023, 8.650089711338763, 73.51669471981023],
             [73.51669471981023, 8.650089711338763, 73.51669471981023],
             [73.51669471981023, 10.698256448660478, 73.51669471981023],
             [73.51669471981023, 10.698256448660478, 73.51669471981023],
             [0.5, 0.04483292, 0.5],
             [0.5, 1., 0.5],
             [0.5, 1., 0.5]
         ]
     ])
     try:
         mm = [numpy.linalg.norm(x) for x in (expected_results - m)]
         numpy.testing.assert_array_almost_equal(
             mm,
             [0.0, 0.0])
     except AssertionError as e:
         self.fail(e)
Example #5
0
 def test_transform_alpha(self):
     a = LocalCoulombMatrix(max_occupancy=1, alpha=2., use_reduced=True)
     a.fit([METHANE, MID])
     m = a.transform([METHANE, MID])
     expected_results = numpy.array([
         [
             [37.3581052, 5.53182436],
             [37.3581052, 41.8898588],
             [37.3581052, 41.88992956],
             [37.3581052, 41.88969357],
             [37.3581052, 41.88202775]
         ],
         [
             [73.7162104, 55.04573231],
             [110.37479992, 98.1442485],
             [147.03338944, 106.36100805],
             [147.03338944, 106.36100805],
             [147.03338944, 108.77198683],
             [147.03338944, 108.77198683],
             [1., 0.85524858],
             [1., 1.5],
             [1., 1.5]
         ]])
     try:
         mm = [numpy.linalg.norm(x) for x in (expected_results - m)]
         numpy.testing.assert_array_almost_equal(
             mm,
             [0.0, 0.0])
     except AssertionError as e:
         self.fail(e)
Example #6
0
    def test_transform_reduced(self):
        a = LocalCoulombMatrix(max_occupancy=1, use_reduced=True)
        a.fit([METHANE, MID])
        m = a.transform([METHANE, MID])
        expected_results = numpy.array([
            [
                [37.3581052, 4.03894587],
                [37.3581052, 40.39690177],
                [37.3581052, 40.39705107],
                [37.3581052, 40.39655317],
                [37.3581052, 40.38040491]
            ],
            [
                [73.7162104, 41.50029746],
                [110.37479992, 79.99977432],
                [147.03338944, 82.16678443],
                [147.03338944, 82.16678443],
                [147.03338944, 84.21495117],
                [147.03338944, 84.21495117],
                [1., 0.54483292],
                [1., 1.5],
                [1., 1.5]
            ]])

        try:
            mm = [numpy.linalg.norm(x) for x in (expected_results - m)]
            numpy.testing.assert_array_almost_equal(
                mm,
                [0.0, 0.0])
        except AssertionError as e:
            self.fail(e)
Example #7
0
 def test_fit_transform(self):
     a = LocalCoulombMatrix(max_occupancy=1)
     m = a.fit_transform([METHANE, MID])
     try:
         mm = [numpy.linalg.norm(x) for x in (BASE_LOCAL_COULOMB - m)]
         numpy.testing.assert_array_almost_equal(mm, [0.0, 0.0])
     except AssertionError as e:
         self.fail(e)
Example #8
0
 def test_fit_transform(self):
     a = LocalCoulombMatrix(max_occupancy=1)
     m = a.fit_transform([METHANE, MID])
     try:
         mm = [numpy.linalg.norm(x) for x in (BASE_LOCAL_COULOMB - m)]
         numpy.testing.assert_array_almost_equal(
             mm,
             [0.0, 0.0])
     except AssertionError as e:
         self.fail(e)
Example #9
0
    def test_transform_max_occupancy(self):
        a = LocalCoulombMatrix(max_occupancy=5)
        a.fit([METHANE, MID])
        m = a.transform([METHANE, MID])
        # Reduce to a sum to save space
        expected_results = [337.53938456166259, 3019.413939202841]

        try:
            numpy.testing.assert_array_almost_equal([x.sum() for x in m],
                                                    expected_results)
        except AssertionError as e:
            self.fail(e)
Example #10
0
    def test_transform_max_occupancy(self):
        a = LocalCoulombMatrix(max_occupancy=5)
        a.fit([METHANE, MID])
        m = a.transform([METHANE, MID])
        # Reduce to a sum to save space
        expected_results = [337.53938456166259, 3019.413939202841]

        try:
            numpy.testing.assert_array_almost_equal(
                [x.sum() for x in m],
                expected_results)
        except AssertionError as e:
            self.fail(e)
Example #11
0
 def test_transform_alpha(self):
     a = LocalCoulombMatrix(max_occupancy=1, alpha=2., use_reduced=True)
     a.fit([METHANE, MID])
     m = a.transform([METHANE, MID])
     expected_results = numpy.array(
         [[
             [36.8581052, 5.03182436, 0.5],
             [0.5, 5.0317536, 36.8581052],
             [0.5, 5.03182436, 36.8581052],
             [0.5, 5.03158837, 36.8581052],
             [0.5, 5.02392255, 36.8581052],
         ],
          [[36.8581052, 18.18762711, 36.8581052],
           [36.8581052, 24.62755378, 73.51669472],
           [73.51669472, 32.84431333, 73.51669472],
           [73.51669472, 32.84431333, 73.51669472],
           [73.51669472, 35.25529211, 73.51669472],
           [73.51669472, 35.25529211, 73.51669472], [0.5, 0.35524858, 0.5],
           [0.5, 1., 0.5], [0.5, 1., 0.5]]])
     try:
         mm = [numpy.linalg.norm(x) for x in (expected_results - m)]
         numpy.testing.assert_array_almost_equal(mm, [0.0, 0.0])
     except AssertionError as e:
         self.fail(e)
Example #12
0
 def test_transform_reduced(self):
     a = LocalCoulombMatrix(max_occupancy=1, use_reduced=True)
     a.fit([METHANE, MID])
     m = a.transform([METHANE, MID])
     expected_results = numpy.array(
         [[
             [36.8581052, 3.53894587, 0.5],
             [0.5, 3.53879657, 36.8581052],
             [0.5, 3.53894587, 36.8581052],
             [0.5, 3.53844797, 36.8581052],
             [0.5, 3.52229971, 36.8581052],
         ],
          [[36.85810519942594, 4.642192257970912, 36.85810519942594],
           [36.85810519942594, 6.483079598556282, 73.51669471981023],
           [73.51669471981023, 8.650089711338763, 73.51669471981023],
           [73.51669471981023, 8.650089711338763, 73.51669471981023],
           [73.51669471981023, 10.698256448660478, 73.51669471981023],
           [73.51669471981023, 10.698256448660478, 73.51669471981023],
           [0.5, 0.04483292, 0.5], [0.5, 1., 0.5], [0.5, 1., 0.5]]])
     try:
         mm = [numpy.linalg.norm(x) for x in (expected_results - m)]
         numpy.testing.assert_array_almost_equal(mm, [0.0, 0.0])
     except AssertionError as e:
         self.fail(e)
Example #13
0
 def test_transform_before_fit(self):
     a = LocalCoulombMatrix(max_occupancy=1)
     # This should not raise an error, becaues no fitting is needed
     a.transform(ALL_DATA)
Example #14
0
 def test_fit(self):
     a = LocalCoulombMatrix()
     # This should not do anything
     a.fit(ALL_DATA)
Example #15
0
 def test_transform_before_fit(self):
     a = LocalCoulombMatrix(max_occupancy=1)
     # This should not raise an error, becaues no fitting is needed
     a.transform(ALL_DATA)
Example #16
0
 def test_fit(self):
     a = LocalCoulombMatrix()
     # This should not do anything
     a.fit(ALL_DATA)