Skip to content

Commit 0ea86cb

Browse files
authored
Merge pull request #29 from chiuhoward/fix-pytorch
[FIX] Remove deprecated verbose flag from ReduceLROnPlateau in tests
2 parents c7cd7fd + eb5ab71 commit 0ea86cb

4 files changed

Lines changed: 28 additions & 23 deletions

File tree

afqinsight/match.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import pandas as pd
55
from scipy.optimize import linear_sum_assignment
66

7-
__all__ = ["mahalonobis_dist_match"]
7+
__all__ = ["mahalanobis_dist_match"]
88

99

10-
def mahalonobis_dist_match(
10+
def mahalanobis_dist_match(
1111
data=None, test=None, ctrl=None, status_col=None, feature_cols=None, threshold=0.2
1212
):
1313
"""
@@ -77,12 +77,12 @@ def mahalonobis_dist_match(
7777
(
7878
"There are NaNs in test or ctrl data. "
7979
"Please replace these NaNs using interpolation or by removing "
80-
"the subjects with NaNs before calling mahalonobis_dist_match. "
80+
"the subjects with NaNs before calling mahalanobis_dist_match. "
8181
)
8282
)
8383

84-
# calculate Mahalonobis distance between test and control
85-
nbrs = _mahalonobis_dist(test, ctrl)
84+
# calculate Mahalanobis distance between test and control
85+
nbrs = _mahalanobis_dist(test, ctrl)
8686

8787
# assign neighbors using Munkres algorithm
8888
row_ind, col_ind = linear_sum_assignment(nbrs)
@@ -118,9 +118,9 @@ def mahalonobis_dist_match(
118118
return data.iloc[all_idx]
119119

120120

121-
def _mahalonobis_dist(arr1, arr2):
121+
def _mahalanobis_dist(arr1, arr2):
122122
"""
123-
Calculate the Mahalonobis distance between two 2d arrays along the first axis.
123+
Calculate the Mahalanobis distance between two 2d arrays along the first axis.
124124
125125
Parameters
126126
----------
@@ -132,7 +132,7 @@ def _mahalonobis_dist(arr1, arr2):
132132
Returns
133133
-------
134134
nbrs : array-like of shape (n_samples1, n_samples2)
135-
Mahalonobis distance between each sample in the
135+
Mahalanobis distance between each sample in the
136136
two input arrays.
137137
"""
138138
v_inv = np.linalg.inv(np.cov(np.concatenate((arr1, arr2), axis=0).T, ddof=0))

afqinsight/nn/tests/test_pt_models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ def run_pytorch_model(
8181
optimizer = torch.optim.Adam(model.parameters(), lr=0.0001)
8282
criterion = torch.nn.MSELoss()
8383
scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(
84-
optimizer, mode="min", factor=0.5, patience=20, verbose=True
84+
optimizer,
85+
mode="min",
86+
factor=0.5,
87+
patience=20,
8588
)
8689

8790
for epoch in range(n_epochs):

afqinsight/nn/tests/test_tf_models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ def run_tensorflow_model(model, data_loaders, n_epochs=20):
8686
)
8787

8888
reduce_lr = tf.keras.callbacks.ReduceLROnPlateau(
89-
monitor="val_loss", factor=0.5, patience=20, verbose=1
89+
monitor="val_loss",
90+
factor=0.5,
91+
patience=20,
9092
)
9193

9294
callbacks = [early_stopping, ckpt, reduce_lr]

afqinsight/tests/test_match.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
data[f"feature_{ii}"] = [*test_features[:, ii], *ctrl_features[:, ii]]
3535

3636

37-
def test_mahalonobis_dist():
38-
nbrs = aim._mahalonobis_dist(test_features, ctrl_features)
37+
def test_mahalanobis_dist():
38+
nbrs = aim._mahalanobis_dist(test_features, ctrl_features)
3939

4040
v_inv = np.linalg.inv(
4141
np.cov(np.concatenate((test_features, ctrl_features), axis=0).T, ddof=0)
@@ -48,8 +48,8 @@ def test_mahalonobis_dist():
4848
assert_array_almost_equal(nbrs, nbrs_scipy)
4949

5050

51-
def test_mahalonobis_dist_match_df():
52-
matched_df = aim.mahalonobis_dist_match(
51+
def test_mahalanobis_dist_match_df():
52+
matched_df = aim.mahalanobis_dist_match(
5353
data=data,
5454
status_col="status",
5555
feature_cols=["feature_0", "feature_1", "feature_2", "feature_3"],
@@ -64,16 +64,16 @@ def test_mahalonobis_dist_match_df():
6464
)
6565

6666

67-
def test_mahalonobis_dist_match_df_err():
67+
def test_mahalanobis_dist_match_df_err():
6868
with pytest.raises(ValueError): # no status column
69-
aim.mahalonobis_dist_match(data=data)
69+
aim.mahalanobis_dist_match(data=data)
7070
with pytest.raises(ValueError): # status has more than two unique values
71-
aim.mahalonobis_dist_match(data=data, status_col="feature_0")
71+
aim.mahalanobis_dist_match(data=data, status_col="feature_0")
7272

7373

74-
def test_mahalonobis_dist_match_df_feauture_none():
74+
def test_mahalanobis_dist_match_df_feauture_none():
7575
data_wo_extras = data.drop(columns=["eid", "age"])
76-
matched_df = aim.mahalonobis_dist_match(
76+
matched_df = aim.mahalanobis_dist_match(
7777
data=data_wo_extras,
7878
status_col="status",
7979
threshold=1,
@@ -87,8 +87,8 @@ def test_mahalonobis_dist_match_df_feauture_none():
8787
)
8888

8989

90-
def test_mahalonobis_dist_match():
91-
matched_df = aim.mahalonobis_dist_match(
90+
def test_mahalanobis_dist_match():
91+
matched_df = aim.mahalanobis_dist_match(
9292
test=test_features, ctrl=ctrl_features, threshold=1
9393
)
9494

@@ -103,10 +103,10 @@ def test_mahalonobis_dist_match():
103103
)
104104

105105

106-
def test_mahalonobis_dist_match_err():
106+
def test_mahalanobis_dist_match_err():
107107
with pytest.raises(ValueError): # test if nan error is raised
108108
test_features_with_nans = test_features.copy()
109109
test_features_with_nans[0, 2] = np.nan
110-
aim.mahalonobis_dist_match(
110+
aim.mahalanobis_dist_match(
111111
test=test_features_with_nans, ctrl=ctrl_features, threshold=1
112112
)

0 commit comments

Comments
 (0)