Skip to content

Commit

Permalink
Update dejong5 and dropwave
Browse files Browse the repository at this point in the history
  • Loading branch information
jungtaekkim committed Feb 10, 2021
1 parent 90deaf0 commit 59edd11
Show file tree
Hide file tree
Showing 26 changed files with 204 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bayeso_benchmarks/plot_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def plot_2d(obj_fun,


if __name__ == '__main__':
# one dim.
from one_dim_gramacyandlee2012 import GramacyAndLee2012 as target_class
obj_fun = target_class()
plot_1d(obj_fun, 'gramacyandlee2012')
Expand All @@ -126,6 +127,7 @@ def plot_2d(obj_fun,
obj_fun = target_class(1)
plot_1d(obj_fun, 'sphere_1d')

# two dim.
from two_dim_beale import Beale as target_class
obj_fun = target_class()
plot_2d(obj_fun, 'beale_2d')
Expand All @@ -138,6 +140,14 @@ def plot_2d(obj_fun,
obj_fun = target_class()
plot_2d(obj_fun, 'branin_2d')

from two_dim_dejong5 import DeJong5 as target_class
obj_fun = target_class()
plot_2d(obj_fun, 'dejong5_2d')

from two_dim_dropwave import DropWave as target_class
obj_fun = target_class()
plot_2d(obj_fun, 'dropwave_2d')

from two_dim_eggholder import Eggholder as target_class
obj_fun = target_class()
plot_2d(obj_fun, 'eggholder_2d')
Expand Down
57 changes: 57 additions & 0 deletions bayeso_benchmarks/two_dim_dejong5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#
# author: Jungtaek Kim ([email protected])
# last updated: February 8, 2021
#

import numpy as np

from bayeso_benchmarks.benchmark_base import Function


def fun_target(bx, dim_bx):
assert len(bx.shape) == 1
assert bx.shape[0] == dim_bx

A = np.array([
[-32.0, -16.0, 0.0, 16.0, 32.0, -32.0, -16.0, 0.0, 16.0, 32.0, -32.0, -16.0, 0.0, 16.0, 32.0, -32.0, -16.0, 0.0, 16.0, 32.0, -32.0, -16.0, 0.0, 16.0, 32.0],
[-32.0, -32.0, -32.0, -32.0, -32.0, -16.0, -16.0, -16.0, -16.0, -16.0, 0.0, 0.0, 0.0, 0.0, 0.0, 16.0, 16.0, 16.0, 16.0, 16.0, 32.0, 32.0, 32.0, 32.0, 32.0],
])
y = 0.002

for ind in range(0, 25):
cur_y = 1.0 / (ind + 1.0 + (bx[0] - A[0, ind])**6 + (bx[1] - A[1, ind])**6)
y += cur_y
y = y**(-1)

return y


class DeJong5(Function):
def __init__(self):
dim_bx = 2
bounds = np.array([
[-65.536, 65.536],
[-65.536, 65.536],
])
global_minimizers = np.array([
[-32.10428207, -32.13705826],
[-32.07150588, -32.13705826],
[-32.03872968, -32.13705826],
[-32.00595349, -32.13705826],
[-31.97317729, -32.13705826],
[-31.9404011, -32.13705826],
[-31.90762491, -32.13705826],
[-32.13705826, -32.10428207],
[-32.10428207, -32.10428207],
[-32.07150588, -32.10428207],
[-32.03872968, -32.10428207],
[-32.00595349, -32.10428207],
[-31.97317729, -32.10428207],
[-31.9404011, -32.10428207],
[-31.90762491, -32.10428207],
[-31.87484871, -32.10428207],
])
global_minimum = 0.9980038753198021
function = lambda bx: fun_target(bx, dim_bx)

Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function)
32 changes: 32 additions & 0 deletions bayeso_benchmarks/two_dim_dropwave.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# author: Jungtaek Kim ([email protected])
# last updated: February 9, 2021
#

import numpy as np

from bayeso_benchmarks.benchmark_base import Function


def fun_target(bx, dim_bx):
assert len(bx.shape) == 1
assert bx.shape[0] == dim_bx

y = -1.0 * (1 + np.cos(12.0 * np.sqrt(bx[0]**2 + bx[1]**2))) / (0.5 * (bx[0]**2 + bx[1]**2) + 2.0)
return y


class DropWave(Function):
def __init__(self):
dim_bx = 2
bounds = np.array([
[-5.12, 5.12],
[-5.12, 5.12],
])
global_minimizers = np.array([
[0.0, 0.0],
])
global_minimum = -1.0
function = lambda bx: fun_target(bx, dim_bx)

Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function)
Binary file modified figures/ackley_1d.pdf
Binary file not shown.
Binary file modified figures/ackley_2d.pdf
Binary file not shown.
Binary file modified figures/beale_2d.pdf
Binary file not shown.
Binary file modified figures/bohachevsky_2d.pdf
Binary file not shown.
Binary file modified figures/branin_2d.pdf
Binary file not shown.
Binary file modified figures/cosines_1d.pdf
Binary file not shown.
Binary file modified figures/cosines_2d.pdf
Binary file not shown.
Binary file added figures/dejong5_2d.pdf
Binary file not shown.
Binary file added figures/dropwave_2d.pdf
Binary file not shown.
Binary file modified figures/eggholder_2d.pdf
Binary file not shown.
Binary file modified figures/goldsteinprice_2d.pdf
Binary file not shown.
Binary file modified figures/gramacyandlee2012.pdf
Binary file not shown.
Binary file modified figures/holdertable_2d.pdf
Binary file not shown.
Binary file modified figures/michalewicz_2d.pdf
Binary file not shown.
Binary file modified figures/rosenbrock_2d.pdf
Binary file not shown.
Binary file modified figures/sixhumpcamel_2d.pdf
Binary file not shown.
Binary file modified figures/sphere_1d.pdf
Binary file not shown.
Binary file modified figures/sphere_2d.pdf
Binary file not shown.
Binary file modified figures/threehumpcamel_2d.pdf
Binary file not shown.
15 changes: 15 additions & 0 deletions tests/test_global_minimum.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from bayeso_benchmarks.two_dim_branin import *
from bayeso_benchmarks.two_dim_eggholder import *
from bayeso_benchmarks.two_dim_michalewicz import *
from bayeso_benchmarks.two_dim_dejong5 import *

TEST_EPSILON = 1e-5

Expand Down Expand Up @@ -54,3 +55,17 @@ def test_global_minimum_michalewicz():
print(grids[ind_minimum])
print(obj_fun.global_minimum - global_minimum_brute_force)
assert (obj_fun.global_minimum - global_minimum_brute_force) < TEST_EPSILON

def test_global_minimum_dejong5():
class_fun = DeJong5

obj_fun = class_fun()
grids = obj_fun.get_grids(100)
vals_grids = obj_fun.output(grids)
ind_minimum = np.argmin(vals_grids)
global_minimum_brute_force = np.min(vals_grids)

print(global_minimum_brute_force)
print(grids[((vals_grids - global_minimum_brute_force) < TEST_EPSILON)[:, 0]])
print(obj_fun.global_minimum - global_minimum_brute_force)
assert (obj_fun.global_minimum - global_minimum_brute_force) < TEST_EPSILON
4 changes: 4 additions & 0 deletions tests/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def test_import_two_dim_branin():
import bayeso_benchmarks.two_dim_branin
from bayeso_benchmarks.two_dim_branin import Branin

def test_import_two_dim_dropwave():
import bayeso_benchmarks.two_dim_dropwave
from bayeso_benchmarks.two_dim_dropwave import DropWave

def test_import_two_dim_eggholder():
import bayeso_benchmarks.two_dim_eggholder
from bayeso_benchmarks.two_dim_eggholder import Eggholder
Expand Down
43 changes: 43 additions & 0 deletions tests/test_two_dim_dejong5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# author: Jungtaek Kim ([email protected])
# last updated: February 8, 2021
#

import numpy as np
import pytest

from bayeso_benchmarks.two_dim_dejong5 import *

class_fun = DeJong5

TEST_EPSILON = 1e-3


def test_init():
obj_fun = class_fun()

def test_validate_properties():
obj_fun = class_fun()
obj_fun.validate_properties()

def test_output():
obj_fun = class_fun()
bounds = obj_fun.get_bounds()

grids = obj_fun.get_grids(3)
truths_grids = np.array([
[499.99985236],
[499.99917292],
[499.99985236],
[499.99917292],
[12.67050581],
[499.99917292],
[499.99985236],
[499.99917292],
[499.99985236],
])

print(grids)
print(obj_fun.output(grids))
print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON)
assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON)
43 changes: 43 additions & 0 deletions tests/test_two_dim_dropwave.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# author: Jungtaek Kim ([email protected])
# last updated: February 8, 2021
#

import numpy as np
import pytest

from bayeso_benchmarks.two_dim_dropwave import *

class_fun = DropWave

TEST_EPSILON = 1e-3


def test_init():
obj_fun = class_fun()

def test_validate_properties():
obj_fun = class_fun()
obj_fun.validate_properties()

def test_output():
obj_fun = class_fun()
bounds = obj_fun.get_bounds()

grids = obj_fun.get_grids(3)
truths_grids = np.array([
[-0.05229446],
[-0.07797539],
[-0.05229446],
[-0.07797539],
[-1.0],
[-0.07797539],
[-0.05229446],
[-0.07797539],
[-0.05229446],
])

print(grids)
print(obj_fun.output(grids))
print(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON)
assert np.all(np.abs(obj_fun.output(grids) - truths_grids) < TEST_EPSILON)

0 comments on commit 59edd11

Please sign in to comment.