Ejemplo n.º 1
0
def test_pooling_no_topology():
    mat = pooling_matrix(4, 5)
    assert mat.shape == (4, 20)
    expected = np.array([[1] * 5 + [0] * 15, [0] * 5 + [1] * 5 + [0] * 10,
                         [0] * 10 + [1] * 5 + [0] * 5, [0] * 15 + [1] * 5])
    assert np.all(mat == expected)
    spmat = pooling_matrix(4, 5, sparse='csr')
    assert np.all(spmat.todense() == expected)
Ejemplo n.º 2
0
def test_pooling_1d_topology_tuples():
    mat = pooling_matrix((3, ), (4, ), (2, ))
    assert mat.shape == (3, 8)
    expected = np.array([[1, 1, 1, 1, 0, 0, 0, 0], [0, 0, 1, 1, 1, 1, 0, 0],
                         [0, 0, 0, 0, 1, 1, 1, 1]])
    assert np.all(mat == expected)
    spmat = pooling_matrix(3, 4, 2, sparse='csr')
    assert np.all(spmat.todense() == expected)
Ejemplo n.º 3
0
def test_pooling_1d_topology():
    mat = pooling_matrix(3, 4, 2)
    assert mat.shape == (3, 8)
    expected = np.array([[1, 1, 1, 1, 0, 0, 0, 0], [0, 0, 1, 1, 1, 1, 0, 0],
                         [0, 0, 0, 0, 1, 1, 1, 1]])
    assert np.all(mat == expected)
    skip_if_no_scipy()
    spmat = pooling_matrix(3, 4, 2, sparse='csr')
    assert np.all(spmat.todense() == expected)
Ejemplo n.º 4
0
def test_pooling_1d_topology_tuples():
    mat = pooling_matrix((3,), (4,), (2,))
    assert mat.shape == (3, 8)
    expected = np.array([[1, 1, 1, 1, 0, 0, 0, 0],
                         [0, 0, 1, 1, 1, 1, 0, 0],
                         [0, 0, 0, 0, 1, 1, 1, 1]])
    assert np.all(mat == expected)
    spmat = pooling_matrix(3, 4, 2, sparse='csr')
    assert np.all(spmat.todense() == expected)
Ejemplo n.º 5
0
def test_pooling_1d_topology():
    mat = pooling_matrix(3, 4, 2)
    assert mat.shape == (3, 8)
    expected = np.array([[1, 1, 1, 1, 0, 0, 0, 0],
                         [0, 0, 1, 1, 1, 1, 0, 0],
                         [0, 0, 0, 0, 1, 1, 1, 1]])
    assert np.all(mat == expected)
    skip_if_no_scipy()
    spmat = pooling_matrix(3, 4, 2, sparse='csr')
    assert np.all(spmat.todense() == expected)
Ejemplo n.º 6
0
def test_pooling_no_topology():
    mat = pooling_matrix(4, 5)
    assert mat.shape == (4, 20)
    expected = np.array([[1] * 5 + [0] * 15,
                         [0] * 5 + [1] * 5 + [0] * 10,
                         [0] * 10 + [1] * 5 + [0] * 5,
                         [0] * 15 + [1] * 5])
    assert np.all(mat == expected)
    spmat = pooling_matrix(4, 5, sparse='csr')
    assert np.all(spmat.todense() == expected)
Ejemplo n.º 7
0
def test_pooling_2d_topology_stride2():
    mat = pooling_matrix((3, 3), (3, 3), (2, 2))
    expected = np.zeros((9, 49))
    maps = expected.reshape((3, 3, 7, 7))
    maps[0, 0, 0:3, 0:3] = 1.
    maps[0, 1, 0:3, 2:5] = 1.
    maps[0, 2, 0:3, 4:7] = 1.
    maps[1, 0, 2:5, 0:3] = 1.
    maps[1, 1, 2:5, 2:5] = 1.
    maps[1, 2, 2:5, 4:7] = 1.
    maps[2, 0, 4:7, 0:3] = 1.
    maps[2, 1, 4:7, 2:5] = 1.
    maps[2, 2, 4:7, 4:7] = 1.
    assert np.all(mat == expected)
    spmat = pooling_matrix((3, 3), (3, 3), (2, 2), sparse='csr')
    assert np.all(spmat.todense() == expected)
