Skip to content

Commit

Permalink
Bug fix in pseudo-inverse computation in the case of hydrogen.
Browse files Browse the repository at this point in the history
  • Loading branch information
gbrunin committed Aug 21, 2024
1 parent af57a94 commit 6c46406
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions matminer/featurizers/composition/tests/test_composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def test_elem_optical(self):
self.df_nans, col_id="composition"
)
self.assertEqual(df_elem.isna().sum().sum(), 0)
self.assertAlmostEqual(df_elem.drop(columns="composition").sum().sum(), 201.3255, 4)
self.assertAlmostEqual(df_elem.drop(columns="composition").sum().sum(), 204.4712, 4)

def test_elem_transport(self):
df_elem = ElementProperty.from_preset("mp_transport", impute_nan=False).featurize_dataframe(
Expand All @@ -343,7 +343,7 @@ def test_elem_transport(self):
df_elem = ElementProperty.from_preset("mp_transport", impute_nan=True).featurize_dataframe(
self.df_nans, col_id="composition"
)
self.assertAlmostEqual(df_elem.drop(columns="composition").sum().sum(), 9798095.622017656, 4)
self.assertAlmostEqual(df_elem.drop(columns="composition").sum().sum(), 10029874.1567, 4)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions matminer/utils/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def test_get_data(self):
c_k = self.data_source_imputed.get_elemental_property(elem="C", property_name="k_760.0")
self.assertAlmostEqual(c_k, 0.7462931865379264)
og_r = self.data_source_imputed.get_elemental_property(elem="Og", property_name="R_400.0")
self.assertAlmostEqual(og_r, 0.4624005395190695)
self.assertAlmostEqual(og_r, 0.46962554794905487)


class TestTransportData(TestCase):
Expand All @@ -308,7 +308,7 @@ def test_get_data(self):
cu_kappan = self.data_source_imputed.get_elemental_property(elem="Cu", property_name="kappa_n")
self.assertAlmostEqual(cu_kappan, 1814544.75663, places=5)
og_mn = self.data_source_imputed.get_elemental_property(elem="Og", property_name="m_n")
self.assertAlmostEqual(og_mn, 0.03237036761677134)
self.assertAlmostEqual(og_mn, 0.03293018092682478)


if __name__ == "__main__":
Expand Down
6 changes: 6 additions & 0 deletions matminer/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,11 @@ def get_pseudo_inverse(df_init, cols=None):
res_pi = np.vstack([res_pi, np.nan * np.ones([len(elems_not_in_df), len(df.T) - 1])])

df_pi = pd.DataFrame(res_pi, columns=cols, index=pd.Index(elems_in_df + elems_not_in_df))
# Handle the case of hydrogen, deuterium, and tritium
# If all are present, there contributions are summed
# and given to hydrogen only. Others are removed.
if all(e in df_pi.index for e in ["H", "D", "T"]):
df_pi.loc["H"] = df_pi.loc["H"] + df_pi.loc["D"] + df_pi.loc["T"]
df_pi.drop(index=["T", "D"], inplace=True)

return df_pi

0 comments on commit 6c46406

Please sign in to comment.