-
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.
- Deprecate callback, storecosts and storetrajectory in options - Move callback out of options to explicit input argument - Use callback for getting costs/trajectory
- Loading branch information
1 parent
2ef74d3
commit 2fcf7b0
Showing
17 changed files
with
228 additions
and
87 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
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
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,54 @@ | ||
import Printf.@printf | ||
|
||
# Default: do nothing | ||
nullcallback(cost, unusedargs...) = (cost, 0) | ||
|
||
# Print out per-iteration results | ||
function printoutcallback(cost, problem, data, trailingargs...) | ||
if data.iternum == 1 | ||
# First iteration, so print out column headers and the zeroth iteration (i.e. start) values | ||
println("iter cost cost_change |step|") | ||
@printf("% 4d % 8e % 4.3e % 3.2e\n", 0, data.bestcost, 0, 0) | ||
end | ||
@printf("% 4d % 8e % 4.3e % 3.2e\n", data.iternum, cost, data.bestcost-cost, norm(data.linsystem.x)) | ||
return cost, 0 | ||
end | ||
function printoutcallback(cost, data, trradius::Float64) | ||
if data.iternum == 1 | ||
# First iteration, so print out column headers and the zeroth iteration (i.e. start) values | ||
println("iter cost cost_change |step| tr_radius") | ||
@printf("% 4d % 8e % 4.3e % 3.2e % 2.1e\n", 0, data.bestcost, 0, 0, trradius) | ||
end | ||
@printf("% 4d % 8e % 4.3e % 3.2e % 2.1e\n", data.iternum, cost, data.bestcost-cost, norm(data.linsystem.x), trradius) | ||
return cost, 0 | ||
end | ||
|
||
# Store per-iteration costs | ||
function storecostscallback(costs::Vector{Float64}, cost, unusedargs...) | ||
push!(costs, cost) | ||
return (cost, 0) | ||
end | ||
|
||
struct CostTrajectory | ||
costs::Vector{Float64} | ||
trajectory::Vector{Vector{Float64}} | ||
|
||
function CostTrajectory() | ||
return new(sizehint!(Vector{Float64}(), 50), sizehint!(Vector{Vector{Float64}}(), 50)) | ||
end | ||
end | ||
function Base.empty!(ct::CostTrajectory) | ||
empty!(ct.costs) | ||
empty!(ct.trajectory) | ||
return ct | ||
end | ||
|
||
# Store per-iteration costs and trajectory | ||
function storecostscallback(store::CostTrajectory, cost, problem, data, unusedargs...) | ||
push!(store.costs, cost) | ||
push!(store.trajectory, Vector{Float64}(data.linsystem.x)) | ||
return (cost, 0) | ||
end | ||
|
||
# Callback function generator | ||
storecostscallback(store) = (args...) -> storecostscallback(store, args...) |
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
Oops, something went wrong.
1 comment
on commit 2fcf7b0
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/91797
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 v3.2.0 -m "<description of version>" 2fcf7b0cab51e63c1c8968ee93b3abbb77bcb801
git push origin v3.2.0
@JuliaRegistrator register