Skip to content

Commit

Permalink
Merge pull request #2 from jungtaekkim/0.1.5
Browse files Browse the repository at this point in the history
0.1.5
  • Loading branch information
jungtaekkim authored Oct 16, 2021
2 parents 2a34823 + 3bdf8e8 commit 823a345
Show file tree
Hide file tree
Showing 72 changed files with 562 additions and 162 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ python:
install:
- pip install .
script:
- pip install scipy
- pytest
notifications:
slack: bayeso:FWBoHH9TMqjKUJWkZxCaTNVE
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# BayesO Benchmarks
[![Build Status](https://travis-ci.org/jungtaekkim/bayeso-benchmarks.svg?branch=main)](https://travis-ci.org/jungtaekkim/bayeso-benchmarks)
[![Build Status](https://travis-ci.com/jungtaekkim/bayeso-benchmarks.svg?branch=main)](https://travis-ci.com/jungtaekkim/bayeso-benchmarks)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Benchmarks for Bayesian optimization.
Expand Down Expand Up @@ -50,6 +50,20 @@ The following `requirements` files include the package list, the purpose of whic

* `requirements-dev.txt`: It is for developing the `bayeso-benchmarks` package.

## Simple Example
A simple example on Branin function is shown below.
```python
from bayeso_benchmarks import Branin

obj_fun = Branin()
bounds = obj_fun.get_bounds()

X = obj_fun.sample_uniform(100)

Y = obj_fun.output(X)
Y_noise = obj_fun.output_gaussian_noise(X)
```

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

Expand Down
30 changes: 28 additions & 2 deletions bayeso_benchmarks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
#
# author: Jungtaek Kim ([email protected])
# last updated: November 5, 2020
# last updated: June 24, 2021
#

__version__ = '0.1.4'
__version__ = '0.1.5'


from bayeso_benchmarks.inf_dim_ackley import Ackley
from bayeso_benchmarks.inf_dim_cosines import Cosines
from bayeso_benchmarks.inf_dim_rosenbrock import Rosenbrock
from bayeso_benchmarks.inf_dim_sphere import Sphere

from bayeso_benchmarks.one_dim_constant import Constant
from bayeso_benchmarks.one_dim_gramacyandlee2012 import GramacyAndLee2012
from bayeso_benchmarks.one_dim_linear import Linear
from bayeso_benchmarks.one_dim_step import Step

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_dejong5 import DeJong5
from bayeso_benchmarks.two_dim_dropwave import DropWave
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_michalewicz import Michalewicz
from bayeso_benchmarks.two_dim_sixhumpcamel import SixHumpCamel
from bayeso_benchmarks.two_dim_threehumpcamel import ThreeHumpCamel

from bayeso_benchmarks.three_dim_hartmann3d import Hartmann3D
from bayeso_benchmarks.six_dim_hartmann6d import Hartmann6D
62 changes: 59 additions & 3 deletions bayeso_benchmarks/benchmark_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# author: Jungtaek Kim ([email protected])
# last updated: February 8, 2021
# last updated: May 1, 2021
#

import numpy as np
Expand Down Expand Up @@ -126,7 +126,7 @@ def output_sparse_gaussian_noise(self, X, scale_noise=0.1, sparsity=0.01):
num_X = X.shape[0]
else:
num_X = 1

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)
Expand All @@ -138,6 +138,44 @@ def output_sparse_gaussian_noise(self, X, scale_noise=0.1, sparsity=0.01):
assert Y.shape[1] == 1
return Y

def output_student_t_noise(self, X, scale_noise=0.01, dof=4.0):
assert isinstance(scale_noise, float)
assert isinstance(dof, float)

by = self._output(X)
by += scale_noise * self.random_state.standard_t(dof, size=by.shape[0])

Y = np.expand_dims(by, axis=1)

assert len(Y.shape) == 2
assert Y.shape[1] == 1
return Y

def output_sparse_student_t_noise(self, X, scale_noise=0.1, dof=4.0, sparsity=0.01):
assert isinstance(scale_noise, float)
assert isinstance(dof, float)
assert isinstance(sparsity, float)
assert sparsity >= 0.0 and sparsity <= 1.0
assert sparsity < 0.5

by = self._output(X)

if len(X.shape) == 2:
num_X = X.shape[0]
else:
num_X = 1

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)
by += scale_noise * noise

Y = np.expand_dims(by, axis=1)

assert len(Y.shape) == 2
assert Y.shape[1] == 1
return Y

def validate_properties(self):
shape_bounds = self.get_bounds().shape

Expand All @@ -154,7 +192,7 @@ def validate_properties(self):
else:
assert self.dimensionality == shape_bounds[0] == shape_global_minimizers[1]

def get_grids(self, num_grids):
def sample_grids(self, num_grids):
assert isinstance(num_grids, int)

list_grids = []
Expand All @@ -167,3 +205,21 @@ def get_grids(self, num_grids):
grids = np.vstack(tuple(list_grids))
grids = grids.T
return grids

def sample_uniform(self, num_points, seed=None):
assert isinstance(num_points, int)
assert isinstance(seed, (type(None), int))

random_state_ = np.random.RandomState(seed)

if self.dimensionality is np.inf:
dim_problem = self.dim_problem
else:
dim_problem = self.dimensionality

bounds = self.get_bounds()

points = random_state_.uniform(size=(num_points, dim_problem))
points = (bounds[:, 0] + (bounds[:, 1] - bounds[:, 0])) * points

return points
5 changes: 3 additions & 2 deletions bayeso_benchmarks/inf_dim_ackley.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ def fun_target(bx, dim_bx,


class Ackley(Function):
def __init__(self, dim_problem):
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([
Expand All @@ -39,4 +40,4 @@ def __init__(self, dim_problem):

function = lambda bx: fun_target(bx, dim_problem)

Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem)
Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed)
5 changes: 3 additions & 2 deletions bayeso_benchmarks/inf_dim_cosines.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ def fun_target(bx, dim_bx):


class Cosines(Function):
def __init__(self, dim_problem):
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([
Expand All @@ -32,4 +33,4 @@ def __init__(self, dim_problem):

function = lambda bx: fun_target(bx, dim_problem)

Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem)
Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed)
5 changes: 3 additions & 2 deletions bayeso_benchmarks/inf_dim_rosenbrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ def fun_target(bx, dim_bx):


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

dim_bx = np.inf
Expand All @@ -36,4 +37,4 @@ def __init__(self, dim_problem):

function = lambda bx: fun_target(bx, dim_problem)

Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem)
Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed)
5 changes: 3 additions & 2 deletions bayeso_benchmarks/inf_dim_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ def fun_target(bx, dim_bx):


class Sphere(Function):
def __init__(self, dim_problem):
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([
Expand All @@ -35,4 +36,4 @@ def __init__(self, dim_problem):

function = lambda bx: fun_target(bx, dim_problem)

Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem)
Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, dim_problem=dim_problem, seed=seed)
6 changes: 4 additions & 2 deletions bayeso_benchmarks/one_dim_constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ def __init__(self,
bounds = np.array([
[-10.0, 10.0],
]),
constant=0.0
constant=0.0,
seed=None
):
assert isinstance(constant, float)
assert isinstance(bounds, np.ndarray)
assert isinstance(seed, (type(None), int))
assert len(bounds.shape) == 2
assert bounds.shape[0] == 1
assert bounds.shape[1] == 2
Expand All @@ -41,4 +43,4 @@ def __init__(self,
global_minimum = constant
function = lambda bx: fun_target(bx, dim_bx, constant)

Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function)
Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed)
6 changes: 4 additions & 2 deletions bayeso_benchmarks/one_dim_gramacyandlee2012.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def fun_target(bx, dim_bx):


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

dim_bx = 1
bounds = np.array([
[0.5, 2.5],
Expand All @@ -28,4 +30,4 @@ def __init__(self):
global_minimum = -0.86901113
function = lambda bx: fun_target(bx, dim_bx)

Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function)
Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed)
6 changes: 4 additions & 2 deletions bayeso_benchmarks/one_dim_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ def __init__(self,
bounds=np.array([
[-10, 10],
]),
slope=1.0
slope=1.0,
seed=None
):
assert isinstance(slope, float)
assert isinstance(bounds, np.ndarray)
assert isinstance(seed, (type(None), int))
assert len(bounds.shape) == 2
assert bounds.shape[0] == 1
assert bounds.shape[1] == 2
Expand All @@ -45,4 +47,4 @@ def __init__(self,
global_minimum = slope * bounds[0, 1]
function = lambda bx: fun_target(bx, dim_bx, slope)

Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function)
Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed)
4 changes: 3 additions & 1 deletion bayeso_benchmarks/one_dim_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ class Step(Function):
def __init__(self,
steps=[-10., -5., 0., 5., 10.],
step_values=[-2., 0., 1., -1.],
seed=None
):
assert isinstance(steps, list)
assert isinstance(step_values, list)
assert isinstance(seed, (type(None), int))
assert len(steps) == len(step_values) + 1
assert isinstance(steps[0], float)
assert isinstance(step_values[0], float)
Expand All @@ -53,4 +55,4 @@ def __init__(self,
global_minimum = np.min(step_values)
function = lambda bx: fun_target(bx, dim_bx, steps, step_values)

Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function)
Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed)
6 changes: 4 additions & 2 deletions bayeso_benchmarks/six_dim_hartmann6d.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ def __init__(self,
[0.0, 1.0],
[0.0, 1.0],
[0.0, 1.0],
])
]),
seed=None
):
assert isinstance(bounds, np.ndarray)
assert isinstance(seed, (type(None), int))
assert len(bounds.shape) == 2
assert bounds.shape[1] == 2

Expand All @@ -61,4 +63,4 @@ def __init__(self,
global_minimum = -3.322368
function = lambda bx: fun_target(bx, dim_bx)

Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function)
Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed)
6 changes: 4 additions & 2 deletions bayeso_benchmarks/three_dim_hartmann3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ def __init__(self,
[0.0, 1.0],
[0.0, 1.0],
[0.0, 1.0],
])
]),
seed=None
):
assert isinstance(bounds, np.ndarray)
assert isinstance(seed, (type(None), int))
assert len(bounds.shape) == 2
assert bounds.shape[1] == 2

Expand All @@ -58,4 +60,4 @@ def __init__(self,
global_minimum = -3.86278
function = lambda bx: fun_target(bx, dim_bx)

Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function)
Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed)
6 changes: 4 additions & 2 deletions bayeso_benchmarks/two_dim_beale.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def fun_target(bx, dim_bx):


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

dim_bx = 2
bounds = np.array([
[-4.5, 4.5],
Expand All @@ -29,4 +31,4 @@ def __init__(self):
global_minimum = 0.0
function = lambda bx: fun_target(bx, dim_bx)

Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function)
Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed)
6 changes: 4 additions & 2 deletions bayeso_benchmarks/two_dim_bohachevsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def fun_target(bx, dim_bx):


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

dim_bx = 2
bounds = np.array([
[-100.0, 100.0],
Expand All @@ -29,4 +31,4 @@ def __init__(self):
global_minimum = 0.0
function = lambda bx: fun_target(bx, dim_bx)

Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function)
Function.__init__(self, dim_bx, bounds, global_minimizers, global_minimum, function, seed=seed)
Loading

0 comments on commit 823a345

Please sign in to comment.