Ejemplo n.º 8
0
def test_pooling_2d_topology_stride2():
    mat = pooling_matrix((3, 3), (3, 3), (2, 2))
    expected = np.zeros((9, 49))
    maps = expected.reshape((3, 3, 7, 7))
    maps[0, 0, 0:3, 0:3] = 1.
    maps[0, 1, 0:3, 2:5] = 1.
    maps[0, 2, 0:3, 4:7] = 1.
    maps[1, 0, 2:5, 0:3] = 1.
    maps[1, 1, 2:5, 2:5] = 1.
    maps[1, 2, 2:5, 4:7] = 1.
    maps[2, 0, 4:7, 0:3] = 1.
    maps[2, 1, 4:7, 2:5] = 1.
    maps[2, 2, 4:7, 4:7] = 1.
    assert np.all(mat == expected)
    spmat = pooling_matrix((3, 3), (3, 3), (2, 2), sparse='csr')
    assert np.all(spmat.todense() == expected)
Ejemplo n.º 9
0
def test_pooling_2d_non_overlapping():
    mat = pooling_matrix((3, 3), (3, 3), (3, 3))
    assert mat.shape == (9, 81)
    expected = np.zeros((9, 81))
    maps = expected.reshape((3, 3, 9, 9))
    maps[0, 0, 0:3, 0:3] = 1.
    maps[0, 1, 0:3, 3:6] = 1.
    maps[0, 2, 0:3, 6:9] = 1.
    maps[1, 0, 3:6, 0:3] = 1.
    maps[1, 1, 3:6, 3:6] = 1.
    maps[1, 2, 3:6, 6:9] = 1.
    maps[2, 0, 6:9, 0:3] = 1.
    maps[2, 1, 6:9, 3:6] = 1.
    maps[2, 2, 6:9, 6:9] = 1.
    assert np.all(mat == expected)
    spmat = pooling_matrix((3, 3), (3, 3), (3, 3), sparse='csr')
    assert np.all(spmat.todense() == expected)
Ejemplo n.º 10
0
def test_pooling_2d_topology():
    mat = pooling_matrix((3, 3), (2, 2), (1, 1))
    assert mat.shape == (9, 16)
    expected = np.zeros((9, 16))
    maps = expected.reshape((3, 3, 4, 4))
    maps[0, 0, 0:2, 0:2] = 1.
    maps[1, 0, 1:3, 0:2] = 1.
    maps[2, 0, 2:4, 0:2] = 1.
    maps[0, 1, 0:2, 1:3] = 1.
    maps[1, 1, 1:3, 1:3] = 1.
    maps[2, 1, 2:4, 1:3] = 1.
    maps[0, 2, 0:2, 2:4] = 1.
    maps[1, 2, 1:3, 2:4] = 1.
    maps[2, 2, 2:4, 2:4] = 1.
    assert np.all(mat == expected)
    spmat = pooling_matrix((3, 3), (2, 2), (1, 1), sparse='csr')
    assert np.all(spmat.todense() == expected)
Ejemplo n.º 11
0
def test_pooling_2d_non_overlapping():
    mat = pooling_matrix((3, 3), (3, 3), (3, 3))
    assert mat.shape == (9, 81)
    expected = np.zeros((9, 81))
    maps = expected.reshape((3, 3, 9, 9))
    maps[0, 0, 0:3, 0:3] = 1.
    maps[0, 1, 0:3, 3:6] = 1.
    maps[0, 2, 0:3, 6:9] = 1.
    maps[1, 0, 3:6, 0:3] = 1.
    maps[1, 1, 3:6, 3:6] = 1.
    maps[1, 2, 3:6, 6:9] = 1.
    maps[2, 0, 6:9, 0:3] = 1.
    maps[2, 1, 6:9, 3:6] = 1.
    maps[2, 2, 6:9, 6:9] = 1.
    assert np.all(mat == expected)
    spmat = pooling_matrix((3, 3), (3, 3), (3, 3), sparse='csr')
    assert np.all(spmat.todense() == expected)
Ejemplo n.º 12
0
def test_pooling_2d_topology():
    mat = pooling_matrix((3, 3), (2, 2), (1, 1))
    assert mat.shape == (9, 16)
    expected = np.zeros((9, 16))
    maps = expected.reshape((3, 3, 4, 4))
    maps[0, 0, 0:2, 0:2] = 1.
    maps[1, 0, 1:3, 0:2] = 1.
    maps[2, 0, 2:4, 0:2] = 1.
    maps[0, 1, 0:2, 1:3] = 1.
    maps[1, 1, 1:3, 1:3] = 1.
    maps[2, 1, 2:4, 1:3] = 1.
    maps[0, 2, 0:2, 2:4] = 1.
    maps[1, 2, 1:3, 2:4] = 1.
    maps[2, 2, 2:4, 2:4] = 1.
    assert np.all(mat == expected)
    spmat = pooling_matrix((3, 3), (2, 2), (1, 1), sparse='csr')
    assert np.all(spmat.todense() == expected)