Skip to content

Commit

Permalink
add brent, deckkers-aarts fns, refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rbalexan committed Apr 6, 2020
1 parent 3fc7530 commit a210ed3
Show file tree
Hide file tree
Showing 30 changed files with 523,063 additions and 101 deletions.
108,442 changes: 108,442 additions & 0 deletions plots/2d_brent.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
414,474 changes: 414,474 additions & 0 deletions plots/2d_deckkers_aarts.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions plots/plots.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using BenchmarkFunctions
using Plots
pyplot()

## plot 1D functions
plot("gramacy_lee", -0.5:0.001:2.5)
savefig("./plots/1d_gramacy_lee.svg")

## plot 2D functions
plot("adjiman", -4:0.1:4, -4:0.1:4)
savefig("./plots/2d_adjiman.svg")
plot("ackley_2", -4:0.1:4, -4:0.1:4)
savefig("./plots/2d_ackley_2.svg")
plot("ackley_3", -4:0.1:4, -4:0.1:4)
savefig("./plots/2d_ackley_3.svg")
plot("bartels_conn", -4:0.1:4, -4:0.1:4)
savefig("./plots/2d_bartels_conn.svg")
plot("beale", -4:0.1:4, -4:0.1:4)
savefig("./plots/2d_beale.svg")
plot("bird", -2π:0.1:2π, -2π:0.1:2π)
savefig("./plots/2d_bird.svg")
plot("bohachevsky_1", -100:1:100, -100:1:100)
savefig("./plots/2d_bohachevsky_1.svg")
plot("bohachevsky_2", -2:0.1:2, -2:0.1:2)
savefig("./plots/2d_bohachevsky_2.svg")
plot("bohachevsky_3", -2:0.1:2, -2:0.1:2)
savefig("./plots/2d_bohachevsky_3.svg")
plot("brent", -15:0.1:-5, -15:0.1:-5)
savefig("./plots/2d_brent.svg")
plot("deckkers_aarts",-20:0.2:20, -20:0.2:20)
savefig("./plots/2d_deckkers_aarts.svg")
plot("himmelblau", -5:0.1:5, -5:0.1:5)
savefig("./plots/2d_himmelblau.svg")
plot("mccormick", -1.5:0.1:4, -3:0.1:3)
savefig("./plots/2d_mccormick.svg")

## plot nD functions
plot("ackley_1", -10:0.01:10)
savefig("./plots/nd_ackley_1_1d.svg")
plot("ackley_1", -10:0.1:10, -10:0.1:10)
savefig("./plots/nd_ackley_1_2d.svg")
plot("ackley_4", -5:0.1:5, -5:0.1:5)
savefig("./plots/nd_ackley_4_2d.svg")
plot("alpine_1", -10:0.01:10)
savefig("./plots/nd_alpine_1_1d.svg")
plot("alpine_1", -10:0.1:10, -10:0.1:10)
savefig("./plots/nd_alpine_1_2d.svg")
plot("alpine_2", 0:0.01:10)
savefig("./plots/nd_alpine_2_1d.svg")
plot("alpine_2", 0:0.1:10, 0:0.1:10)
savefig("./plots/nd_alpine_2_2d.svg")
plot("rosenbrock", -2:0.1:2, -2:0.1:2)
savefig("./plots/nd_rosenbrock_2d.svg")
33 changes: 3 additions & 30 deletions src/BenchmarkFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,9 @@ using Plots
using LaTeXStrings

# utils
include("attributes.jl")
include("ndgrid.jl")
include("plot.jl")
export attributes, ndgrid, plot
include("utils/utils.jl")

# 1-dimensional
include("gramacy_lee.jl")
export gramacy_lee

# 2-dimensional
include("adjiman.jl")
include("ackley_2.jl")
include("ackley_3.jl")
include("bartels_conn.jl")
include("beale.jl")
include("bird.jl")
include("bohachevsky_1.jl")
include("bohachevsky_2.jl")
include("bohachevsky_3.jl")
include("himmelblau.jl")
include("mccormick.jl")
export adjiman, ackley_2, ackley_3, bartels_conn, beale, bird, bohachevsky_1,
bohachevsky_2, bohachevsky_3, himmelblau, mccormick

# n-dimensional
include("ackley_1.jl")
include("ackley_4.jl")
include("alpine_1.jl")
include("alpine_2.jl")
include("rosenbrock.jl")
export ackley_1, ackley_4, alpine_1, alpine_2, rosenbrock
# functions
include("functions/functions.jl")

end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions src/functions/brent.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
brent(X)
Compute the 2-dimensional Brent function on sample vector `X`.
The function is usually evaluated on `xᵢ` ∈ [-10, 10] for i = 1, 2.
"""
function brent(X)

@assert all(length.(X) .== 2) "Sample vector tuples must be length 2."

y = [Tuple( (x[1]+10)^2 + (x[2]+10)^2 + exp(-x[1]^2 - x[2]^2) ) for x in X]

return y

end
17 changes: 17 additions & 0 deletions src/functions/deckkers_aarts.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
deckkers_aarts(X)
Compute the 2-dimensional Deckkers-Aarts function on sample vector `X`.
The function is usually evaluated on `xᵢ` ∈ [-20, 20] for i = 1, 2.
"""
function deckkers_aarts(X)

