-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3db2b4e
commit 2d522b3
Showing
2 changed files
with
43 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import numpy as np | ||
from numpy.testing import assert_allclose | ||
|
||
from stemu.skutils import CDFTransformer, FunctionScaler, IdentityTransformer | ||
|
||
|
||
def test_CDFTransformer(): | ||
t = np.linspace(0, 1, 100) | ||
y = t**3 - t + 1 | ||
y = y * np.random.rand(20, len(t)) | ||
cdf = CDFTransformer() | ||
assert isinstance(cdf.fit(t, y), CDFTransformer) | ||
t_ = cdf.transform(t) | ||
assert not (t == t_).all() | ||
t_ = cdf.inverse_transform(t_) | ||
assert (t == t_).all() | ||
|
||
|
||
def test_FunctionScaler(): | ||
t = np.linspace(0, 1, 100) | ||
y = t**3 - t + 1 | ||
y = y * np.random.rand(20, len(t)) | ||
X = np.block([[t], [y]]) | ||
|
||
fs = FunctionScaler() | ||
assert isinstance(fs.fit(X), FunctionScaler) | ||
X_ = fs.transform(X) | ||
assert_allclose(X_[1:].mean(axis=0), 0, atol=1e-15) | ||
assert_allclose(X_[1:].std(axis=0), 1, atol=1e-15) | ||
assert_allclose(fs.inverse_transform(X_), X) | ||
|
||
|
||
def test_IdentityTransformer(): | ||
y = np.random.rand(10, 20) | ||
|
||
identity = IdentityTransformer() | ||
assert isinstance(identity.fit(y), IdentityTransformer) | ||
t_ = identity.transform(t) | ||
assert (t == t_).all() | ||
t_ = identity.inverse_transform(t_) | ||
assert (t == t_).all() |