{"action":"created","comment":{"url":"https://api.github.com/repos/odlgroup/odl/pulls/comments/62034865","id":62034865,"diff_hunk":"@@ -0,0 +1,180 @@\n+# Copyright 2014-2016 The ODL development group\n+#\n+# This file is part of ODL.\n+#\n+# ODL is free software: you can redistribute it and/or modify\n+# it under the terms of the GNU General Public License as published by\n+# the Free Software Foundation, either version 3 of the License, or\n+# (at your option) any later version.\n+#\n+# ODL is distributed in the hope that it will be useful,\n+# but WITHOUT ANY WARRANTY; without even the implied warranty of\n+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+# GNU General Public License for more details.\n+#\n+# You should have received a copy of the GNU General Public License\n+# along with ODL.  If not, see <http://www.gnu.org/licenses/>.\n+\n+\"\"\"Total variation base image denoising using the Chambolle-Pock solver.\n+\n+Let X and Y be finite-dimensional Hilbert spaces and K a linear mapping\n+from X to Y with induce norm ||K||. The (primal) minimization problem we\n+want to solve is\n+\n+    min_{x in X} F(K x) + G(x)\n+\n+where the proper, convex, lower-semicontinuous functionals\n+F : Y -> [0, +infinity] and G : X -> [0, +infinity] are given\n+by an l2-data fitting term regularized by isotropic total variation\n+\n+    F(K x) = 1/2 ||x - g||_2^2 + lam || |grad(x)| ||_1\n+\n+and by the indicator function for the set fo non-negative components of x\n+\n+   G(x) = {0 if x >=0, infinity if x < 0} ,\n+\n+respectively. Here, g denotes the image to denoise, ||.||_2 the l2-norm,\n+||.||_1 the l1-semi-norm, grad the spatial gradient, lam the regularization\n+parameter, |.| the point-wise magnitude across the vector components of\n+grad(x), and K is a column vector of operators K = (id, grad)^T with\n+identity mapping id.\n+\n+In order to use the Chambolle-Pock solver, we have to create the column\n+operator K, choose a starting point x, create the proximal operator for G,\n+create the proximal operator for the convex conjugate of F, choose the\n+step sizes tau and sigma such that tau sigma ||K||_2^2 < 1, and set the\n+total number of iterations.\n+\n+For details see :ref:`chambolle_pock`, :ref:`proximal_operators`, and\n+references therein.\n+\"\"\"\n+\n+# Imports for common Python 2/3 codebase\n+from __future__ import print_function, division, absolute_import\n+from future import standard_library\n+standard_library.install_aliases()\n+\n+import numpy as np\n+import scipy\n+import scipy.ndimage\n+import matplotlib.pyplot as plt\n+\n+import odl\n+\n+# Read test image: use only every second pixel, convert integer to float,\n+# and rotate to get the image upright\n+image = np.rot90(scipy.misc.ascent()[::2, ::2], 3).astype('float')\n+shape = image.shape\n+\n+# Rescale max to 1\n+image /= image.max()\n+\n+# Discretized spaces\n+discr_space = odl.uniform_discr([0, 0], [1, 1], shape)\n+\n+# Original image\n+orig = discr_space.element(image)\n+orig.show('Original image')\n+\n+# Add noise\n+image += np.random.normal(0, 0.1, shape)\n+\n+# Data of noisy image\n+noisy = discr_space.element(image)\n+noisy.show('Nosy image')\n+\n+# Gradient operator\n+gradient = odl.Gradient(discr_space, method='forward')\n+\n+# Matrix of operators\n+op = odl.BroadcastOperator(odl.IdentityOperator(discr_space), gradient)\n+\n+# Proximal operators related to the dual variable\n+\n+# l2-data matching\n+prox_convconj_l2 = odl.solvers.proximal_convexconjugate_l2(discr_space,\n+                                                           lam=1, g=noisy)\n+\n+# TV-regularization: l1-semi norm of grad(x)\n+prox_convconj_l1 = odl.solvers.proximal_convexconjugate_l1(gradient.range,\n+                                                           lam=1/4000.0)\n+\n+# Combine proximal operators: the order must match the order of operators in K\n+proximal_dual = odl.solvers.combine_proximals([prox_convconj_l2,\n+                                               prox_convconj_l1])\n+\n+# Proximal operator related to the primal variable\n+\n+# Non-negativity constraint\n+proximal_primal = odl.solvers.proximal_nonnegativity(op.domain)\n+\n+\n+# --- Run algorithms without preconditioner\n+\n+\n+op_norm_identity = 1.0\n+op_norm_gradient = 1.5 * odl.power_method_opnorm(gradient, 100, noisy)\n+print('Operator norms, I: {}, gradient: {}'.format(op_norm_identity,\n+                                                   op_norm_gradient))\n+\n+# --- Run algorithms without preconditioner\n+\n+niter = 50\n+\n+# Create a function to save the partial errors\n+differences = []\n+\n+\n+def print_diff(x):\n+    error = (x-orig).norm()\n+    differences.append(error)\n+\n+# Optional: pass partial objects to solver\n+partial = (odl.solvers.ShowPartial() &\n+           odl.solvers.PrintIterationPartial() &\n+           print_diff)","path":"examples/solvers/chambolle_pock_preconditioner_denoising.py","position":135,"original_position":135,"commit_id":"e9ad1407f322a9e2867701ca29ba710f284c1d2e","original_commit_id":"b187c01c82f47388926bb4b697829ab080427669","user":{"login":"adler-j","id":2202312,"avatar_url":"https://avatars.githubusercontent.com/u/2202312?v=3","gravatar_id":"","url":"https://api.github.com/users/adler-j","html_url":"https://github.com/adler-j","followers_url":"https://api.github.com/users/adler-j/followers","following_url":"https://api.github.com/users/adler-j/following{/other_user}","gists_url":"https://api.github.com/users/adler-j/gists{/gist_id}","starred_url":"https://api.github.com/users/adler-j/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adler-j/subscriptions","organizations_url":"https://api.github.com/users/adler-j/orgs","repos_url":"https://api.github.com/users/adler-j/repos","events_url":"https://api.github.com/users/adler-j/events{/privacy}","received_events_url":"https://api.github.com/users/adler-j/received_events","type":"User","site_admin":false},"body":"Added in  e9ad140","created_at":"2016-05-04T13:07:38Z","updated_at":"2016-05-04T13:07:38Z","html_url":"https://github.com/odlgroup/odl/pull/380#discussion_r62034865","pull_request_url":"https://api.github.com/repos/odlgroup/odl/pulls/380","_links":{"self":{"href":"https://api.github.com/repos/odlgroup/odl/pulls/comments/62034865"},"html":{"href":"https://github.com/odlgroup/odl/pull/380#discussion_r62034865"},"pull_request":{"href":"https://api.github.com/repos/odlgroup/odl/pulls/380"}}},"pull_request":{"url":"https://api.github.com/repos/odlgroup/odl/pulls/380","id":68828180,"html_url":"https://github.com/odlgroup/odl/pull/380","diff_url":"https://github.com/odlgroup/odl/pull/380.diff","patch_url":"https://github.com/odlgroup/odl/pull/380.patch","issue_url":"https://api.github.com/repos/odlgroup/odl/issues/380","number":380,"state":"open","locked":false,"title":"Issue 379  diagonal precon","user":{"login":"adler-j","id":2202312,"avatar_url":"https://avatars.githubusercontent.com/u/2202312?v=3","gravatar_id":"","url":"https://api.github.com/users/adler-j","html_url":"https://github.com/adler-j","followers_url":"https://api.github.com/users/adler-j/followers","following_url":"https://api.github.com/users/adler-j/following{/other_user}","gists_url":"https://api.github.com/users/adler-j/gists{/gist_id}","starred_url":"https://api.github.com/users/adler-j/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adler-j/subscriptions","organizations_url":"https://api.github.com/users/adler-j/orgs","repos_url":"https://api.github.com/users/adler-j/repos","events_url":"https://api.github.com/users/adler-j/events{/privacy}","received_events_url":"https://api.github.com/users/adler-j/received_events","type":"User","site_admin":false},"body":"* Add preconditioning to chambolle pock\r\n* Add example using diagonal preconditioner\r\n* Changed `diagonal_operator` into `DiagonalOperator`\r\n* Extended `&` syntax of partials to accept `Partial & callable`\r\n* Expose `power_method_opnorm` and others to main namespace, closes #325 \r\n\r\nTry the example, the difference is extremely big.","created_at":"2016-05-04T08:47:47Z","updated_at":"2016-05-04T13:07:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f0870ebee8faab11f38ac2dfa7b72ae066b7b3eb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/odlgroup/odl/pulls/380/commits","review_comments_url":"https://api.github.com/repos/odlgroup/odl/pulls/380/comments","review_comment_url":"https://api.github.com/repos/odlgroup/odl/pulls/comments{/number}","comments_url":"https://api.github.com/repos/odlgroup/odl/issues/380/comments","statuses_url":"https://api.github.com/repos/odlgroup/odl/statuses/e9ad1407f322a9e2867701ca29ba710f284c1d2e","head":{"label":"odlgroup:issue-379__diagonal_precon","ref":"issue-379__diagonal_precon","sha":"e9ad1407f322a9e2867701ca29ba710f284c1d2e","user":{"login":"odlgroup","id":15667171,"avatar_url":"https://avatars.githubusercontent.com/u/15667171?v=3","gravatar_id":"","url":"https://api.github.com/users/odlgroup","html_url":"https://github.com/odlgroup","followers_url":"https://api.github.com/users/odlgroup/followers","following_url":"https://api.github.com/users/odlgroup/following{/other_user}","gists_url":"https://api.github.com/users/odlgroup/gists{/gist_id}","starred_url":"https://api.github.com/users/odlgroup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odlgroup/subscriptions","organizations_url":"https://api.github.com/users/odlgroup/orgs","repos_url":"https://api.github.com/users/odlgroup/repos","events_url":"https://api.github.com/users/odlgroup/events{/privacy}","received_events_url":"https://api.github.com/users/odlgroup/received_events","type":"Organization","site_admin":false},"repo":{"id":45596393,"name":"odl","full_name":"odlgroup/odl","owner":{"login":"odlgroup","id":15667171,"avatar_url":"https://avatars.githubusercontent.com/u/15667171?v=3","gravatar_id":"","url":"https://api.github.com/users/odlgroup","html_url":"https://github.com/odlgroup","followers_url":"https://api.github.com/users/odlgroup/followers","following_url":"https://api.github.com/users/odlgroup/following{/other_user}","gists_url":"https://api.github.com/users/odlgroup/gists{/gist_id}","starred_url":"https://api.github.com/users/odlgroup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odlgroup/subscriptions","organizations_url":"https://api.github.com/users/odlgroup/orgs","repos_url":"https://api.github.com/users/odlgroup/repos","events_url":"https://api.github.com/users/odlgroup/events{/privacy}","received_events_url":"https://api.github.com/users/odlgroup/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/odlgroup/odl","description":"Operator Discretization Library","fork":false,"url":"https://api.github.com/repos/odlgroup/odl","forks_url":"https://api.github.com/repos/odlgroup/odl/forks","keys_url":"https://api.github.com/repos/odlgroup/odl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/odlgroup/odl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/odlgroup/odl/teams","hooks_url":"https://api.github.com/repos/odlgroup/odl/hooks","issue_events_url":"https://api.github.com/repos/odlgroup/odl/issues/events{/number}","events_url":"https://api.github.com/repos/odlgroup/odl/events","assignees_url":"https://api.github.com/repos/odlgroup/odl/assignees{/user}","branches_url":"https://api.github.com/repos/odlgroup/odl/branches{/branch}","tags_url":"https://api.github.com/repos/odlgroup/odl/tags","blobs_url":"https://api.github.com/repos/odlgroup/odl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/odlgroup/odl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/odlgroup/odl/git/refs{/sha}","trees_url":"https://api.github.com/repos/odlgroup/odl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/odlgroup/odl/statuses/{sha}","languages_url":"https://api.github.com/repos/odlgroup/odl/languages","stargazers_url":"https://api.github.com/repos/odlgroup/odl/stargazers","contributors_url":"https://api.github.com/repos/odlgroup/odl/contributors","subscribers_url":"https://api.github.com/repos/odlgroup/odl/subscribers","subscription_url":"https://api.github.com/repos/odlgroup/odl/subscription","commits_url":"https://api.github.com/repos/odlgroup/odl/commits{/sha}","git_commits_url":"https://api.github.com/repos/odlgroup/odl/git/commits{/sha}","comments_url":"https://api.github.com/repos/odlgroup/odl/comments{/number}","issue_comment_url":"https://api.github.com/repos/odlgroup/odl/issues/comments{/number}","contents_url":"https://api.github.com/repos/odlgroup/odl/contents/{+path}","compare_url":"https://api.github.com/repos/odlgroup/odl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/odlgroup/odl/merges","archive_url":"https://api.github.com/repos/odlgroup/odl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/odlgroup/odl/downloads","issues_url":"https://api.github.com/repos/odlgroup/odl/issues{/number}","pulls_url":"https://api.github.com/repos/odlgroup/odl/pulls{/number}","milestones_url":"https://api.github.com/repos/odlgroup/odl/milestones{/number}","notifications_url":"https://api.github.com/repos/odlgroup/odl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/odlgroup/odl/labels{/name}","releases_url":"https://api.github.com/repos/odlgroup/odl/releases{/id}","deployments_url":"https://api.github.com/repos/odlgroup/odl/deployments","created_at":"2015-11-05T07:57:55Z","updated_at":"2016-02-03T10:05:06Z","pushed_at":"2016-05-04T13:07:28Z","git_url":"git://github.com/odlgroup/odl.git","ssh_url":"git@github.com:odlgroup/odl.git","clone_url":"https://github.com/odlgroup/odl.git","svn_url":"https://github.com/odlgroup/odl","homepage":null,"size":16395,"stargazers_count":3,"watchers_count":3,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":101,"forks":3,"open_issues":101,"watchers":3,"default_branch":"master"}},"base":{"label":"odlgroup:master","ref":"master","sha":"5c029c377f3b785516ddd2d373a2db1f2b2ee66b","user":{"login":"odlgroup","id":15667171,"avatar_url":"https://avatars.githubusercontent.com/u/15667171?v=3","gravatar_id":"","url":"https://api.github.com/users/odlgroup","html_url":"https://github.com/odlgroup","followers_url":"https://api.github.com/users/odlgroup/followers","following_url":"https://api.github.com/users/odlgroup/following{/other_user}","gists_url":"https://api.github.com/users/odlgroup/gists{/gist_id}","starred_url":"https://api.github.com/users/odlgroup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odlgroup/subscriptions","organizations_url":"https://api.github.com/users/odlgroup/orgs","repos_url":"https://api.github.com/users/odlgroup/repos","events_url":"https://api.github.com/users/odlgroup/events{/privacy}","received_events_url":"https://api.github.com/users/odlgroup/received_events","type":"Organization","site_admin":false},"repo":{"id":45596393,"name":"odl","full_name":"odlgroup/odl","owner":{"login":"odlgroup","id":15667171,"avatar_url":"https://avatars.githubusercontent.com/u/15667171?v=3","gravatar_id":"","url":"https://api.github.com/users/odlgroup","html_url":"https://github.com/odlgroup","followers_url":"https://api.github.com/users/odlgroup/followers","following_url":"https://api.github.com/users/odlgroup/following{/other_user}","gists_url":"https://api.github.com/users/odlgroup/gists{/gist_id}","starred_url":"https://api.github.com/users/odlgroup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odlgroup/subscriptions","organizations_url":"https://api.github.com/users/odlgroup/orgs","repos_url":"https://api.github.com/users/odlgroup/repos","events_url":"https://api.github.com/users/odlgroup/events{/privacy}","received_events_url":"https://api.github.com/users/odlgroup/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/odlgroup/odl","description":"Operator Discretization Library","fork":false,"url":"https://api.github.com/repos/odlgroup/odl","forks_url":"https://api.github.com/repos/odlgroup/odl/forks","keys_url":"https://api.github.com/repos/odlgroup/odl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/odlgroup/odl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/odlgroup/odl/teams","hooks_url":"https://api.github.com/repos/odlgroup/odl/hooks","issue_events_url":"https://api.github.com/repos/odlgroup/odl/issues/events{/number}","events_url":"https://api.github.com/repos/odlgroup/odl/events","assignees_url":"https://api.github.com/repos/odlgroup/odl/assignees{/user}","branches_url":"https://api.github.com/repos/odlgroup/odl/branches{/branch}","tags_url":"https://api.github.com/repos/odlgroup/odl/tags","blobs_url":"https://api.github.com/repos/odlgroup/odl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/odlgroup/odl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/odlgroup/odl/git/refs{/sha}","trees_url":"https://api.github.com/repos/odlgroup/odl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/odlgroup/odl/statuses/{sha}","languages_url":"https://api.github.com/repos/odlgroup/odl/languages","stargazers_url":"https://api.github.com/repos/odlgroup/odl/stargazers","contributors_url":"https://api.github.com/repos/odlgroup/odl/contributors","subscribers_url":"https://api.github.com/repos/odlgroup/odl/subscribers","subscription_url":"https://api.github.com/repos/odlgroup/odl/subscription","commits_url":"https://api.github.com/repos/odlgroup/odl/commits{/sha}","git_commits_url":"https://api.github.com/repos/odlgroup/odl/git/commits{/sha}","comments_url":"https://api.github.com/repos/odlgroup/odl/comments{/number}","issue_comment_url":"https://api.github.com/repos/odlgroup/odl/issues/comments{/number}","contents_url":"https://api.github.com/repos/odlgroup/odl/contents/{+path}","compare_url":"https://api.github.com/repos/odlgroup/odl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/odlgroup/odl/merges","archive_url":"https://api.github.com/repos/odlgroup/odl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/odlgroup/odl/downloads","issues_url":"https://api.github.com/repos/odlgroup/odl/issues{/number}","pulls_url":"https://api.github.com/repos/odlgroup/odl/pulls{/number}","milestones_url":"https://api.github.com/repos/odlgroup/odl/milestones{/number}","notifications_url":"https://api.github.com/repos/odlgroup/odl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/odlgroup/odl/labels{/name}","releases_url":"https://api.github.com/repos/odlgroup/odl/releases{/id}","deployments_url":"https://api.github.com/repos/odlgroup/odl/deployments","created_at":"2015-11-05T07:57:55Z","updated_at":"2016-02-03T10:05:06Z","pushed_at":"2016-05-04T13:07:28Z","git_url":"git://github.com/odlgroup/odl.git","ssh_url":"git@github.com:odlgroup/odl.git","clone_url":"https://github.com/odlgroup/odl.git","svn_url":"https://github.com/odlgroup/odl","homepage":null,"size":16395,"stargazers_count":3,"watchers_count":3,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":101,"forks":3,"open_issues":101,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/odlgroup/odl/pulls/380"},"html":{"href":"https://github.com/odlgroup/odl/pull/380"},"issue":{"href":"https://api.github.com/repos/odlgroup/odl/issues/380"},"comments":{"href":"https://api.github.com/repos/odlgroup/odl/issues/380/comments"},"review_comments":{"href":"https://api.github.com/repos/odlgroup/odl/pulls/380/comments"},"review_comment":{"href":"https://api.github.com/repos/odlgroup/odl/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/odlgroup/odl/pulls/380/commits"},"statuses":{"href":"https://api.github.com/repos/odlgroup/odl/statuses/e9ad1407f322a9e2867701ca29ba710f284c1d2e"}}}}