-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Copyright 2014-2016 The ODL development group | ||
# | ||
# This file is part of ODL. | ||
# | ||
# ODL is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# ODL is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with ODL. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""Example of interfacing with cvx solvers. | ||
This example solves the problem | ||
-Laplacian(x) = b | ||
where b is a gaussian peak at the origin. | ||
""" | ||
|
||
# Imports for common Python 2/3 codebase | ||
from __future__ import print_function, division, absolute_import | ||
from future import standard_library | ||
standard_library.install_aliases() | ||
|
||
import odl | ||
import proximal | ||
|
||
# Create discrete space, a square from [-1, 1] x [-1, 1] with (11 x 11) points | ||
space = odl.uniform_discr([-1, -1], [1, 1], [100, 100]) | ||
|
||
# Create odl operator for negative laplacian | ||
laplacian = -odl.Laplacian(space) | ||
|
||
# Create right hand side | ||
rhs = laplacian(odl.phantom.shepp_logan(space)) | ||
|
||
# Convert laplacian to cvx operator | ||
cvx_laplacian = odl.operator.oputils.as_cvx_operator(laplacian) | ||
|
||
# Convert to array | ||
rhs_arr = rhs.asarray() | ||
|
||
x = proximal.Variable(space.shape) | ||
funcs = [7.5 * proximal.sum_squares(cvx_laplacian(x) - rhs_arr), | ||
proximal.norm1(proximal.grad(x))] | ||
prob = proximal.Problem(funcs) | ||
|
||
# Solve the problem | ||
with odl.util.Timer('solve problem'): | ||
prob.solve(verbose=True, solver='pc', eps_abs=1e-3, eps_rel=1e-3) | ||
|
||
# Convert back to odl and display result | ||
result_odl = space.element(x.value) | ||
result_odl.show('result') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters