Skip to content

Commit

Permalink
Merge pull request #4 from jungtaekkim/0.1.7
Browse files Browse the repository at this point in the history
0.1.7
  • Loading branch information
jungtaekkim committed Jan 13, 2023
2 parents 6e82748 + 5b1b3f4 commit 226d07d
Show file tree
Hide file tree
Showing 106 changed files with 7,201 additions and 94 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/pytest.yml
Expand Up @@ -12,7 +12,8 @@ jobs:
- '3.8'
- '3.9'
- '3.10'
runs-on: ubuntu-latest
- '3.11'
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019-2022 Jungtaek Kim
Copyright (c) 2019-2023 Jungtaek Kim

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
13 changes: 8 additions & 5 deletions README.md
@@ -1,10 +1,16 @@
# BayesO Benchmarks
<p align="center">
<img src="https://github.com/jungtaekkim/bayeso/blob/main/docs/_static/assets/logo_bayeso_capitalized.svg" width="400" />
</p>

# BayesO Benchmarks: Benchmark Functions for Bayesian Optimization
[![Build Status](https://github.com/jungtaekkim/bayeso-benchmarks/actions/workflows/pytest.yml/badge.svg)](https://github.com/jungtaekkim/bayeso-benchmarks/actions/workflows/pytest.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Benchmarks for Bayesian optimization.
This repository provides the implementation of benchmark functions for Bayesian optimization.
The details of benchmark functions can be found in [these notes](https://jungtaek.github.io/notes/benchmarks_bo.pdf).

* [https://bayeso.org](https://bayeso.org)

## Installation
We recommend installing it with `virtualenv`.
You can choose one of three installation options.
Expand Down Expand Up @@ -64,8 +70,5 @@ Y = obj_fun.output(X)
Y_noise = obj_fun.output_gaussian_noise(X)
```

## Author
* [Jungtaek Kim](https://jungtaek.github.io) (POSTECH)

## License
[MIT License](LICENSE)
49 changes: 47 additions & 2 deletions bayeso_benchmarks/__init__.py
@@ -1,16 +1,20 @@
#
# author: Jungtaek Kim (jtkim@postech.ac.kr)
# last updated: October 23, 2021
# last updated: January 6, 2023
#


__version__ = '0.1.6'
__version__ = '0.1.7'


from bayeso_benchmarks.inf_dim_ackley import Ackley
from bayeso_benchmarks.inf_dim_cosines import Cosines
from bayeso_benchmarks.inf_dim_griewank import Griewank
from bayeso_benchmarks.inf_dim_levy import Levy
from bayeso_benchmarks.inf_dim_rastrigin import Rastrigin
from bayeso_benchmarks.inf_dim_rosenbrock import Rosenbrock
from bayeso_benchmarks.inf_dim_sphere import Sphere
from bayeso_benchmarks.inf_dim_zakharov import Zakharov

from bayeso_benchmarks.one_dim_constant import Constant
from bayeso_benchmarks.one_dim_gramacyandlee2012 import GramacyAndLee2012
Expand All @@ -20,17 +24,58 @@
from bayeso_benchmarks.two_dim_beale import Beale
from bayeso_benchmarks.two_dim_bohachevsky import Bohachevsky
from bayeso_benchmarks.two_dim_branin import Branin
from bayeso_benchmarks.two_dim_bukin6 import Bukin6
from bayeso_benchmarks.two_dim_dejong5 import DeJong5
from bayeso_benchmarks.two_dim_dropwave import DropWave
from bayeso_benchmarks.two_dim_easom import Easom
from bayeso_benchmarks.two_dim_eggholder import Eggholder
from bayeso_benchmarks.two_dim_goldsteinprice import GoldsteinPrice
from bayeso_benchmarks.two_dim_holdertable import HolderTable
from bayeso_benchmarks.two_dim_kim1 import Kim1
from bayeso_benchmarks.two_dim_kim2 import Kim2
from bayeso_benchmarks.two_dim_kim3 import Kim3
from bayeso_benchmarks.two_dim_michalewicz import Michalewicz
from bayeso_benchmarks.two_dim_shubert import Shubert
from bayeso_benchmarks.two_dim_sixhumpcamel import SixHumpCamel
from bayeso_benchmarks.two_dim_threehumpcamel import ThreeHumpCamel

from bayeso_benchmarks.four_dim_colville import Colville
from bayeso_benchmarks.three_dim_hartmann3d import Hartmann3D
from bayeso_benchmarks.six_dim_hartmann6d import Hartmann6D


all_benchmarks = [
Ackley,
Cosines,
Griewank,
Levy,
Rastrigin,
Rosenbrock,
Sphere,
Zakharov,
Constant,
GramacyAndLee2012,
Linear,
Step,
Beale,
Bohachevsky,
Branin,
Bukin6,
DeJong5,
DropWave,
Easom,
Eggholder,
GoldsteinPrice,
HolderTable,
Kim1,
Kim2,
Kim3,
Michalewicz,
Shubert,
SixHumpCamel,
ThreeHumpCamel,
Colville,
Hartmann3D,
Hartmann6D,
]
num_benchmarks = len(all_benchmarks)
23 changes: 18 additions & 5 deletions bayeso_benchmarks/benchmark_base.py
@@ -1,21 +1,22 @@
#
# author: Jungtaek Kim (jtkim@postech.ac.kr)
# last updated: May 1, 2021
# last updated: December 13, 2022
#

import numpy as np

EPSILON = 1e-4


class Function(object):
class Function:
def __init__(self, dimensionality, bounds, global_minimizers, global_minimum, function, dim_problem=None, seed=None):
assert isinstance(dimensionality, int) or dimensionality is np.inf
assert isinstance(bounds, np.ndarray)
assert isinstance(global_minimizers, np.ndarray)
assert isinstance(global_minimum, float)
assert callable(function)
assert isinstance(dim_problem, int) or dim_problem is None
assert isinstance(dim_problem, (type(None), int))
assert isinstance(seed, (type(None), int))
assert len(bounds.shape) == 2
assert bounds.shape[1] == 2
assert (bounds[:, 0] <= bounds[:, 1]).all()
Expand All @@ -30,6 +31,7 @@ def __init__(self, dimensionality, bounds, global_minimizers, global_minimum, fu
self.random_state = np.random.RandomState(seed)

self.validate_properties()
self.set_name()

@property
def dimensionality(self):
Expand All @@ -47,6 +49,14 @@ def global_minimizers(self):
def global_minimum(self):
return self._global_minimum

def set_name(self):
name = self.__class__.__name__.lower()

if self.dimensionality is np.inf:
self.name = f'{name}_{self.dim_problem}'
else:
self.name = name

def get_bounds(self):
if self.dimensionality is np.inf:
return np.array(list(self.bounds) * self.dim_problem)
Expand Down Expand Up @@ -134,7 +144,7 @@ def output_sparse_gaussian_noise(self, X, scale_noise=0.1, sparsity=0.01):

noise = self.random_state.randn(num_X)
mask = self.random_state.uniform(low=0.0, high=1.0, size=num_X) < sparsity
noise *= mask.astype(np.float)
noise *= mask.astype(float)
by += scale_noise * noise

Y = np.expand_dims(by, axis=1)
Expand Down Expand Up @@ -172,7 +182,7 @@ def output_sparse_student_t_noise(self, X, scale_noise=0.1, dof=4.0, sparsity=0.

noise = self.random_state.standard_t(dof, size=num_X)
mask = self.random_state.uniform(low=0.0, high=1.0, size=num_X) < sparsity
noise *= mask.astype(np.float)
noise *= mask.astype(float)
by += scale_noise * noise

Y = np.expand_dims(by, axis=1)
Expand Down Expand Up @@ -228,3 +238,6 @@ def sample_uniform(self, num_points, seed=None):
points = bounds[:, 0] + (bounds[:, 1] - bounds[:, 0]) * points

return points

def __call__(self, X):
return self.output(X)
48 changes: 48 additions & 0 deletions bayeso_benchmarks/four_dim_colville.py
@@ -0,0 +1,48 @@
#
# author: Jungtaek Kim (jtkim@postech.ac.kr)
# last updated: December 30, 2022
#

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 = 100.0 * (bx[0]**2 - bx[1])**2
y += (bx[0] - 1.0)**2
y += (bx[2] - 1.0)**2
y += 90.0 * (bx[2]**2 - bx[3])**2
y += 10.1 * ((bx[1] - 1.0)**2 + (bx[3] - 1.0)**2)
y += 19.8 * (bx[1] - 1.0) * (bx[3] - 1.0)

return y


class Colville(Function):
def __init__(self, seed=None):
assert isinstance(seed, (type(None), int))

dim_bx = 4
bounds = np.array([
[-10.0, 10.0],
[-10.0, 10.0],
[-10.0, 10.0],
[-10.0, 10.0],
])
assert bounds.shape[0] == dim_bx
assert bounds.shape[1] == 2

global_minimizers = np.array([
[1.0, 1.0, 1.0, 1.0],
])
global_minimum = 0.0
function = lambda bx: fun_target(bx, dim_bx)

try:
super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed)
except:
super(Colville, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed)
45 changes: 45 additions & 0 deletions bayeso_benchmarks/inf_dim_griewank.py
@@ -0,0 +1,45 @@
#
# author: Jungtaek Kim (jtkim@postech.ac.kr)
# last updated: January 6, 2023
#

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

first_term = np.sum(bx**2 / 4000.0)

second_term = 1.0
for ind in range(1, dim_bx + 1):
second_term *= np.cos(bx[ind - 1] / np.sqrt(ind))

y = first_term - second_term + 1.0
return y


class Griewank(Function):
def __init__(self, dim_problem, seed=None):
assert isinstance(dim_problem, int)
assert isinstance(seed, (type(None), int))

dim_bx = np.inf
bounds = np.array([
[-600.0, 600.0],
])
global_minimizers = np.array([
[0.0],
])
global_minimum = 0.0
dim_problem = dim_problem

function = lambda bx: fun_target(bx, dim_problem)

try:
super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed)
except:
super(Griewank, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed)
51 changes: 51 additions & 0 deletions bayeso_benchmarks/inf_dim_levy.py
@@ -0,0 +1,51 @@
#
# author: Jungtaek Kim (jtkim@postech.ac.kr)
# last updated: December 29, 2022
#

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

bw = []
for x in bx:
w = 1.0 + (x - 1.0) / 4.0
bw.append(w)
bw = np.array(bw)

y = np.sin(np.pi * bw[0])**2

for w in bw[:-1]:
y += (w - 1.0)**2 * (1.0 + 10.0 * np.sin(np.pi * w + 1.0)**2)

y += (bw[-1] - 1.0)**2 * (1.0 + np.sin(2.0 * np.pi * bw[-1])**2)
return y


class Levy(Function):
def __init__(self, dim_problem, seed=None):
assert isinstance(dim_problem, int)
assert isinstance(seed, (type(None), int))

dim_bx = np.inf
bounds = np.array([
[-10.0, 10.0],
])
global_minimizers = np.array([
[1.0],
])
global_minimum = 0.0
dim_problem = dim_problem

function = lambda bx: fun_target(bx, dim_problem)

try:
super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed)
except:
super(Levy, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed)
43 changes: 43 additions & 0 deletions bayeso_benchmarks/inf_dim_rastrigin.py
@@ -0,0 +1,43 @@
#
# author: Jungtaek Kim (jtkim@postech.ac.kr)
# last updated: December 20, 2022
#

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 = 10.0 * dim_bx

for ind in range(0, dim_bx):
y += bx[ind]**2 - 10.0 * np.cos(2.0 * np.pi * bx[ind])

return y


class Rastrigin(Function):
def __init__(self, dim_problem, seed=None):
assert isinstance(dim_problem, int)
assert isinstance(seed, (type(None), int))

dim_bx = np.inf
bounds = np.array([
[-5.12, 5.12],
])
global_minimizers = np.array([
[0.0],
])
global_minimum = 0.0
dim_problem = dim_problem

function = lambda bx: fun_target(bx, dim_problem)

try:
super().__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed)
except:
super(Rastrigin, self).__init__(dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed)

0 comments on commit 226d07d

Please sign in to comment.