Exemplo n.º 1
0
def test_operators_adjointness(size=4):
    """The same as test_identity_adjointness, but with generic design matrix"""
    rng = check_random_state(42)

    # A mask full of ones
    mask = np.ones((size, size, size), dtype=np.bool)

    # But with some zeros
    mask[0:3, 0:3, 0:3] = 0
    adjoint_mask = np.array([mask for _ in range(mask.ndim)])
    n_samples = 200
    X = rng.rand(n_samples, np.sum(mask))
    l1_ratio = 0.5
    for _ in range(10):
        x = rng.rand(np.sum(mask))
        y = rng.rand(n_samples + np.sum(mask) * mask.ndim)
        Axdoty = np.dot(_graph_net_data_function(X, x, mask, l1_ratio), y)
        xdotAty = np.dot(_graph_net_adjoint_data_function(
            X, y, adjoint_mask, l1_ratio), x)
        np.testing.assert_almost_equal(Axdoty, xdotAty)
Exemplo n.º 2
0
def test_identity_adjointness(size=4):
    """Tests adjointess between _graph_net_data_function and
    _graph_net_adjoint_data_function, with identity design matrix"""
    rng = check_random_state(42)

    # A mask full of ones
    mask = np.ones((size, size, size), dtype=np.bool)

    # But with some zeros
    mask[0:3, 0:3, 0:3] = 0
    adjoint_mask = np.array([mask for _ in range(mask.ndim)])
    n_samples = np.sum(mask)
    X = np.eye(n_samples)
    l1_ratio = 0.5
    for _ in range(10):
        x = rng.rand(np.sum(mask))
        y = rng.rand(n_samples + np.sum(mask) * mask.ndim)
        Axdoty = np.dot(_graph_net_data_function(X, x, mask, l1_ratio), y)
        xdotAty = np.dot(_graph_net_adjoint_data_function(
            X, y, adjoint_mask, l1_ratio), x)
        assert_almost_equal(Axdoty, xdotAty)