|
3 | 3 | import numpy as np |
4 | 4 | from numpy.testing import assert_array_almost_equal |
5 | 5 |
|
6 | | -from pylops.basicoperators import Identity, Diagonal, MatrixMult |
| 6 | +from pylops.basicoperators import Identity, Diagonal, MatrixMult, FirstDerivative |
7 | 7 | from pyproximal.utils import moreau |
8 | | -from pyproximal.proximal import Box, Euclidean, L2, L1, L21, L21_plus_L1, Huber, Nuclear |
| 8 | +from pyproximal.proximal import Box, Euclidean, L2, L1, L21, L21_plus_L1, Huber, Nuclear, TV |
9 | 9 |
|
10 | 10 | par1 = {'nx': 10, 'sigma': 1., 'dtype': 'float32'} # even float32 |
11 | 11 | par2 = {'nx': 11, 'sigma': 2., 'dtype': 'float64'} # odd float64 |
@@ -189,6 +189,18 @@ def test_Huber(par): |
189 | 189 | assert moreau(hub, x, tau) |
190 | 190 |
|
191 | 191 |
|
| 192 | +@pytest.mark.parametrize("par", [(par1), (par2)]) |
| 193 | +def test_TV(par): |
| 194 | + """TV norm of x and proximal |
| 195 | + """ |
| 196 | + tv = TV(dim=1, sigma=par['sigma']) |
| 197 | + # norm |
| 198 | + x = np.random.normal(0., 1., par['nx']).astype(par['dtype']) |
| 199 | + derivOp = FirstDerivative(par['nx'], dtype=par['dtype'], kind='forward') |
| 200 | + dx = derivOp @ x |
| 201 | + assert_array_almost_equal(tv(x), par['sigma'] * np.sum(np.abs(dx), axis=0)) |
| 202 | + |
| 203 | + |
192 | 204 | def test_Nuclear_FOM(): |
193 | 205 | """Nuclear norm benchmark with FOM solver |
194 | 206 | """ |
@@ -228,7 +240,7 @@ def test_Weighted_Nuclear(par): |
228 | 240 | # the exact same singular values) |
229 | 241 | X = np.random.uniform(0., 0.1, (par['nx'], 2 * par['nx'])).astype(par['dtype']) |
230 | 242 | S = np.linalg.svd(X, compute_uv=False) |
231 | | - assert (nucl(X.ravel()) - np.sum(weights[:S.size] * S)) < 1e-3 |
| 243 | + assert (nucl(X.ravel()) - np.sum(weights[:S.size] * S)) < 1e-2 |
232 | 244 |
|
233 | 245 | # prox / dualprox |
234 | 246 | tau = 2. |
|
0 commit comments