forked from JuliaFirstOrder/ProximalOperators.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranslate.jl
More file actions
48 lines (41 loc) · 1.3 KB
/
translate.jl
File metadata and controls
48 lines (41 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
export Translate
"""
Translate(f, b)
Return the translated function
```math
g(x) = f(x + b)
```
"""
struct Translate{T, V}
f::T
b::V
end
is_separable(::Type{<:Translate{T}}) where T = is_separable(T)
is_proximable(::Type{<:Translate{T}}) where T = is_proximable(T)
is_convex(::Type{<:Translate{T}}) where T = is_convex(T)
is_set_indicator(::Type{<:Translate{T}}) where T = is_set_indicator(T)
is_singleton_indicator(::Type{<:Translate{T}}) where T = is_singleton_indicator(T)
is_cone_indicator(::Type{<:Translate{T}}) where T = is_cone_indicator(T)
is_affine_indicator(::Type{<:Translate{T}}) where T = is_affine_indicator(T)
is_smooth(::Type{<:Translate{T}}) where T = is_smooth(T)
is_locally_smooth(::Type{<:Translate{T}}) where T = is_locally_smooth(T)
is_generalized_quadratic(::Type{<:Translate{T}}) where T = is_generalized_quadratic(T)
is_strongly_convex(::Type{<:Translate{T}}) where T = is_strongly_convex(T)
function (g::Translate)(x)
return g.f(x .+ g.b)
end
function gradient!(y, g::Translate, x)
z = x .+ g.b
v = gradient!(y, g.f, z)
return v
end
function prox!(y, g::Translate, x, gamma)
z = x .+ g.b
v = prox!(y, g.f, z, gamma)
y .-= g.b
return v
end
function prox_naive(g::Translate, x, gamma)
y, v = prox_naive(g.f, x .+ g.b, gamma)
return y - g.b, v
end