def test_unstandardize2(self): # Arrange X = np.random.randn(1e4, 1, 32, 32) * 10 + 12 y = np.arange(len(X)) ds = DataSet(X, y) # Apply ds.standardize(standardization_type='individual') ds.unstandardize() # Assert np.testing.assert_allclose(X, ds.X, atol=1e-5)
def test_swap_standardization(self): # Arrange X = np.random.randn(1e4, 1, 32, 32) * 10 + 12 y = np.arange(len(X)) ds = DataSet(X, y) # Apply ds.standardize(standardization_type='individual') ds.standardize(standardization_type='global') # Assert assert ds.mean.shape == () np.testing.assert_allclose(ds.mean, 12, atol=1e-1) np.testing.assert_allclose(ds.std, 10, atol=1e-1)
def test_unstandardize_global(self): # Arrange X = np.random.randn(1e4, 1, 32, 32) * 10 + 12 y = np.arange(len(X)) ds = DataSet(X, y) # Apply ds.standardize(standardization_type='global') ds.unstandardize() # Assert assert ds.mean.shape == () np.testing.assert_allclose(ds.mean, 12, atol=1e-1) np.testing.assert_allclose(ds.std, 10, atol=1e-1)
def test_standardize_none(self): # Arrange x1 = np.array([[0, 1, 0], [0, 1, 0], [0, 1, 0]]) x2 = np.array([[1, 0, 1], [1, 0, 1], [1, 0, 1]]) X = np.array([x1, x2]) y = np.arange(len(X)) ds = DataSet(X, y) Xorig = ds.X.copy() # Apply ds.standardize(standardization_type=None) # Assert np.testing.assert_allclose(Xorig, ds.X)
def test_standardize_global(self): # Arrange x1 = np.array([[0, 1, 0], [0, 1, 0], [0, 1, 0]]) x2 = np.array([[1, 0, 1], [1, 0, 1], [1, 0, 1]]) X = np.array([x1, x2]) y = np.arange(len(X)) ds = DataSet(X, y) # Apply ds.standardize(standardization_type='global') # Assert assert ds.mean.shape == () assert ds.mean == 0.5 assert ds.X.std() == 1
def test_unstandardize(self): # Arrange x1 = np.array([[0, 1, 0], [0, 1, 0], [0, 1, 0]]) x2 = np.array([[1, 0, 1], [1, 0, 1], [1, 0, 1]]) X = np.array([x1, x2]) y = np.arange(len(X)) ds = DataSet(X, y) # Apply ds.standardize() ds.unstandardize() # Assert np.testing.assert_allclose(ds.X[0].squeeze(), x1) np.testing.assert_allclose(ds.X[1].squeeze(), x2)
def test_standardize(self): # Arrange x1 = np.array([[0, 1, 0], [0, 1, 0], [0, 1, 0]]) x2 = np.array([[1, 0, 1], [1, 0, 1], [1, 0, 1]]) X = np.array([x1, x2]) y = np.arange(len(X)) ds = DataSet(X, y) # Apply ds.standardize() # Assert for x in ds.X: np.testing.assert_allclose(x.mean(), 0, atol=1e-7) np.testing.assert_allclose(x.std(), 1, atol=1e-7)