-
Notifications
You must be signed in to change notification settings - Fork 48
AMPGO multivariate implementation #408
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
Open
arnavk23
wants to merge
10
commits into
JuliaSmoothOptimizers:main
Choose a base branch
from
arnavk23:fix/ampgo-test-set-issue-236
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cacd031
Add AMPGO multivariate test functions (Ackley, Rastrigin, Griewank, S…
arnavk23 0a64e74
Add Meta and PureJuMP implementations for AMPGO multivariate functions
arnavk23 c38d708
Apply suggestions from code review
arnavk23 daa7ad2
Update rastrigin.jl
arnavk23 49dc51a
adding Random to Project.toml
arnavk23 249fb6d
updating griewank
arnavk23 8334d0c
addressing review comments
arnavk23 3f89a93
Apply suggestions from code review
arnavk23 11b21e3
Merge branch 'JuliaSmoothOptimizers:main' into fix/ampgo-test-set-iss…
arnavk23 8c87341
getting files up to date
arnavk23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,14 @@ | ||
| export ackley | ||
|
|
||
| function ackley(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} | ||
| function f(x) | ||
| n = length(x) | ||
| sum1 = sum(x[i]^2 for i = 1:n) | ||
| sum2 = sum(cos(2 * T(π) * x[i]) for i = 1:n) | ||
| return -20 * exp(-T(0.2) * sqrt(sum1 / n)) - exp(sum2 / n) + 20 + T(ℯ) | ||
| end | ||
| x0 = zeros(T, n) | ||
| lvar = fill(T(-32.768), n) | ||
| uvar = fill(T(32.768), n) | ||
| return ADNLPModels.ADNLPModel(f, x0; lvar = lvar, uvar = uvar, name = "ackley", kwargs...) | ||
| end |
This file contains hidden or 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,19 @@ | ||
| export griewank | ||
|
|
||
| function griewank(; n::Int = default_nvar, type::Type{T} = Float64, x0::Union{Nothing,AbstractVector} = nothing, kwargs...) where {T} | ||
| function f(x) | ||
| n = length(x) | ||
| sum_term = sum(x[i]^2 for i = 1:n) / T(4000) | ||
| prod_term = prod(cos(x[i] / sqrt(T(i))) for i = 1:n) | ||
| return sum_term - prod_term + one(T) | ||
| end | ||
| if x0 === nothing | ||
| x0 = zeros(T, n) | ||
| else | ||
| length(x0) == n || throw(ArgumentError("griewank: length(x0) = $(length(x0)) must equal n = $n")) | ||
| x0 = T.(x0) | ||
| end | ||
| lvar = fill(T(-600), n) | ||
| uvar = fill(T(600), n) | ||
| return ADNLPModels.ADNLPModel(f, x0; lvar = lvar, uvar = uvar, name = "griewank", kwargs...) | ||
| end |
This file contains hidden or 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,12 @@ | ||
| export rastrigin | ||
|
|
||
| function rastrigin(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} | ||
| function f(x) | ||
| n = length(x) | ||
| return 10 * n + sum(x[i]^2 - 10 * cos(2 * T(π) * x[i]) for i = 1:n) | ||
| end | ||
| x0 = zeros(T, n) | ||
| lvar = fill(T(-5.12), n) | ||
| uvar = fill(T(5.12), n) | ||
| return ADNLPModels.ADNLPModel(f, x0, lvar = lvar, uvar = uvar, name = "rastrigin"; kwargs...) | ||
| end |
This file contains hidden or 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,11 @@ | ||
| export sphere | ||
|
|
||
| function sphere(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T} | ||
| function f(x) | ||
| return sum(x[i]^2 for i = 1:length(x)) | ||
| end | ||
| x0 = zeros(T, n) | ||
| lvar = fill(T(-1), n) | ||
| uvar = fill(T(1), n) | ||
| return ADNLPModels.ADNLPModel(f, x0; lvar = lvar, uvar = uvar, name = "sphere", kwargs...) | ||
| end |
This file contains hidden or 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,48 @@ | ||
| ackley_meta = Dict( | ||
| :nvar => 100, | ||
| :variable_nvar => true, | ||
| :ncon => 0, | ||
| :variable_ncon => false, | ||
| :minimize => true, | ||
| :name => "ackley", | ||
| :has_equalities_only => false, | ||
| :has_inequalities_only => false, | ||
| :has_bounds => true, | ||
| :has_fixed_variables => false, | ||
| :objtype => :other, | ||
| :contype => :unconstrained, | ||
| :best_known_lower_bound => 0.0, | ||
| :best_known_upper_bound => 0.0, | ||
| :is_feasible => true, | ||
| :defined_everywhere => missing, | ||
| :origin => :modelling, | ||
| :implementation => :both, | ||
| :url => "https://doi.org/10.1007/978-1-4613-1997-9", | ||
| :notes => raw""" | ||
| A non-convex multimodal function commonly used as a performance test problem for | ||
| global optimization algorithms. The function has a global minimum of 0 at the origin | ||
| and is surrounded by a nearly flat outer region that makes gradient-based methods difficult. | ||
| The search domain is [-32.768, 32.768]^n. | ||
| """, | ||
| :origin_notes => raw""" | ||
| Proposed by David Ackley in his 1987 PhD dissertation. | ||
| The n-dimensional generalization is due to Bäck and Schwefel (1993). | ||
| """, | ||
| :reference => raw""" | ||
| @book{Ackley1987, | ||
| author = {Ackley, David H.}, | ||
| title = {A Connectionist Machine for Genetic Hillclimbing}, | ||
| publisher = {Kluwer Academic Publishers}, | ||
| address = {Boston, MA}, | ||
| year = {1987}, | ||
| doi = {10.1007/978-1-4613-1997-9} | ||
| } | ||
| """, | ||
| :lib => "", | ||
| ) | ||
| get_ackley_nvar(; n::Int = default_nvar, kwargs...) = n | ||
| get_ackley_ncon(; n::Int = default_nvar, kwargs...) = 0 | ||
| get_ackley_nlin(; n::Int = default_nvar, kwargs...) = 0 | ||
| get_ackley_nnln(; n::Int = default_nvar, kwargs...) = 0 | ||
| get_ackley_nequ(; n::Int = default_nvar, kwargs...) = 0 | ||
| get_ackley_nineq(; n::Int = default_nvar, kwargs...) = 0 |
This file contains hidden or 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,49 @@ | ||
| griewank_meta = Dict( | ||
| :nvar => 100, | ||
| :variable_nvar => true, | ||
| :ncon => 0, | ||
| :variable_ncon => false, | ||
| :minimize => true, | ||
| :name => "griewank", | ||
| :has_equalities_only => false, | ||
| :has_inequalities_only => false, | ||
| :has_bounds => true, | ||
| :has_fixed_variables => false, | ||
| :objtype => :other, | ||
| :contype => :unconstrained, | ||
| :best_known_lower_bound => 0.0, | ||
| :best_known_upper_bound => 0.0, | ||
| :is_feasible => true, | ||
| :defined_everywhere => missing, | ||
| :origin => :modelling, | ||
| :implementation => :both, | ||
| :url => "https://doi.org/10.1007/BF00933356", | ||
| :notes => raw""" | ||
| A multimodal function composed of a quadratic term and a cosine modulation. | ||
| The global minimum of 0 is at the origin. The search domain is [-600, 600]^n. | ||
| The function becomes easier as dimension increases due to the product term | ||
| being averaged out. | ||
| """, | ||
| :origin_notes => raw""" | ||
| Introduced by Andreas Griewank in 1981. | ||
| """, | ||
| :reference => raw""" | ||
| @article{Griewank1981, | ||
| author = {Griewank, Andreas O.}, | ||
| title = {Generalized Descent for Global Optimization}, | ||
| journal = {Journal of Optimization Theory and Applications}, | ||
| volume = {34}, | ||
| number = {1}, | ||
| pages = {11--39}, | ||
| year = {1981}, | ||
| doi = {10.1007/BF00933356} | ||
| } | ||
| """, | ||
| :lib => "", | ||
| ) | ||
| get_griewank_nvar(; n::Int = default_nvar, kwargs...) = n | ||
| get_griewank_ncon(; n::Int = default_nvar, kwargs...) = 0 | ||
| get_griewank_nlin(; n::Int = default_nvar, kwargs...) = 0 | ||
| get_griewank_nnln(; n::Int = default_nvar, kwargs...) = 0 | ||
| get_griewank_nequ(; n::Int = default_nvar, kwargs...) = 0 | ||
| get_griewank_nineq(; n::Int = default_nvar, kwargs...) = 0 |
This file contains hidden or 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,47 @@ | ||
| rastrigin_meta = Dict( | ||
| :nvar => 100, | ||
| :variable_nvar => true, | ||
| :ncon => 0, | ||
| :variable_ncon => false, | ||
| :minimize => true, | ||
| :name => "rastrigin", | ||
| :has_equalities_only => false, | ||
| :has_inequalities_only => false, | ||
| :has_bounds => true, | ||
| :has_fixed_variables => false, | ||
| :objtype => :other, | ||
| :contype => :unconstrained, | ||
| :best_known_lower_bound => 0.0, | ||
| :best_known_upper_bound => 0.0, | ||
| :is_feasible => true, | ||
| :defined_everywhere => missing, | ||
| :origin => :modelling, | ||
| :implementation => :both, | ||
| :url => "", | ||
| :notes => raw""" | ||
| A non-convex multimodal function based on cosine modulation. The global minimum | ||
| of 0 is at the origin. The search domain is [-5.12, 5.12]^n. The large number | ||
| of local minima makes it a difficult test problem for global optimizers. | ||
| """, | ||
| :origin_notes => raw""" | ||
| First proposed by L.A. Rastrigin in 1974 as a 2-dimensional function. | ||
| The n-dimensional generalization is due to Rudolph (1990) and was popularized | ||
| by Hoffmeister & Bäck (1991) and Mühlenbein et al. (1991). | ||
| """, | ||
| :reference => raw""" | ||
| @book{Rastrigin1974, | ||
| author = {Rastrigin, L. A.}, | ||
| title = {Systems of Extremal Control}, | ||
| publisher = {Nauka}, | ||
| address = {Moscow}, | ||
| year = {1974} | ||
| } | ||
| """, | ||
| :lib => "", | ||
| ) | ||
| get_rastrigin_nvar(; n::Int = default_nvar, kwargs...) = n | ||
| get_rastrigin_ncon(; n::Int = default_nvar, kwargs...) = 0 | ||
| get_rastrigin_nlin(; n::Int = default_nvar, kwargs...) = 0 | ||
| get_rastrigin_nnln(; n::Int = default_nvar, kwargs...) = 0 | ||
| get_rastrigin_nequ(; n::Int = default_nvar, kwargs...) = 0 | ||
| get_rastrigin_nineq(; n::Int = default_nvar, kwargs...) = 0 | ||
This file contains hidden or 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,48 @@ | ||
| sphere_meta = Dict( | ||
| :nvar => 100, | ||
| :variable_nvar => true, | ||
| :ncon => 0, | ||
| :variable_ncon => false, | ||
| :minimize => true, | ||
| :name => "sphere", | ||
| :has_equalities_only => false, | ||
| :has_inequalities_only => false, | ||
| :has_bounds => true, | ||
| :has_fixed_variables => false, | ||
| :objtype => :quadratic, | ||
| :contype => :unconstrained, | ||
| :best_known_lower_bound => 0.0, | ||
| :best_known_upper_bound => 0.0, | ||
| :is_feasible => true, | ||
| :defined_everywhere => missing, | ||
| :origin => :modelling, | ||
| :implementation => :both, | ||
| :url => "https://doi.org/10.1145/355934.355936", | ||
| :notes => raw""" | ||
| The simplest convex test function: sum of squares. The global minimum of 0 is | ||
| at the origin. The search domain is [-1, 1]^n in this implementation. | ||
| """, | ||
| :origin_notes => raw""" | ||
| A classic unconstrained optimization test problem, also known as the De Jong | ||
| function 1. Commonly listed as problem 1 in Moré, Garbow and Hillstrom (1981). | ||
| """, | ||
| :reference => raw""" | ||
| @article{MoreGarbowHillstrom1981, | ||
| author = {Mor{\'e}, Jorge J. and Garbow, Burton S. and Hillstrom, Kenneth E.}, | ||
| title = {Testing Unconstrained Optimization Software}, | ||
| journal = {ACM Transactions on Mathematical Software}, | ||
| year = {1981}, | ||
| volume = {7}, | ||
| number = {1}, | ||
| pages = {17--41}, | ||
| doi = {10.1145/355934.355936} | ||
| } | ||
| """, | ||
| :lib => "", | ||
| ) | ||
| get_sphere_nvar(; n::Int = default_nvar, kwargs...) = n | ||
| get_sphere_ncon(; n::Int = default_nvar, kwargs...) = 0 | ||
| get_sphere_nlin(; n::Int = default_nvar, kwargs...) = 0 | ||
| get_sphere_nnln(; n::Int = default_nvar, kwargs...) = 0 | ||
| get_sphere_nequ(; n::Int = default_nvar, kwargs...) = 0 | ||
| get_sphere_nineq(; n::Int = default_nvar, kwargs...) = 0 |
This file contains hidden or 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,23 @@ | ||
| export ackley | ||
|
|
||
| "Ackley multimodal minimization problem" | ||
| function ackley(args...; n::Int = default_nvar, kwargs...) | ||
| n < 1 && @warn("ackley: number of variables must be ≥ 1") | ||
| n = max(1, n) | ||
|
|
||
| nlp = Model() | ||
|
|
||
| x0 = zeros(n) | ||
| @variable(nlp, -32.768 <= x[i = 1:n] <= 32.768, start = x0[i]) | ||
|
|
||
| @objective( | ||
| nlp, | ||
| Min, | ||
| -20 * exp(-0.2 * sqrt(sum(x[i]^2 for i = 1:n) / n)) - | ||
| exp(sum(cos(2 * π * x[i]) for i = 1:n) / n) + | ||
| 20 + | ||
| exp(1) | ||
| ) | ||
|
|
||
| return nlp | ||
| end |
This file contains hidden or 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,24 @@ | ||
| export griewank | ||
|
|
||
| "Griewank multimodal minimization problem" | ||
| function griewank(args...; n::Int = default_nvar, x0::Union{Nothing,AbstractVector} = nothing, kwargs...) | ||
| n < 1 && @warn("griewank: number of variables must be ≥ 1") | ||
| n = max(1, n) | ||
|
|
||
| nlp = Model() | ||
|
|
||
| if x0 === nothing | ||
| x0 = zeros(n) | ||
| elseif length(x0) != n | ||
| throw(ArgumentError("griewank: length(x0) = $(length(x0)) must equal n = $n")) | ||
| end | ||
| @variable(nlp, -600 <= x[i = 1:n] <= 600, start = x0[i]) | ||
|
|
||
| @objective( | ||
| nlp, | ||
| Min, | ||
| sum(x[i]^2 for i = 1:n) / 4000 - prod(cos(x[i] / sqrt(i)) for i = 1:n) + 1 | ||
| ) | ||
|
|
||
| return nlp | ||
| end |
This file contains hidden or 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,16 @@ | ||
| export rastrigin | ||
|
|
||
| "Rastrigin multimodal minimization problem" | ||
| function rastrigin(args...; n::Int = default_nvar, kwargs...) | ||
| n < 1 && @warn("rastrigin: number of variables must be ≥ 1") | ||
| n = max(1, n) | ||
|
|
||
| nlp = Model() | ||
|
|
||
| x0 = [0.0 for i = 1:n] | ||
| @variable(nlp, x[i = 1:n], lower_bound = -5.12, upper_bound = 5.12, start = x0[i]) | ||
|
|
||
| @objective(nlp, Min, 10 * n + sum(x[i]^2 - 10 * cos(2 * π * x[i]) for i = 1:n)) | ||
|
|
||
| return nlp | ||
| end |
This file contains hidden or 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,16 @@ | ||
| export sphere | ||
|
|
||
| "Sphere convex minimization problem" | ||
| function sphere(args...; n::Int = default_nvar, kwargs...) | ||
| n < 1 && @warn("sphere: number of variables must be ≥ 1") | ||
| n = max(1, n) | ||
|
|
||
| nlp = Model() | ||
|
|
||
| x0 = zeros(n) | ||
| @variable(nlp, -1 <= x[i = 1:n] <= 1, start = x0[i]) | ||
|
|
||
| @objective(nlp, Min, sum(x[i]^2 for i = 1:n)) | ||
|
|
||
| return nlp | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.