Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve #528 #532

Merged
merged 5 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions scico/optimize/_admmaux.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,19 +404,24 @@ def internal_init(self, admm: soa.ADMM):
f"or scico.linop.Identity; got {type(admm.f.A)}."
)

self.ndims = admm.f.A.ndims if isinstance(admm.f.A, CircularConvolve) else None
super().internal_init(admm)

self.real_result = is_real_dtype(admm.C_list[0].input_dtype)

# All of the C operators are assumed to be linear and shift invariant
# but this is not checked.
lhs_op_list = [
rho * CircularConvolve.from_operator(C.gram_op)
rho * CircularConvolve.from_operator(C.gram_op, ndims=self.ndims)
for rho, C in zip(admm.rho_list, admm.C_list)
]
A_lhs = reduce(lambda a, b: a + b, lhs_op_list)
if self.admm.f is not None:
A_lhs += 2.0 * admm.f.scale * CircularConvolve.from_operator(admm.f.A.gram_op)
A_lhs += (
2.0
* admm.f.scale
* CircularConvolve.from_operator(admm.f.A.gram_op, ndims=self.ndims)
)

self.A_lhs = A_lhs

Expand Down
17 changes: 12 additions & 5 deletions scico/test/optimize/test_admm.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,23 +363,29 @@ def test_admm_quadratic_matrix(self):
assert (snp.linalg.norm(self.grdA(x) - self.grdb) / snp.linalg.norm(self.grdb)) < 1e-5


@pytest.mark.parametrize("extra_axis", (False, True))
@pytest.mark.parametrize("center", (None, [-1.0, 2.5]))
class TestCircularConvolveSolve:
def setup_method(self, method):

@pytest.fixture(scope="function", autouse=True)
def setup_and_teardown(self, extra_axis, center):
np.random.seed(12345)
Nx = 8
x = np.pad(np.ones((Nx, Nx), dtype=np.float32), Nx)
x = snp.pad(snp.ones((Nx, Nx), dtype=np.float32), Nx)
Npsf = 3
psf = snp.ones((Npsf, Npsf), dtype=np.float32) / (Npsf**2)
if extra_axis:
x = x[np.newaxis]
psf = psf[np.newaxis]
self.A = linop.CircularConvolve(
h=psf,
input_shape=x.shape,
input_dtype=np.float32,
h=psf, input_shape=x.shape, ndims=2, input_dtype=np.float32, h_center=center
)
self.y = self.A(x)
λ = 1e-2
self.f = loss.SquaredL2Loss(y=self.y, A=self.A)
self.g_list = [λ * functional.L1Norm()]
self.C_list = [linop.FiniteDifference(input_shape=x.shape, circular=True)]
yield

def test_admm(self):
maxiter = 50
Expand All @@ -406,6 +412,7 @@ def test_admm(self):
x0=self.A.adj(self.y),
subproblem_solver=CircularConvolveSolver(),
)
assert admm_dft.subproblem_solver.A_lhs.ndims == 2
x_dft = admm_dft.solve()
np.testing.assert_allclose(x_dft, x_lin, atol=1e-4, rtol=0)
assert metric.mse(x_lin, x_dft) < 1e-9
Expand Down
Loading