-
Notifications
You must be signed in to change notification settings - Fork 4
/
ProShI.jl
158 lines (131 loc) · 4.49 KB
/
ProShI.jl
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# Latafat, Themelis, Patrinos, "Block-coordinate and incremental aggregated
# proximal gradient methods for nonsmooth nonconvex problems."
# arXiv:1906.10053 (2019).
#
using LinearAlgebra
using ProximalOperators
using ProximalAlgorithms.IterationTools
using Printf
using Base.Iterators
using Random
using StatsBase: sample
export solution
include("ProShI_basic.jl")
struct Proshi{R<:Real}
γ::Maybe{Union{Array{R},R}}
sweeping::Int8
minibatch::Tuple{Bool,Int}
maxit::Int
verbose::Bool
freq::Int
α::R
function Proshi{R}(;
γ::Maybe{Union{Array{R},R}} = nothing,
sweeping = 1,
minibatch::Tuple{Bool,Int} = (false, 1),
maxit::Int = 10000,
verbose::Bool = false,
freq::Int = 10000,
α::R = R(0.999),
) where {R}
@assert γ === nothing || minimum(γ) > 0
@assert maxit > 0
@assert freq > 0
new(γ, sweeping, minibatch, maxit, verbose, freq, α)
end
end
function (solver::Proshi{R})(
x0::AbstractArray{C};
F = nothing,
g = ProximalOperators.Zero(),
L = nothing,
N = N,
) where {R,C<:RealOrComplex{R}}
stop(state) = false
disp(it, state) = @printf "%5d | %.3e \n" it state.hat_γ
F === nothing && (F = fill(ProximalOperators.Zero(), (N,)))
# dispatching the iterator
iter = Proshi_basic_iterable(
F,
g,
x0,
N,
L,
solver.γ,
solver.sweeping,
solver.minibatch[2],
solver.α,
)
iter = take(halt(iter, stop), solver.maxit)
iter = enumerate(iter)
num_iters, state_final = nothing, nothing
for (it_, state_) in iter # unrolling the iterator
# see https://docs.julialang.org/en/v1/manual/interfaces/index.html
if solver.verbose && mod(it_, solver.freq) == 0
disp(it_, state_)
end
num_iters, state_final = it_, state_
end
if solver.verbose && mod(num_iters, solver.freq) !== 0
disp(num_iters, state_final)
end # for the final iteration
return solution(state_final), num_iters
end
"""
Proshi([γ, sweeping, LProshi, adaptive, minibatch, maxit, verbose, freq, tol, tol_b])
Instantiate the Proshi algorithm for solving fully nonconvex optimization problems of the form
minimize 1/N sum_{i=1}^N f_i(x) + g(x)
where `f_i` are smooth and `g` is possibly nonsmooth, all of which may be nonconvex.
If `solver = Proshi(args...)`, then the above problem is solved with
solver(x0, [F, g, N, L])
where F is an array containing f_i's, x0 is the initial point, and L is an array of
smoothness moduli of f_i's; it is optional in the adaptive mode or if γ is provided.
Optional keyword arguments are:
* `γ`: an array of N stepsizes for each coordinate
* `sweeping::Int` 1 for uniform randomized (default), 2 for cyclic, 3 for shuffled
* `LProshi::Bool` low memory variant of the Proshi/MISO algorithm
* `adaptive::Bool` to activate adaptive smoothness parameter computation
* `minibatch::(Bool,Int)` to use batchs of a given size
* `maxit::Integer` (default: `10000`), maximum number of iterations to perform.
* `verbose::Bool` (default: `true`), whether or not to print information during the iterations.
* `freq::Integer` (default: `10000`), frequency of verbosity.
* `α::R` parameter where γ_i = αN/L_i
* `tol::Real` (default: `1e-8`), absolute tolerance for the adaptive case
* `tol_b::R` tolerance for the backtrack (default: `1e-9`)
"""
Proshi(::Type{R}; kwargs...) where {R} = Proshi{R}(; kwargs...)
Proshi(; kwargs...) = Proshi(Float64; kwargs...)
"""
If `solver = Proshi(args...)`, then
itr = iterator(solver, x0, [F, g, N, L])
is an iterable object. Note that [maxit, verbose, freq] fields of the solver are ignored here.
The solution at any given state can be obtained using solution(state), e.g.,
for state in Iterators.take(itr, maxit)
# do something using solution(state)
end
See https://docs.julialang.org/en/v1/manual/interfaces/index.html
and https://docs.julialang.org/en/v1/base/iterators/ for a list of iteration utilities
"""
function iterator(
solver::Proshi{R},
x0::AbstractArray{C};
F = nothing,
g = ProximalOperators.Zero(),
L = nothing,
N = N,
) where {R,C<:RealOrComplex{R}}
F === nothing && (F = fill(ProximalOperators.Zero(), (N,)))
# dispatching the iterator
iter = Proshi_basic_iterable(
F,
g,
x0,
N,
L,
solver.γ,
solver.sweeping,
solver.minibatch[2],
solver.α,
)
return iter
end