-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add callback to all three algorithms
- Loading branch information
Showing
7 changed files
with
118 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <[email protected]>"] | ||
version = "0.1.8" | ||
version = "0.1.9" | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
[deps] | ||
LineSearches = "d3d80556-e9d4-5f37-9878-2ab0fcc64255" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Author: Mathias Louboutin, [email protected] | ||
# Date: December 2020 | ||
|
||
using LinearAlgebra, SlimOptim | ||
|
||
N = 10 | ||
|
||
A = Diagonal(1:N) | ||
|
||
function proj(x) | ||
xp = deepcopy(x) | ||
xp[xp .< 0] .= 0 | ||
return xp | ||
end | ||
|
||
x0 = 10 .+ 10 .* rand(N) | ||
b = A*x0 | ||
|
||
function obj(x) | ||
fun = .5*norm(A*x - b)^2 | ||
grad = A'*(A*x - b) | ||
return fun, grad | ||
end | ||
|
||
function mycallback(sol::result) | ||
# Print some info. ϕ_trace contains initial value so iteration is lenght-1 | ||
println("Bonjour at iteration $(length(sol.ϕ_trace)-1) with misfit value of $(sol.ϕ)") | ||
println("Norm of solution is $(norm(sol.x))") | ||
nothing | ||
end | ||
|
||
function mycallback(sol::BregmanIterations) | ||
# Print some info. ϕ_trace contains initial value so iteration is lenght-1 | ||
println("Bonjour at iteration $(length(sol.ϕ_trace)-1) with misfit value of $(sol.ϕ)") | ||
println("Norm of solution are $(norm(sol.x)), $(norm(sol.z))") | ||
nothing | ||
end | ||
|
||
# PQN | ||
sol = pqn(obj, randn(N), proj) | ||
sol = pqn(obj, randn(N), proj, callback=mycallback) | ||
|
||
# SPG | ||
sol = spg(obj, randn(N), proj) | ||
sol = spg(obj, randn(N), proj, callback=mycallback) | ||
|
||
# Bregman | ||
sol = bregman(A, zeros(Float32, N), A*randn(Float32, N)) | ||
sol = bregman(A, zeros(Float32, N), A*randn(Float32, N); callback=mycallback) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 comment
on commit 1a9a33a
There was a problem hiding this comment.
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/63419
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.9 -m "<description of version>" 1a9a33a7470e54012a023f69d704a6ecc7d2a0af
git push origin v0.1.9
@JuliaRegistrator register