Skip to content

Commit

Permalink
Merge pull request #942 from Matgenix/main
Browse files Browse the repository at this point in the history
Bug fixes in pseudo inverse computations
  • Loading branch information
ml-evs committed Aug 21, 2024
2 parents 761c99f + 6c46406 commit 8e99cf6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
6 changes: 5 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ repos:
rev: v1.5.1
hooks:
- id: mypy
additional_dependencies: [types-all]
additional_dependencies:
- types-setuptools
- types-paramiko
- types-requests
- types-ujson

# - repo: local
# hooks:
Expand Down
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
8 changes: 7 additions & 1 deletion matminer/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_elem_in_data(df, as_pure=False):
else:
for elem in Element:
for compound in df.index.to_list():
if elem.name in compound and elem.name not in elems_in_df:
if elem in Composition(compound) and elem.name not in elems_in_df:
elems_in_df.append(elem.name)

# Find the elements not in the data
Expand Down 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 8e99cf6

Please sign in to comment.