Skip to content

Commit

Permalink
Julia 1.0 update (#15)
Browse files Browse the repository at this point in the history
1.0 update
  • Loading branch information
nantonel committed Sep 22, 2018
1 parent c438551 commit 9922dd7
Show file tree
Hide file tree
Showing 22 changed files with 229 additions and 286 deletions.
33 changes: 8 additions & 25 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
## Documentation: http://docs.travis-ci.com/user/languages/julia/
# Documentation: http://docs.travis-ci.com/user/languages/julia/
language: julia
os:
- linux
- osx
julia:
- 0.6
- 0.7
- 1.0
- nightly
notifications:
email: false
git:
depth: 99999999

## uncomment the following lines to allow failures on nightly julia
## (tests will run but not make your overall status red)
matrix:
allow_failures:
- julia: nightly

## uncomment and modify the following lines to manually install system packages
#addons:
# apt: # apt-get for linux
# packages:
# - gfortran
#before_script: # homebrew for mac
# - if [ $TRAVIS_OS_NAME = osx ]; then brew install gcc; fi

## uncomment the following lines to override the default test script
#script:
# - julia -e 'Pkg.clone(pwd()); Pkg.build("ProximalAlgorithms"); Pkg.test("ProximalAlgorithms"; coverage=true)'
notifications:
email: false
after_success:
# push coverage results to Coveralls
- julia -e 'cd(Pkg.dir("ProximalAlgorithms")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
# push coverage results to Codecov
- julia -e 'cd(Pkg.dir("ProximalAlgorithms")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
- julia -e 'using Pkg; cd(Pkg.dir("ProximalAlgorithms")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder())'
- julia -e 'using Pkg; cd(Pkg.dir("ProximalAlgorithms")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
# - julia -e 'using Pkg; Pkg.add("Documenter"); cd(Pkg.dir("ProximalAlgorithms")); include(joinpath("docs", "make.jl"))'
6 changes: 3 additions & 3 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
julia 0.6
AbstractOperators 0.0.3
ProximalOperators 0.4.1
julia 0.7
AbstractOperators 0.1.0
ProximalOperators 0.8.0
51 changes: 23 additions & 28 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

## uncomment the following lines to allow failures on nightly julia
## (tests will run but not make your overall status red)
#matrix:
# allow_failures:
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
- julia_version: 0.7
- julia_version: 1
- julia_version: nightly

platform:
# - x86 # 32-bit
- x64 # 64-bit

matrix:
allow_failures:
- julia_version: 1
- julia_version: nightly

branches:
only:
Expand All @@ -24,24 +25,18 @@ notifications:
on_build_status_changed: false

install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# If there's a newer build queued for the same PR, cancel this one
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
throw "There are newer queued builds for this pull request, failing early." }
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$env:JULIA_URL,
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))

build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"ProximalAlgorithms\"); Pkg.build(\"ProximalAlgorithms\")"
- echo "%JL_BUILD_SCRIPT%"
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"ProximalAlgorithms\")"
- echo "%JL_TEST_SCRIPT%"
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"

# # Uncomment to support code coverage upload. Should only be enabled for packages
# # which would have coverage gaps without running on Windows
# on_success:
# - echo "%JL_CODECOV_SCRIPT%"
# - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%"
25 changes: 16 additions & 9 deletions src/ProximalAlgorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ module ProximalAlgorithms
using AbstractOperators
using AbstractOperators.BlockArrays
using ProximalOperators
using LinearAlgebra
using Printf

import Base: start, next, done
import Base: iterate

include("utilities/identity.jl")
include("utilities/zero.jl")
Expand All @@ -14,14 +16,18 @@ abstract type ProximalAlgorithm{I,T} end

# The following methods give `ProximalAlgorithm` objects the iterable behavior.

function start(solver::ProximalAlgorithm{I,T})::I where {I,T}
initialize!(solver)
return zero(I)
function iterate(solver::ProximalAlgorithm{I,T}) where {I,T}
point = initialize!(solver)
return (point, one(I))
end

function next(solver::ProximalAlgorithm{I,T}, it::I)::Tuple{T, I} where {I,T}
point = iterate!(solver, it)
return (point, it + one(I))
function iterate(solver::ProximalAlgorithm{I,T}, it::I) where {I,T}
if done(solver, it)
return nothing
else
point = iterate!(solver, it)
return (point, it + one(I))
end
end

