Skip to content

Commit bf64668

Browse files
committed
ENH: Rename example to functional_basic_example_solver.
1 parent 2ea6d69 commit bf64668

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

examples/solvers/functionals_basic_examples.py renamed to examples/solvers/functional_basic_example_solver.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,30 @@
1515
# You should have received a copy of the GNU General Public License
1616
# along with ODL. If not, see <http://www.gnu.org/licenses/>.
1717

18-
"""Basic examples on how to use the fucntional class.
19-
20-
This file contains two basic examples on how to use the functional class. It
21-
contains one example of how to use the default functionals, and how they can be
22-
used in connection to solvers. It also contains one example on how to
23-
implement a new functional.
18+
"""Basic examples on how to use the fucntional class together with solvers.
19+
20+
This file shows an example of how to set up and solve an optimization problem
21+
using the default functionals. The problem we will solve is to minimize
22+
1/2 * ||x - g||_2^2 + lam*||x||_1, for some vector g and some constant lam,
23+
subject to that all components in x are greater than or equal to 0. The
24+
theoretical optimal solution to this problem is x = (g - lam)_+, where ( )+
25+
denotes the positive part of (i.e., (z)_+ = z if z >= 0, 0 otherwise).
2426
"""
2527

2628
import numpy as np
2729
import odl
2830

29-
# First we show how the default functionals can be used in order to set up and
30-
# solve an optimization problem. The problem we will solve is to minimize
31-
# 1/2 * ||x - g||_2^2 + lam*||x||_1, for some vector g and some constant lam,
32-
# subject to that all components in x are greater than or equal to 0.
33-
34-
# Create a space with dimensiona n.
31+
# Create a space with dimensiona n=10.
3532
n = 10
3633
space = odl.rn(n)
3734

3835
# Create parameters. First half of g are ones, second half are minus ones.
3936
g = space.element(np.hstack((np.ones(n/2), -np.ones(n/2))))
4037
lam = 0.5
4138

39+
# Note that with the values above, the optimal solution is given by a vector
40+
# with fires half of the elements equal to 0.5, the second half equal to 0.
41+
4242
# Create the L1-norm functional and multiplyit with the constant lam.
4343
lam_l1_func = lam * odl.solvers.L1Norm(space)
4444

@@ -81,6 +81,4 @@
8181
op, x, tau=tau, sigma=sigma, proximal_primal=proximal_primal,
8282
proximal_dual=proximal_dual, niter=niter, callback=callback)
8383

84-
# The theoretical optimal solution to this problem is x = (g - lam)_+, where
85-
# ( )+ denotes the positive part of (i.e., (z)_+ = z if z >= 0, 0 otherwise).
8684
print(x.asarray())

0 commit comments

Comments
 (0)