@assert all(length.(X) .== 2) "Sample vector tuples must be length 2."

y = [Tuple( 1e5*x[1]^2 + x[2]^2 - (x[1]^2+x[2]^2)^2 +
1e-5*(x[1]^2+x[2]^2)^4 ) for x in X]

return y

end
29 changes: 29 additions & 0 deletions src/functions/functions.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 1-dimensional
include("gramacy_lee.jl")
export gramacy_lee

# 2-dimensional
include("adjiman.jl")
include("ackley_2.jl")
include("ackley_3.jl")
include("bartels_conn.jl")
include("beale.jl")
include("bird.jl")
include("bohachevsky_1.jl")
include("bohachevsky_2.jl")
include("bohachevsky_3.jl")
include("brent.jl")
include("deckkers_aarts.jl")
include("himmelblau.jl")
include("mccormick.jl")
export adjiman, ackley_2, ackley_3, bartels_conn, beale, bird, bohachevsky_1,
bohachevsky_2, bohachevsky_3, brent, deckkers_aarts, himmelblau,
mccormick

# n-dimensional
include("ackley_1.jl")
include("ackley_4.jl")
include("alpine_1.jl")
include("alpine_2.jl")
include("rosenbrock.jl")
export ackley_1, ackley_4, alpine_1, alpine_2, rosenbrock
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions src/attributes.jl → src/utils/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ functionDict = Dict("gramacy_lee" => Set(["1d", "continuous", "differentiable"
"bohachevsky_1" => Set(["2d", "continuous", "differentiable", "convex", "unimodal", "separable"]),
"bohachevsky_2" => Set(["2d", "continuous", "differentiable", "non-convex", "multimodal", "non-separable"]),
"bohachevsky_3" => Set(["2d", "continuous", "differentiable", "non-convex", "multimodal", "non-separable"]),
"brent" => Set(["2d", "continuous", "differentiable", "convex", "unimodal", "non-separable"]),
"deckkers_aarts"=> Set(["2d", "continuous", "differentiable", "non-convex", "multimodal", "non-separable"]),
"himmelblau" => Set(["2d", "continuous", "differentiable", "non-convex", "multimodal", "separable"]),
"mccormick" => Set(["2d", "continuous", "differentiable", "convex", "multimodal", "separable"]),
"ackley_1" => Set(["nd", "continuous", "differentiable", "non-convex", "multimodal", "separable"]),
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions src/utils/utils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include("attributes.jl")
include("ndgrid.jl")
include("plot.jl")
export attributes, ndgrid, plot
50 changes: 0 additions & 50 deletions test/plots.jl

This file was deleted.

44 changes: 23 additions & 21 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,35 @@ using BenchmarkFunctions
using Test

@testset "1-dimensional function minima" begin
@test isapprox(minimum(gramacy_lee( ndgrid(-0.5:0.01:2.5)))[1], -2.84962, atol=0.1)
@test isapprox(minimum(gramacy_lee( ndgrid(-0.5:0.01:2.5)))[1], -2.84962, atol=0.1)
end

@testset "2-dimensional function minima" begin
@test isapprox(minimum(ackley_2( ndgrid(-5 :0.1:5 ,-5 :0.1:5 )))[1], -200., atol=0.1)
@test isapprox(minimum(ackley_3( ndgrid(-5 :0.1:5 ,-5 :0.1:5 )))[1], -195.629, atol=0.1)
@test isapprox(minimum(adjiman( ndgrid(-1 :0.1:2 ,-1 :0.1:1 )))[1], -2.02181, atol=0.1)
@test isapprox(minimum(bartels_conn( ndgrid(-4 :0.1:4 ,-4 :0.1:4 )))[1], 1, atol=0.1)
@test isapprox(minimum(beale( ndgrid(-4 :0.1:4 ,-4 :0.1:4 )))[1], 0., atol=0.1)
@test isapprox(minimum(bird( ndgrid(-2π :0.05:2π,-2π:0.05:2π)))[1],-106.764, atol=0.1)
@test isapprox(minimum(bohachevsky_1(ndgrid(-4 :0.1:4 ,-4 :0.1:4 )))[1], 0., atol=0.1)
@test isapprox(minimum(bohachevsky_2(ndgrid(-4 :0.1:4 ,-4 :0.1:4 )))[1], 0., atol=0.1)
@test isapprox(minimum(bohachevsky_3(ndgrid(-4 :0.1:4 ,-4 :0.1:4 )))[1], 0., atol=0.1)
@test isapprox(minimum(himmelblau( ndgrid(-4 :0.1:4 ,-4 :0.1:4 )))[1], 0., atol=0.1)
@test isapprox(minimum(mccormick( ndgrid(-1.5:0.1:4 ,-3 :0.1:3 )))[1], -1.9133, atol=0.1)
@test isapprox(minimum(ackley_2( ndgrid(-5 :0.1:5 ,-5 :0.1:5 )))[1], -200., atol=0.1)
@test isapprox(minimum(ackley_3( ndgrid(-5 :0.1:5 ,-5 :0.1:5 )))[1], -195.629, atol=0.1)
@test isapprox(minimum(adjiman( ndgrid(-1 :0.1:2 ,-1 :0.1:1 )))[1], -2.02181, atol=0.1)
@test isapprox(minimum(bartels_conn( ndgrid(-4 :0.1:4 ,-4 :0.1:4 )))[1], 1, atol=0.1)
@test isapprox(minimum(beale( ndgrid(-4 :0.1:4 ,-4 :0.1:4 )))[1], 0., atol=0.1)
@test isapprox(minimum(bird( ndgrid(-2π :0.05:2π,-2π:0.05:2π)))[1],-106.764,atol=0.1)
@test isapprox(minimum(bohachevsky_1( ndgrid(-4 :0.1:4 ,-4 :0.1:4 )))[1], 0., atol=0.1)
@test isapprox(minimum(bohachevsky_2( ndgrid(-4 :0.1:4 ,-4 :0.1:4 )))[1], 0., atol=0.1)
@test isapprox(minimum(bohachevsky_3( ndgrid(-4 :0.1:4 ,-4 :0.1:4 )))[1], 0., atol=0.1)
@test isapprox(minimum(brent( ndgrid(-15 :0.1:-5,-15:0.1:-5)))[1], exp(-200),atol=0.1)
@test isapprox(minimum(deckkers_aarts(ndgrid(-20 :0.4:20,-20:0.4:20)))[1], -24771, atol=1e2)
@test isapprox(minimum(himmelblau( ndgrid(-4 :0.1:4 ,-4 :0.1:4 )))[1], 0., atol=0.1)
@test isapprox(minimum(mccormick( ndgrid(-1.5:0.1:4 ,-3 :0.1:3 )))[1], -1.9133, atol=0.1)
end

@testset "n-dimensional function minima" begin
@test isapprox(minimum(ackley_1( ndgrid( -5:0.1: 5), n=1))[1], 0., atol=0.1)
@test isapprox(minimum(ackley_1( ndgrid( -5:0.1: 5, -5:0.1: 5)))[1], 0., atol=0.1)
@test isapprox(minimum(ackley_4( ndgrid( -5:0.1: 5, -5:0.1: 5)))[1], -4.590101, atol=0.1)
@test isapprox(minimum(alpine_1( ndgrid(-10:0.1:10), n=1))[1], 0., atol=0.1)
@test isapprox(minimum(alpine_1( ndgrid(-10:0.1:10,-10:0.1:10)))[1], 0., atol=0.1)
@test isapprox(minimum(alpine_2( ndgrid( 0:0.1:10), n=1))[1], -2.808^1, atol=0.1)
@test isapprox(minimum(alpine_2( ndgrid( 0:0.1:10, 0:0.1:10)))[1], -2.808^2, atol=0.1)
@test isapprox(minimum(rosenbrock( ndgrid( -2:0.1: 2, -2:0.1: 2)))[1], 0., atol=0.1)
@test isapprox(minimum(rosenbrock( ndgrid( -2:0.1: 2, -2:0.1: 2,-2:0.1:2), n=3))[1], 0., atol=0.1)
@test isapprox(minimum(ackley_1( ndgrid( -5:0.1: 5), n=1))[1], 0., atol=0.1)
@test isapprox(minimum(ackley_1( ndgrid( -5:0.1: 5, -5:0.1: 5)))[1], 0., atol=0.1)
@test isapprox(minimum(ackley_4( ndgrid( -5:0.1: 5, -5:0.1: 5)))[1], -4.590101, atol=0.1)
@test isapprox(minimum(alpine_1( ndgrid(-10:0.1:10), n=1))[1], 0., atol=0.1)
@test isapprox(minimum(alpine_1( ndgrid(-10:0.1:10,-10:0.1:10)))[1], 0., atol=0.1)
@test isapprox(minimum(alpine_2( ndgrid( 0:0.1:10), n=1))[1], -2.808^1, atol=0.1)
@test isapprox(minimum(alpine_2( ndgrid( 0:0.1:10, 0:0.1:10)))[1], -2.808^2, atol=0.1)
@test isapprox(minimum(rosenbrock( ndgrid( -2:0.1: 2, -2:0.1: 2)))[1], 0., atol=0.1)
@test isapprox(minimum(rosenbrock( ndgrid( -2:0.1: 2, -2:0.1: 2,-2:0.1:2), n=3))[1], 0., atol=0.1)
end

@testset "Attribute output" begin
Expand Down

0 comments on commit a210ed3

Please sign in to comment.