Skip to content

Commit

Permalink
Merge 271c728 into 3351bb6
Browse files Browse the repository at this point in the history
  • Loading branch information
pkofod committed Aug 8, 2016
2 parents 3351bb6 + 271c728 commit 95c091f
Show file tree
Hide file tree
Showing 26 changed files with 877 additions and 898 deletions.
17 changes: 1 addition & 16 deletions src/Optim.jl
Expand Up @@ -93,22 +93,6 @@ module Optim
include("golden_section.jl")
include("brent.jl")

const methods = Dict{Symbol, Type}(
:gradient_descent => GradientDescent,
:momentum_gradient_descent => MomentumGradientDescent,
:cg => ConjugateGradient,
:bfgs => BFGS,
:l_bfgs => LBFGS,
:newton => Newton,
:newton_tr => NewtonTrustRegion,
:nelder_mead => NelderMead,
:simulated_annealing => SimulatedAnnealing,
:particle_swarm => ParticleSwarm,
:brent => Brent,
:golden_section => GoldenSection,
:accelerated_gradient_descent => AcceleratedGradientDescent,
:fminbox => Fminbox)

# Backward compatibility
include("deprecate.jl")

Expand All @@ -117,6 +101,7 @@ module Optim

# Examples for testing
include(joinpath("problems", "unconstrained.jl"))
include(joinpath("problems", "univariate.jl"))

cgdescent(args...) = error("API has changed. Please use cg.")
end
51 changes: 51 additions & 0 deletions src/problems/univariate.jl
@@ -0,0 +1,51 @@
module UnivariateProblems

### Sources
###
### [1] http://infinity77.net/global_optimization/test_functions_1d.html

immutable UnivariateProblem
name::AbstractString
f::Function
bounds::Vector{Float64}
minimizers::Vector{Float64}
minima::Vector{Float64}
end

examples = Dict{AbstractString, UnivariateProblem}()

f(x) = 2x^2+3x+1

examples["Polynomial"] = UnivariateProblem("Polynomial",
f,
[-2.0, 1.0],
[-0.75,],
[f(-0.75),])

# Problem 04 from [1]
p04(x) = -(16x^2-24x+5)exp(-x)

examples["Problem04"] = UnivariateProblem("Problem04",
p04,
[1.9, 3.9],
[2.868034,],
[p04(2.868034),])

# Problem 13 from [1]
p13(x) = -x^(2/3)-(1-x^2)^(1/3)

examples["Problem13"] = UnivariateProblem("Problem13",
p13,
[0.001, 0.99],
[1./sqrt(2.0),],
[p13(1./sqrt(2.0)),])

# Problem 18 from [1]
p18(x) = x <= 3.0 ? (x-2.0)^2 : 2.0*log(x-2.0)+1.0

examples["Problem18"] = UnivariateProblem("Problem18",
p18,
[0.0, 6.0],
[2.0,],
[p18(2.0),])
end
27 changes: 14 additions & 13 deletions test/accelerated_gradient_descent.jl
@@ -1,16 +1,17 @@
using Optim
# TODO expand tests here
let
f(x) = x[1]^4
function g!(x, storage)
storage[1] = 4 * x[1]^3
return
end

f(x) = x[1]^4
function g!(x, storage)
storage[1] = 4 * x[1]^3
return
end

d = DifferentiableFunction(f, g!)
d = DifferentiableFunction(f, g!)

initial_x = [1.0]
initial_x = [1.0]

Optim.optimize(d, initial_x,
method = AcceleratedGradientDescent()
show_trace = true,
iterations = 10)
Optim.optimize(d, initial_x,
method = AcceleratedGradientDescent()
show_trace = true,
iterations = 10)
end

0 comments on commit 95c091f

Please sign in to comment.