function done(solver::ProximalAlgorithm{I,T}, it::I)::Bool where {I,T}
Expand All @@ -40,8 +46,9 @@ function run!(solver::ProximalAlgorithm{I,T})::Tuple{I,T} where {I,T}
# [...]
# end
# See: https://docs.julialang.org/en/stable/manual/interfaces
for (it, point) in enumerate(solver)
if verbose(solver, it) display(solver, it) end
for (it_, point_) in enumerate(solver)
if verbose(solver, it_) display(solver, it_) end
it, point = it_, point_
end
if verbose(solver) display(solver, it) end
return it, point
Expand Down
29 changes: 13 additions & 16 deletions src/algorithms/AsymmetricForwardBackwardAdjoint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ function AFBAIterator(x0::T1, y0::T2; g=IndFree(), h=IndFree(), f=IndFree(), l=I
lconj = Conjugate(l)

# default stepsizes
par = 4 # scale parameter for comparing Lipschitz constant and norm(L)
nmL = norm(L)
par = 4 # scale parameter for comparing Lipschitz constant and opnorm(L)
nmL = opnorm(L)
alpha = 1
if isa(h, ProximalOperators.IndFree) && (gamma1<0 || gamma2<0)
# mu=0 is the only case where stepsizes matter
Expand Down Expand Up @@ -86,11 +86,11 @@ function AFBAIterator(x0::T1, y0::T2; g=IndFree(), h=IndFree(), f=IndFree(), l=I
gamma2 = 0.99/(betaR/2+gamma1*nmL^2)
elseif theta==0 && mu==1 # default stepsize for theta=0, mu=1
temp=3
if betaQ > par*nmL && betaR > temp*par*nmL # denominator for Sigma involves 3α norm(L) in this case
if betaQ > par*nmL && betaR > temp*par*nmL # denominator for Sigma involves 3α opnorm(L) in this case
alpha = 1
elseif betaQ > par*nmL
alpha = 2*nmL/betaQ
elseif betaR > temp*par*nmL # denominator for Sigma involves 3α norm(L) in this case
elseif betaR > temp*par*nmL # denominator for Sigma involves 3α opnorm(L) in this case
alpha = betaR/(temp*2*nmL)
end
gamma1 = 1/(betaQ/2+nmL/alpha)
Expand All @@ -101,7 +101,7 @@ function AFBAIterator(x0::T1, y0::T2; g=IndFree(), h=IndFree(), f=IndFree(), l=I
alpha = 1
elseif betaR > par*nmL
alpha = betaR/(2*nmL)
elseif betaQ > temp*par*nmL # denominator for Sigma involves 3α norm(L) in this case
elseif betaQ > temp*par*nmL # denominator for Sigma involves 3α opnorm(L) in this case
alpha = 2*nmL*temp/betaQ
end
gamma2 = 1/(betaR/2+ alpha*nmL)
Expand All @@ -117,7 +117,7 @@ end
# Utility methods
maxit(sol::AFBAIterator) = sol.maxit

converged(sol::AFBAIterator, it) = it > 0 && vecnorm(sol.FPR_x)+vecnorm(sol.FPR_y) <= sol.tol
converged(sol::AFBAIterator, it) = it > 0 && norm(sol.FPR_x)+norm(sol.FPR_y) <= sol.tol

verbose(sol::AFBAIterator) = sol.verbose > 0
verbose(sol::AFBAIterator, it) = sol.verbose > 0 && (sol.verbose == 2 ? true : (it == 1 || it%sol.verbose_freq == 0))
Expand All @@ -128,7 +128,7 @@ function display(sol::AFBAIterator)
end

function display(sol::AFBAIterator, it)
@printf("%6d | %7.4e, %7.4e | %7.4e |\n", it, sol.gamma1, sol.gamma2, vecnorm(sol.FPR_x)+vecnorm(sol.FPR_y))
@printf("%6d | %7.4e, %7.4e | %7.4e |\n", it, sol.gamma1, sol.gamma2, norm(sol.FPR_x)+norm(sol.FPR_y))
end

function Base.show(io::IO, sol::AFBAIterator)
Expand All @@ -138,15 +138,15 @@ function Base.show(io::IO, sol::AFBAIterator)
else
println(io, "theta, mu : $(sol.theta), $(sol.mu)" )
end
println(io, "fpr : $(vecnorm(sol.FPR_x)+vecnorm(sol.FPR_y))")
println(io, "fpr : $(norm(sol.FPR_x)+norm(sol.FPR_y))")
print( io, "gamma1, gamma2 : $(sol.gamma1), $(sol.gamma2)")
end

################################################################################
# Initialization

function initialize!(sol::AFBAIterator)
return
return sol.x, sol.y
end

################################################################################
Expand All @@ -155,15 +155,15 @@ end
function iterate!(sol::AFBAIterator{I, R, T1, T2}, it::I) where {I, R, T1, T2}
# perform xbar-update step
gradient!(sol.gradf, sol.f, sol.x)
Ac_mul_B!(sol.temp_x, sol.L, sol.y)
mul!(sol.temp_x, sol.L', sol.y)
sol.temp_x .+= sol.gradf
sol.temp_x .*= -sol.gamma1
sol.temp_x .+= sol.x
prox!(sol.xbar, sol.g, sol.temp_x, sol.gamma1)
# perform ybar-update step
gradient!(sol.gradl, sol.lconj, sol.y)
sol.temp_x .= (sol.theta * sol.xbar) .+ ((1-sol.theta) * sol.x)
A_mul_B!(sol.temp_y, sol.L, sol.temp_x)
mul!(sol.temp_y, sol.L, sol.temp_x)
sol.temp_y .-= sol.gradl
sol.temp_y .*= sol.gamma2
sol.temp_y .+= sol.y
Expand All @@ -173,11 +173,11 @@ function iterate!(sol::AFBAIterator{I, R, T1, T2}, it::I) where {I, R, T1, T2}
sol.FPR_y .= sol.ybar .- sol.y
# perform x-update step
sol.temp_y .= sol.mu*(2-sol.theta)*sol.gamma1*sol.FPR_y
Ac_mul_B!(sol.temp_x, sol.L, sol.temp_y)
mul!(sol.temp_x, sol.L', sol.temp_y)
sol.x .+= sol.lam *(sol.FPR_x .- sol.temp_x)
# perform y-update step
sol.temp_x .= (1-sol.mu)*(2-sol.theta)*sol.gamma2*sol.FPR_x
A_mul_B!(sol.temp_y, sol.L, sol.temp_x)
mul!(sol.temp_y, sol.L, sol.temp_x)
sol.y .+= sol.lam *(sol.FPR_y .+ sol.temp_y)
return sol.x, sol.y
end
Expand Down Expand Up @@ -227,7 +227,6 @@ See [1, Figure 1] for other special cases and relation to other algorithms.
[2] Condat. "A primal–dual splitting method for convex optimization involving Lipschitzian, proximable and linear composite terms" Journal of Optimization Theory and Applications 158.2 (2013): 460-479.
[3] Vũ. "A splitting algorithm for dual monotone inclusions involving cocoercive operators"" Advances in Computational Mathematics, 38(3), pp.667-681.
"""

function AFBA(x0, y0; kwargs...)
# Create iterable
sol = AFBAIterator(x0, y0; kwargs...)
Expand All @@ -252,7 +251,6 @@ Points `x0` and `y0` are the initial primal and dual iterates, respectively.
See documentation of `AFBA` for the list of keyword arguments.
"""

function VuCondat(x0, y0; kwargs...)
# Create iterable
sol = AFBAIterator(x0, y0; kwargs..., theta=2)
Expand All @@ -276,7 +274,6 @@ Points `x0` and `y0` are the initial primal and dual iterates, respectively.
See documentation of `AFBA` for the list of keyword arguments.
"""

function ChambollePock(x0, y0; kwargs...)
# Create iterable
sol = AFBAIterator(x0, y0; kwargs..., f=IndFree(), theta=2)
Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/DouglasRachford.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ end
# Initialization

function initialize!(sol::DRSIterator)
return
return sol.z
end

################################################################################
# Iteration

function iterate!(sol::DRSIterator{I, T}, it::I) where {I, T}
prox!(sol.y, sol.f, sol.x, sol.gamma)
sol.r .= 2.*sol.y .- sol.x
sol.r .= 2 .*sol.y .- sol.x
prox!(sol.z, sol.g, sol.r, sol.gamma)
sol.FPR_x .= sol.y .- sol.z
sol.x .-= sol.FPR_x
Expand Down

0 comments on commit 9922dd7

Please sign in to comment.