-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use numpy std with bessel correction and test
- Loading branch information
1 parent
49bd61b
commit 3adaf4c
Showing
3 changed files
with
46 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import numpy as np | ||
import torch | ||
from pytorch_tabnet.metrics import UnsupervisedLoss, UnsupervisedLossNumpy | ||
|
||
torch.set_printoptions(precision=10) | ||
|
||
|
||
def test_equal_losses(): | ||
y_pred = np.random.uniform(low=-2, high=2, size=(20, 100)) | ||
embedded_x = np.random.uniform(low=-2, high=2, size=(20, 100)) | ||
obf_vars = np.random.choice([0, 1], size=(20, 100), replace=True) | ||
|
||
numpy_loss = UnsupervisedLossNumpy( | ||
y_pred=y_pred, | ||
embedded_x=embedded_x, | ||
obf_vars=obf_vars | ||
) | ||
|
||
torch_loss = UnsupervisedLoss( | ||
y_pred=torch.tensor(y_pred, dtype=torch.float64), | ||
embedded_x=torch.tensor(embedded_x, dtype=torch.float64), | ||
obf_vars=torch.tensor(obf_vars, dtype=torch.float64) | ||
) | ||
|
||
assert np.isclose(numpy_loss, torch_loss.detach().numpy()) |