Skip to content

Commit

Permalink
Merge pull request #5 from slimgroup/misc
Browse files Browse the repository at this point in the history
Misc
  • Loading branch information
mloubout authored Aug 8, 2022
2 parents 9d78d7e + 1f91a3a commit b86f1b4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

include:
- os: macos-latest
version: '1.5'
version: '1.7'
arch: x64

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ jobs:
steps:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.TAGBOT_PAT }}
ssh: ${{ secrets.DOCUMENTER_KEY }}
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SlimOptim"
uuid = "e4c7bc62-5b23-4522-a1b9-71c2be45f1df"
authors = ["Mathias Louboutin <mathias.louboutin@gmail.com>"]
version = "0.1.9"
version = "0.1.10"

This comment has been minimized.

Copy link
@mloubout

mloubout Aug 8, 2022

Author Member

[deps]
LineSearches = "d3d80556-e9d4-5f37-9878-2ab0fcc64255"
Expand Down
30 changes: 18 additions & 12 deletions src/bregman.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mutable struct BregmanParams
spg
TD
λfunc
reset_λ
end

"""
Expand All @@ -33,17 +34,19 @@ Options structure for the bregman iteration algorithm
- `λ`: a pre-set threshold, will only be used if `λfunc` is not defined, default is nothing
- `quantile`: a percentage to calculate the threshold by quantile of the dual variable in 1st iteration, will only be used if neither `λfunc` nor `λ` are defined, default is .95 i.e thresholds 95% of the vector
- `w`: a weight vector that is applied on the threshold element-wise according to relaxation of weighted l1, default is 1 (no weighting)
- `reset_lambda`: How often should lambda be updated. Defaults to `nothing` i.e lambda is nerver updated and estimated at the first iteration.
"""
function bregman_options(;verbose=1, progTol=1e-8, maxIter=20, store_trace=false, antichatter=true, alpha=.5, spg=false, TD=LinearAlgebra.I, quantile=.95, λ=nothing, λfunc=nothing, w=1)
function bregman_options(;verbose=1, progTol=1e-8, maxIter=20, store_trace=false, antichatter=true, alpha=.5,
spg=false, TD=LinearAlgebra.I, quantile=.95, λ=nothing, λfunc=nothing, w=1,
reset_lambda=nothing)
if isnothing(λfunc)
if ~isnothing(λ)
λfunc = z->λ
else
λfunc = z->Statistics.quantile(abs.(z), quantile)
end
end
return BregmanParams(verbose, progTol, maxIter, store_trace, antichatter, alpha, spg, TD, z->w.*λfunc(z))
return BregmanParams(verbose, progTol, maxIter, store_trace, antichatter, alpha, spg, TD, z->w.*λfunc(z), reset_lambda)
end

"""
Expand Down Expand Up @@ -119,7 +122,7 @@ function bregman(funobj::Function, x::AbstractVector{T}, options::BregmanParams=
# Initialize variables
z = options.TD*x
d = similar(z)
options.spg && (gold = similar(x); xold=similar(x))
options.spg && (gold = deepcopy(x); xold = deepcopy(x))
if options.antichatter
tk = 0 * z
end
Expand All @@ -136,11 +139,10 @@ function bregman(funobj::Function, x::AbstractVector{T}, options::BregmanParams=
for i=1:options.maxIter
f, g = funobj(x)
# Preconditionned ipdate direction
d .= -options.TD*g
d .= -(options.TD*g)
# Step length
t = (options.spg && i> 1) ? T(dot(x-xold, x-xold)/dot(x-xold, g-gold)) : T(options.alpha*f/norm(d)^2)
t = abs(t)
mul!(d, d, t)
t = (options.spg) ? T(dot(x-xold, x-xold)/dot(x-xold, g-gold)) : T(options.alpha*f/norm(d)^2)
scale!(d, t)

# Anti-chatter
if options.antichatter
Expand All @@ -155,7 +157,7 @@ function bregman(funobj::Function, x::AbstractVector{T}, options::BregmanParams=
# Update z variable
@. z = z + d
# Get λ at first iteration
(i == 1) && (sol.λ = abs.(T.(options.λfunc(z))))
set_λ!(sol, z, options, i, options.reset_λ)
# Save curent state
options.spg && (gold .= g; xold .= x)
# Update x
Expand All @@ -172,10 +174,10 @@ function bregman(funobj::Function, x::AbstractVector{T}, options::BregmanParams=
return sol
end

function bregman(funobj::Function, x::AbstractVector{T}, options::BregmanParams, TD) where {T}
function bregman(funobj::Function, x::AbstractVector{T}, options::BregmanParams, TD; kw...) where {T}
@warn "deprecation warning: please put TD in options (BregmanParams) for version > 0.1.7; now overwritting TD in BregmanParams"
options.TD = TD
return bregman(funobj, x, options)
return bregman(funobj, x, options; kw...)
end

"""
Expand Down Expand Up @@ -210,4 +212,8 @@ function breglog(init_x, init_z; lambda0=0, f0=0, obj0=0)
return BregmanIterations(1*init_x, 1*init_z, 0*init_z, f0, lambda0, obj0, Vector{}(), Vector{}(), Vector{}(), Vector{}())
end

noop_callback(::BregmanIterations) = nothing
noop_callback(::BregmanIterations) = nothing
scale!(d, t) = (t == 0 || !isLegal(t)) ? lmul!(1/norm(d)^2, d) : lmul!(abs(t), d)

set_λ!(sol::BregmanIterations, z::AbstractVector{T}, options::BregmanParams, s, ::Nothing) where {T} = (s == 1) ? set_λ!(sol, z, options, s, 1) : nothing
set_λ!(sol::BregmanIterations, z::AbstractVector{T}, options::BregmanParams, s::Integer, rs::Integer) where {T} = (s % rs == 0 || s == 1) ? (sol.λ = abs.(T.(options.λfunc(z)))) : nothing

1 comment on commit b86f1b4

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/65856

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.10 -m "<description of version>" b86f1b4458a48a28147ca4a40ce531f522392b9d
git push origin v0.1.10

Please sign in to comment.