Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [RFC!] Refactoring... #266

Merged
merged 20 commits into from
Sep 26, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Collect traces, and add ParticleSwarm to the mix.
  • Loading branch information
pkofod committed Sep 18, 2016
commit f011980e809a19f13cb80b8f733bcd41bb581b50
2 changes: 1 addition & 1 deletion src/Optim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module Optim
# Heuristic Optimization Methods
include("nelder_mead.jl")
#include("simulated_annealing.jl")
#include("particle_swarm.jl")
include("particle_swarm.jl")

# Univariate methods
include("golden_section.jl")
Expand Down
20 changes: 0 additions & 20 deletions src/bfgs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,6 @@ method_string(method::BFGS) = "BFGS"
BFGS(; linesearch!::Function = hz_linesearch!, initial_invH = x -> eye(eltype(x), length(x))) =
BFGS(linesearch!, initial_invH)

function trace!(tr, state, iteration, method::BFGS, options)
dt = Dict()
if options.extended_trace
dt["x"] = copy(state.x)
dt["g(x)"] = copy(state.g)
dt["~inv(H)"] = copy(state.invH)
dt["Current step size"] = state.alpha
end
g_norm = vecnorm(state.g, Inf)
update!(tr,
iteration,
state.f_x,
g_norm,
dt,
options.store_trace,
options.show_trace,
options.show_every,
options.callback)
end

type BFGSState{T}
n::Int64
x::Array{T}
Expand Down
19 changes: 2 additions & 17 deletions src/nelder_mead.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,6 @@ centroid(simplex, h) = centroid!(similar(simplex[1]), simplex, h)

nmobjective(y::Vector, m::Integer, n::Integer) = sqrt(var(y) * (m / n))

function trace!(tr, state, iteration, method::NelderMead, options)
dt = Dict()
if options.extended_trace
dt["centroid"] = state.x_centroid
dt["step_type"] = state.step_type
end
update!(tr,
iteration,
state.f_lowest,
state.f_x,
dt,
options.store_trace,
options.show_trace,
options.show_every,
options.callback)
end

function print_header(method::NelderMead)
@printf "Iter Function value √(Σ(yᵢ-ȳ)²)/n \n"
@printf "------ -------------- --------------\n"
Expand Down Expand Up @@ -147,7 +130,9 @@ type NelderMeadState{T, N}
f_calls::Int64
g_calls::Int64
end

initialize_state(method::NelderMead, options, d, initial_x::Array) = initialize_state(method, options, d.f, initial_x)

function initialize_state{T}(method::NelderMead, options, f::Function, initial_x::Array{T})
m = length(initial_x)
n = m + 1
Expand Down
4 changes: 3 additions & 1 deletion src/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ end

# Iterative method boiler plate
#This will just be replaced by ::Optimizer once they're all converted
typealias Refactored Union{AcceleratedGradientDescent, GradientDescent, MomentumGradientDescent, ConjugateGradient, LBFGS, BFGS, NelderMead}
typealias Refactored Union{AcceleratedGradientDescent, GradientDescent, MomentumGradientDescent, ConjugateGradient, LBFGS, BFGS, NelderMead, ParticleSwarm}

function after_while!(d, state, method, options)
nothing
Expand All @@ -226,6 +226,8 @@ function optimize{T}(d, initial_x::Array{T}, method::Refactored, options::Optimi
x_converged, f_converged = false, false
g_converged = if typeof(method) <: NelderMead
nmobjective(state.f_simplex, state.m, state.n) < options.g_tol
elseif typeof(method) <: ParticleSwarm
g_converged = false
else
vecnorm(state.g, Inf) < options.g_tol
end
Copy link
Contributor

Choose a reason for hiding this comment

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

some indentation artefact here

Expand Down
Loading