src/Denoise.jl

Thu, 19 Sep 2024 21:30:26 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Thu, 19 Sep 2024 21:30:26 -0500
changeset 67
fe38c518e67e
parent 53
f8a3bc920f6a
permissions
-rw-r--r--

Print ∑_{i=0}^N} 𝒢(x^{k+1}; x^k) as value

9
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1 ########################################################
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
2 # Basic TV denoising via primal–dual proximal splitting
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
3 ########################################################
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
4
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
5 __precompile__()
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
6
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
7 module Denoise
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
8
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
9 using AlgTools.Util
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
10 import AlgTools.Iterate
53
f8a3bc920f6a Fix some `using` to be relative.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
11 using ..Gradient
9
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
12
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
13 ##############
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
14 # Our exports
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
15 ##############
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
16
28
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
17 export denoise_pdps,
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
18 denoise_fista
9
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
19
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
20 #############
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
21 # Data types
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
22 #############
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
23
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
24 ImageSize = Tuple{Integer,Integer}
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
25 Image = Array{Float64,2}
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
26 Primal = Image
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
27 Dual = Array{Float64,3}
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
28
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
29 #########################
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
30 # Iterate initialisation
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
31 #########################
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
32
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
33 function init_rest(x::Primal)
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
34 imdim=size(x)
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
35
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
36 y = zeros(2, imdim...)
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
37 Δx = copy(x)
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
38 Δy = copy(y)
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
39 x̄ = copy(x)
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
40
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
41 return x, y, Δx, Δy, x̄
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
42 end
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
43
28
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
44 function init_primal(xinit::Image, b)
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
45 return copy(xinit)
9
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
46 end
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
47
28
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
48 function init_primal(xinit::Nothing, b :: Image)
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
49 return zeros(size(b)...)
9
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
50 end
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
51
28
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
52
9
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
53 ############
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
54 # Algorithm
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
55 ############
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
56
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
57 function denoise_pdps(b :: Image;
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
58 xinit :: Union{Image,Nothing} = nothing,
46
46053b3af251 typofix
Tuomo Valkonen <tuomov@iki.fi>
parents: 28
diff changeset
59 iterate = Iterate.simple_iterate,
28
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
60 params::NamedTuple)
9
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
61
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
62 ################################
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
63 # Extract and set up parameters
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
64 ################################
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
65
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
66 α, ρ = params.α, params.ρ
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
67 τ₀, σ₀ = params.τ₀, params.σ₀
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
68
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
69 R_K = ∇₂_norm₂₂_est
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
70 γ = 1
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
71
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
72 @assert(τ₀*σ₀ < 1)
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
73 σ = σ₀/R_K
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
74 τ = τ₀/R_K
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
75
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
76 ######################
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
77 # Initialise iterates
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
78 ######################
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
79
28
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
80 x, y, Δx, Δy, x̄ = init_rest(init_primal(xinit, b))
9
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
81
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
82 ####################
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
83 # Run the algorithm
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
84 ####################
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
85
67
fe38c518e67e Print ∑_{i=0}^N} 𝒢(x^{k+1}; x^k) as value
Tuomo Valkonen <tuomov@iki.fi>
parents: 53
diff changeset
86 q = norm₂²(b-x)/2
fe38c518e67e Print ∑_{i=0}^N} 𝒢(x^{k+1}; x^k) as value
Tuomo Valkonen <tuomov@iki.fi>
parents: 53
diff changeset
87 cum = 0.0
fe38c518e67e Print ∑_{i=0}^N} 𝒢(x^{k+1}; x^k) as value
Tuomo Valkonen <tuomov@iki.fi>
parents: 53
diff changeset
88
9
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
89 v = iterate(params) do verbose :: Function
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
90 ω = params.accel ? 1/√(1+2*γ*τ) : 1
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
91
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
92 ∇₂ᵀ!(Δx, y) # primal step:
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
93 @. x̄ = x # | save old x for over-relax
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
94 @. x = (x-τ*(Δx-b))/(1+τ) # | prox
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
95 @. x̄ = (1+ω)*x - ω*x̄ # over-relax: x̄ = 2x-x_old
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
96 ∇₂!(Δy, x̄) # dual step: y
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
97 @. y = (y + σ*Δy)/(1 + σ*ρ/α) # |
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
98 proj_norm₂₁ball!(y, α) # | prox
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
99
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
100 if params.accel
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
101 τ, σ = τ*ω, σ/ω
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
102 end
67
fe38c518e67e Print ∑_{i=0}^N} 𝒢(x^{k+1}; x^k) as value
Tuomo Valkonen <tuomov@iki.fi>
parents: 53
diff changeset
103
fe38c518e67e Print ∑_{i=0}^N} 𝒢(x^{k+1}; x^k) as value
Tuomo Valkonen <tuomov@iki.fi>
parents: 53
diff changeset
104 qnew = norm₂²(b-x)/2
fe38c518e67e Print ∑_{i=0}^N} 𝒢(x^{k+1}; x^k) as value
Tuomo Valkonen <tuomov@iki.fi>
parents: 53
diff changeset
105 cum = qnew - q + dot(∇y, x) - dot(∇x, y)
fe38c518e67e Print ∑_{i=0}^N} 𝒢(x^{k+1}; x^k) as value
Tuomo Valkonen <tuomov@iki.fi>
parents: 53
diff changeset
106 q = qnew
fe38c518e67e Print ∑_{i=0}^N} 𝒢(x^{k+1}; x^k) as value
Tuomo Valkonen <tuomov@iki.fi>
parents: 53
diff changeset
107
9
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
108 ################################
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
109 # Give function value if needed
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
110 ################################
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
111 v = verbose() do
67
fe38c518e67e Print ∑_{i=0}^N} 𝒢(x^{k+1}; x^k) as value
Tuomo Valkonen <tuomov@iki.fi>
parents: 53
diff changeset
112 #∇₂!(Δy, x)
fe38c518e67e Print ∑_{i=0}^N} 𝒢(x^{k+1}; x^k) as value
Tuomo Valkonen <tuomov@iki.fi>
parents: 53
diff changeset
113 #value = norm₂²(b-x)/2 + params.α*γnorm₂₁(Δy, params.ρ)
fe38c518e67e Print ∑_{i=0}^N} 𝒢(x^{k+1}; x^k) as value
Tuomo Valkonen <tuomov@iki.fi>
parents: 53
diff changeset
114 cum, x
9
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
115 end
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
116
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
117 v
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
118 end
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
119
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
120 return x, y, v
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
121 end
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
122
28
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
123 function denoise_fista(b :: Image;
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
124 xinit :: Union{Image,Nothing} = nothing,
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
125 iterate = AlgTools.simple_iterate,
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
126 params::NamedTuple)
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
127
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
128 ################################
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
129 # Extract and set up parameters
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
130 ################################
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
131
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
132 α, ρ = params.α, params.ρ
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
133 τ₀ = params.τ₀
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
134 τ = τ₀/∇₂_norm₂₂_est²
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
135
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
136 ######################
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
137 # Initialise iterates
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
138 ######################
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
139
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
140 x = init_primal(xinit, b)
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
141 imdim = size(x)
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
142 Δx = similar(x)
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
143 y = zeros(2, imdim...)
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
144 ỹ = copy(y)
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
145 y⁻ = similar(y)
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
146 Δy = similar(y)
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
147
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
148 ####################
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
149 # Run the algorithm
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
150 ####################
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
151
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
152 t = 0
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
153
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
154 v = iterate(params) do verbose :: Function
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
155 ∇₂ᵀ!(Δx, ỹ)
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
156 @. Δx .-= b
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
157 ∇₂!(Δy, Δx)
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
158 @. y⁻ = y
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
159 @. y = (ỹ - τ*Δy)/(1 + τ*ρ/α)
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
160 proj_norm₂₁ball!(y, α)
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
161 t⁺ = (1+√(1+4*t^2))/2
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
162 @. ỹ = y+((t-1)/t⁺)*(y-y⁻)
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
163 t = t⁺
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
164
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
165 ################################
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
166 # Give function value if needed
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
167 ################################
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
168 v = verbose() do
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
169 ∇₂ᵀ!(Δx, y)
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
170 @. x = b - Δx
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
171 ∇₂!(Δy, x)
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
172 value = norm₂²(b-x)/2 + params.α*γnorm₂₁(Δy, params.ρ)
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
173 value, x
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
174 end
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
175
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
176 v
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
177 end
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
178
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
179 ∇₂ᵀ!(Δx, y)
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
180 @. x = b - Δx
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
181
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
182 return x, y, v
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
183 end
d1f40f6654cb denoise_fista
Tuomo Valkonen <tuomov@iki.fi>
parents: 9
diff changeset
184
9
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
185 end # Module
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
186
1cffd3d07fe2 Denoising routine for testing + visualisation tools
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
187

mercurial