예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
    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)
예제 #6
0
    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
예제 #7
0
    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)
예제 #8
0
    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)
예제 #9
0
    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)
예제 #10
0
    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
예제 #11
0
    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)
예제 #12
0
    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)