@@ -0,0 +1,2246 @@
+# Copyright 2014-2018 The ODL contributors%0A#%0A# This file is part of ODL.%0A#%0A# This Source Code Form is subject to the terms of the Mozilla Public License,%0A# v. 2.0. If a copy of the MPL was not distributed with this file, You can%0A# obtain one at https://mozilla.org/MPL/2.0/.%0A%0A%22%22%22A simple example to get started with SPDHG %5BCERS2017%5D. The example at hand%0Asolves the ROF denoising problem.%0A%0AReference%0A---------%0A%5BCERS2017%5D A. Chambolle, M. J. Ehrhardt, P. Richtarik and C.-B. Schoenlieb,%0A*Stochastic Primal-Dual Hybrid Gradient Algorithm with Arbitrary Sampling%0Aand Imaging Applications*. ArXiv: http://arxiv.org/abs/1706.04957 (2017).%0A%22%22%22%0A%0Afrom __future__ import division, print_function%0Aimport odl%0Aimport odl.contrib.solvers.spdhg as spdhg%0Aimport odl.contrib.datasets.images as images%0Aimport numpy as np%0A%0A# set ground truth and data%0Aimage_gray = images.building(gray=True)%0AX = odl.uniform_discr(%5B0, 0%5D, image_gray.shape, image_gray.shape)%0Agroundtruth = X.element(image_gray)%0Adata = odl.phantom.white_noise(X, mean=groundtruth, stddev=0.1, seed=1807)%0A%0A# set parameter%0Aalpha = .12  # regularisation parameter%0Anepoch = 100%0A%0A# set functionals and operator%0AA = odl.BroadcastOperator(*%5Bodl.PartialDerivative(X, d, pad_mode='symmetric')%0A                            for d in %5B0, 1%5D%5D)%0Af = odl.solvers.SeparableSum(*%5Bodl.solvers.L1Norm(Yi) for Yi in A.range%5D)%0Ag = 1 / (2 * alpha) * odl.solvers.L2NormSquared(X).translated(data)%0A%0A# set sampling%0An = 2  # number of subsets%0Aprob = %5B1 / n%5D * n  # probablity that a subset gets selected%0AS = %5B%5B0%5D, %5B1%5D%5D  # all possible subsets to select from%0Adef fun_select(k):  # subset selection function%0A    return S%5Bint(np.random.choice(n, 1, p=prob))%5D%0A%0A# set parameters for algorithm%0AAi_norm = %5B2, 2%5D%0Agamma = 0.99%0Asigma = %5Bgamma / a for a in Ai_norm%5D%0Atau = gamma / (n * max(Ai_norm))%0A%0A# callback for output during the iterations%0Acb = (odl.solvers.CallbackPrintIteration(fmt='iter:%7B:4d%7D', step=n, end=', ') &%0A      odl.solvers.CallbackPrintTiming(fmt='time: %7B:5.2f%7D s', cumulative=True,%0A                                      step=n))%0A%0A# initialise variable and run algorithm%0Ax = X.zero()%0Aniter = 2 * nepoch%0Aspdhg.spdhg(x, f, g, A, tau, sigma, niter, prob, fun_select, callback=cb)%0A%0A# show data and output%0Adata.show()%0Ax.show()%0A

Add new example which is much much simpler