Ejemplo n.º 1
0
def test_tv1d_dtype():
    # check that prox_tv1d preserve 32bit

    x = np.arange(5)
    for dtype in (np.float32, np.float64):
        y = x.astype(dtype, copy=True)
        prox_fast.prox_tv1d(y, 0.01)
        assert_equal(y.dtype, dtype)
Ejemplo n.º 2
0
def test_tv1d_dtype():
    # check that prox_tv1d preserve 32bit

    x = np.arange(5)
    for dtype in (np.float32, np.float64):
        y = x.astype(dtype, copy=True)
        prox_fast.prox_tv1d(y, 0.01)
        assert_equal(y.dtype, dtype)
Ejemplo n.º 3
0
def test_tv1_denoise():
    # test the prox of TV1D
    # since its not trivial to check the KKT conditions
    # we check that the proximal point algorithm converges
    # to a solution to the TV minimization
    n_iter = 100
    n_features = 100

    # repeat the test 10 times
    for nrun in range(10):
        x = np.random.randn(n_features)
        for _ in range(n_iter):
            prox_fast.prox_tv1d(x, 1.0)
        # check that the solution is flat
        np.testing.assert_allclose(x, x.mean() * np.ones(n_features))
Ejemplo n.º 4
0
def test_tv1_denoise():
    # test the prox of TV1D
    # since its not trivial to check the KKT conditions
    # we check that the proximal point algorithm converges
    # to a solution to the TV minimization
    n_iter = 100
    n_features = 100

    # repeat the test 10 times
    for nrun in range(10):
        x = np.random.randn(n_features)
        for _ in range(n_iter):
            prox_fast.prox_tv1d(x, 1.0)
        # check that the solution is flat
        np.testing.assert_allclose(x, x.mean() * np.ones(n_features))
Ejemplo n.º 5
0
 def projection(self, coef, alpha, L):
     tmp = coef.copy()
     for i in range(tmp.shape[0]):
         prox_tv1d(tmp[i, :], alpha / L)  # operates inplace
     return tmp
Ejemplo n.º 6
0
 def projection(self, coef, alpha, L):
     tmp = coef.copy()
     for i in range(tmp.shape[0]):
         prox_tv1d(tmp[i, :], alpha / L)  # operates inplace
     return tmp
Ejemplo n.º 7
0
 def projection(self, coef, alpha, L):
     tmp = np.empty_like(coef)
     for i in range(tmp.shape[0]):
         tmp[i] = prox_tv1d(coef[i], alpha / L)
     return tmp
Ejemplo n.º 8
0
def test_tv1d_dtype(dtype):
    # check that prox_tv1d preserve 32bit
    x = np.arange(5)
    y = x.astype(dtype, copy=True)
    prox_fast.prox_tv1d(y, 0.01)
    assert y.dtype == dtype