Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
877 additions
and
898 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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,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 |
Oops, something went wrong.