Ejemplo n.º 1
0
    def test_zoom(self):
        # Arrange
        X = np.zeros((300, 1, 128, 128))
        y = np.arange(len(X))
        ds = DataSet(X, y)

        # Apply
        zoomed = ds.zoom(0.5)

        # Assert
        assert zoomed.X.shape == (300, 1, 64, 64)
Ejemplo n.º 2
0
    def test_zoom(self):
        # Arrange
        X = np.zeros((300, 1, 128, 128))
        y = np.arange(len(X))
        ds = DataSet(X, y)

        # Apply
        zoomed = ds.zoom(0.5)

        # Assert
        assert zoomed.X.shape == (300, 1, 64, 64)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
    def test_to_nxmxc(self):
        # Arrange
        X = np.zeros((100, 3, 4, 2))
        y = np.arange(len(X))
        ds = DataSet(X, y)
        assert ds.X.shape == (100, 3, 4, 2)

        # Apply
        nxmxc = ds.to_nxmxc()

        # Assert
        assert nxmxc.X.shape == (100, 4, 2, 3)
        for x in nxmxc.X:
            assert x.shape == (4, 2, 3)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
    def test_to_nxmxc(self):
        # Arrange
        X = np.zeros((100, 3, 4, 2))
        y = np.arange(len(X))
        ds = DataSet(X, y)
        assert ds.X.shape == (100, 3, 4, 2)

        # Apply
        nxmxc = ds.to_nxmxc()

        # Assert
        assert nxmxc.X.shape == (100, 4, 2, 3)
        for x in nxmxc.X:
            assert x.shape == (4, 2, 3)
Ejemplo n.º 7
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)
Ejemplo n.º 8
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
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
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)
Ejemplo n.º 12
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)
Ejemplo n.º 13
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
Ejemplo n.º 14
0
    def test_classes(self):
        # Arrange
        X = np.ones((10, 32, 32))
        y = [0, 0, 1, 2, 2, 1, 3, 3, 4, 4, 0]
        ds = DataSet(X, y)

        # Apply
        classes = ds.classes

        # Assert
        assert classes == [0, 1, 2, 3, 4]
Ejemplo n.º 15
0
    def test_one_of_every_class(self):
        # Arrange
        a = np.array([[[0]]])
        a2 = np.array([[[0]]])
        b = np.array([[[1]]])
        b2 = np.array([[[1]]])
        c = np.array([[[2]]])
        d = np.array([[[3]]])
        d2 = np.array([[[3]]])
        d3 = np.array([[[3]]])

        X = np.array([a, a2, b, b2, c, d, d2, d3])
        y = np.array([0, 0, 1, 1, 2, 3, 3, 3])
        ds = DataSet(X, y).shuffle()

        # Apply
        sample = ds.one_of_class()

        # Assert
        np.testing.assert_equal(sample.X, np.array([a, b, c, d]))
        np.testing.assert_equal(sample.y, np.array([0, 1, 2, 3]))
Ejemplo n.º 16
0
    def test_one_of_every_class(self):
        # Arrange
        a = np.array([[[0]]])
        a2 = np.array([[[0]]])
        b = np.array([[[1]]])
        b2 = np.array([[[1]]])
        c = np.array([[[2]]])
        d = np.array([[[3]]])
        d2 = np.array([[[3]]])
        d3 = np.array([[[3]]])

        X = np.array([a, a2, b, b2, c, d, d2, d3])
        y = np.array([0, 0, 1, 1, 2, 3, 3, 3])
        ds = DataSet(X, y).shuffle()

        # Apply
        sample = ds.one_of_class()

        # Assert
        np.testing.assert_equal(sample.X, np.array([a, b, c, d]))
        np.testing.assert_equal(sample.y, np.array([0, 1, 2, 3]))
Ejemplo n.º 17
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)
Ejemplo n.º 18
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)
Ejemplo n.º 19
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)