Commit 18720d13 authored by Guillaume Garrigos's avatar Guillaume Garrigos
Browse files

upload tp4

parent 325c8413
File added
import numpy as np
import invprob
from invprob import prox
from invprob.signal import dct2, idct2, gaussian_kernel
############################################
# This is for deblurring inverse problem
kernel_size = 3
kernel_std = 1
im_shape = (128,128)
kernel_fourier = gaussian_kernel(kernel_size, kernel_std, im_shape)
def flou(x): # La fonction qui permet d'évaluer A@x
return np.real(idct2(dct2(x) * kernel_fourier))
Lipschitz_flou = np.max(np.abs(kernel_fourier)) # Ceci est la constante de Lipschitz du gradient de la fonction quadratique
############################################
# this is for doing prox with TV norm
def prox_infty(x, s=1):
# Prox operator of the sup/infty norm
# We use Moreau's decomposition theorem: the dual of the sup norm is the indicator of the L1 unit ball
return x - prox.L1_ball(x, s)
def TV(x):
return np.sum(np.abs(invprob.signal.grad(x)))
def proj_TV_ball(a, s=1, init=None, itermax=200, tol=1e-4, stepsize=0.125):
# stepsize in ]0,1/4[
if init is not None:
x = init
else:
x = a
u = invprob.signal.grad(x) # dual vector
v = u
t = 1.0
for k in range(itermax):
u_temp = v - stepsize * invprob.signal.grad(a - invprob.signal.div(v)) # gradient step
u_temp = prox_infty(u_temp, stepsize*s) # prox step
alpha = t-1
t = (1 + np.sqrt( 1 + 4*t**2 ))/2
alpha = alpha / t
v = (1+alpha)*u_temp - alpha*u
if np.linalg.norm(u-u_temp)<tol:
print(k)
break
u = u_temp
return a - invprob.signal.div(v)
from ipywidgets import interactive
import matplotlib.pyplot as plt
import numpy as np
def widget_TV():
def f(b):
plt.figure(2)
p = proj_TV_ball(comete, b, itermax=200, tol=0.1)
imshow(p)
plt.show()
interactive_plot = interactive(f, b=(1, 2000, 10))
output = interactive_plot.children[-1]
output.layout.height = '350px'
interactive_plot
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment