forked from JuliaFirstOrder/ProximalOperators.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtilt.jl
More file actions
42 lines (34 loc) · 1.19 KB
/
tilt.jl
File metadata and controls
42 lines (34 loc) · 1.19 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
# Tilting (addition with affine function)
export Tilt
"""
Tilt(f, a, b=0.0)
Given function `f`, an array `a` and a constant `b` (optional), return function
```math
g(x) = f(x) + \\langle a, x \\rangle + b.
```
"""
struct Tilt{T, S, R}
f::T
a::S
b::R
end
is_separable(::Type{<:Tilt{T}}) where T = is_separable(T)
is_proximable(::Type{<:Tilt{T}}) where T = is_proximable(T)
is_convex(::Type{<:Tilt{T}}) where T = is_convex(T)
is_singleton_indicator(::Type{<:Tilt{T}}) where T = is_singleton_indicator(T)
is_smooth(::Type{<:Tilt{T}}) where T = is_smooth(T)
is_locally_smooth(::Type{<:Tilt{T}}) where T = is_locally_smooth(T)
is_generalized_quadratic(::Type{<:Tilt{T}}) where T = is_generalized_quadratic(T)
is_strongly_convex(::Type{<:Tilt{T}}) where T = is_strongly_convex(T)
Tilt(f::T, a::S) where {T, S} = Tilt{T, S, real(eltype(S))}(f, a, real(eltype(S))(0))
function (g::Tilt)(x)
return g.f(x) + real(dot(g.a, x)) + g.b
end
function prox!(y, g::Tilt, x, gamma)
v = prox!(y, g.f, x .- gamma .* g.a, gamma)
return v + real(dot(g.a, y)) + g.b
end
function prox_naive(g::Tilt, x, gamma)
y, v = prox_naive(g.f, x .- gamma .* g.a, gamma)
return y, v + real(dot(g.a, y)) + g.b
end