Skip to content

Commit

Permalink
Merge pull request #1 from jungtaekkim/0.1.4
Browse files Browse the repository at this point in the history
0.1.4
  • Loading branch information
jungtaekkim committed Apr 19, 2021
2 parents ba942fe + 4f58d5d commit 2a34823
Show file tree
Hide file tree
Showing 75 changed files with 539 additions and 157 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -129,6 +129,6 @@ dmypy.json
.pyre/

# Jungtaek
*.swp
.DS_Store
__MACOSX/
*.swp
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -6,6 +6,7 @@ python:
- "3.6"
- "3.7"
- "3.8"
- "3.9"
install:
- pip install .
script:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Jungtaek Kim
Copyright (c) 2019-2021 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
2 changes: 1 addition & 1 deletion MANIFEST.in
@@ -1,2 +1,2 @@
include LICENSE
include requirements.txt
include LICENSE
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -6,7 +6,7 @@ Benchmarks for Bayesian optimization.
The details of benchmark functions can be found in [these notes](http://jungtaek.github.io/notes/benchmarks_bo.pdf).

## Installation
We recommend it should be installed in `virtualenv`.
We recommend installing it with `virtualenv`.
You can choose one of three installation options.

* Using PyPI repository (for user installation)
Expand Down Expand Up @@ -51,7 +51,7 @@ The following `requirements` files include the package list, the purpose of whic
* `requirements-dev.txt`: It is for developing the `bayeso-benchmarks` package.

## Author
* [Jungtaek Kim](http://mlg.postech.ac.kr/~jtkim/) (POSTECH)
* [Jungtaek Kim](http://jungtaek.github.io) (POSTECH)

## Contact
* Jungtaek Kim: [jtkim@postech.ac.kr](mailto:jtkim@postech.ac.kr)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/__init__.py → bayeso_benchmarks/__init__.py
Expand Up @@ -3,4 +3,4 @@
# last updated: November 5, 2020
#

__version__ = '0.1.3'
__version__ = '0.1.4'
@@ -1,6 +1,6 @@
#
# author: Jungtaek Kim (jtkim@postech.ac.kr)
# last updated: November 5, 2020
# last updated: February 8, 2021
#

import numpy as np
Expand All @@ -9,7 +9,7 @@


class Function(object):
def __init__(self, dimensionality, bounds, global_minimizers, global_minimum, function, dim_problem=None):
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)
Expand All @@ -27,6 +27,7 @@ def __init__(self, dimensionality, bounds, global_minimizers, global_minimum, fu
self._function = function

self.dim_problem = dim_problem
self.random_state = np.random.RandomState(seed)

self.validate_properties()

Expand Down Expand Up @@ -70,7 +71,7 @@ def function(self, bx):

return self._function(bx)

def output(self, X):
def _output(self, X):
assert isinstance(X, np.ndarray)

if len(X.shape) == 2:
Expand All @@ -79,22 +80,20 @@ def output(self, X):
list_results = [self.function(X)]

by = np.array(list_results)
return by

def output(self, X):
by = self._output(X)
Y = np.expand_dims(by, axis=1)

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

def output_constant_noise(self, X, scale_noise=0.01):
assert isinstance(X, np.ndarray)
assert isinstance(scale_noise, float)

if len(X.shape) == 2:
list_results = [self.function(bx) for bx in X]
else:
list_results = [self.function(X)]

by = np.array(list_results)
by = self._output(X)
by += scale_noise

Y = np.expand_dims(by, axis=1)
Expand All @@ -104,16 +103,10 @@ def output_constant_noise(self, X, scale_noise=0.01):
return Y

def output_gaussian_noise(self, X, scale_noise=0.01):
assert isinstance(X, np.ndarray)
assert isinstance(scale_noise, float)

if len(X.shape) == 2:
list_results = [self.function(bx) for bx in X]
else:
list_results = [self.function(X)]

by = np.array(list_results)
by += scale_noise * np.random.randn(by.shape[0])
by = self._output(X)
by += scale_noise * self.random_state.randn(by.shape[0])

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

Expand All @@ -122,23 +115,20 @@ def output_gaussian_noise(self, X, scale_noise=0.01):
return Y

def output_sparse_gaussian_noise(self, X, scale_noise=0.1, sparsity=0.01):
assert isinstance(X, np.ndarray)
assert isinstance(scale_noise, 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]
list_results = [self.function(bx) for bx in X]
else:
num_X = 1
list_results = [self.function(X)]

by = np.array(list_results)

noise = np.random.randn(num_X)
mask = np.random.uniform(low=0.0, high=1.0, size=num_X) < sparsity
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)
by += scale_noise * noise

Expand Down
@@ -1,11 +1,11 @@
#
# author: Jungtaek Kim (jtkim@postech.ac.kr)
# last updated: November 5, 2020
# last updated: February 8, 2021
#

import numpy as np

from benchmarks.benchmark_base import Function
from bayeso_benchmarks.benchmark_base import Function


def fun_target(bx, dim_bx,
Expand Down
@@ -1,11 +1,11 @@
#
# author: Jungtaek Kim (jtkim@postech.ac.kr)
# last updated: November 5, 2020
# last updated: February 8, 2021
#

import numpy as np

from benchmarks.benchmark_base import Function
from bayeso_benchmarks.benchmark_base import Function


def fun_target(bx, dim_bx):
Expand Down
@@ -1,6 +1,11 @@
#
# author: Jungtaek Kim (jtkim@postech.ac.kr)
# last updated: February 8, 2021
#

import numpy as np

from benchmarks.benchmark_base import Function
from bayeso_benchmarks.benchmark_base import Function


def fun_target(bx, dim_bx):
Expand All @@ -17,6 +22,7 @@ def fun_target(bx, dim_bx):
class Rosenbrock(Function):
def __init__(self, dim_problem):
assert isinstance(dim_problem, int)
assert dim_problem > 1

dim_bx = np.inf
bounds = np.array([
Expand Down
@@ -1,11 +1,11 @@
#
# author: Jungtaek Kim (jtkim@postech.ac.kr)
# last updated: November 5, 2020
# last updated: February 8, 2021
#

import numpy as np

from benchmarks.benchmark_base import Function
from bayeso_benchmarks.benchmark_base import Function


def fun_target(bx, dim_bx):
Expand Down
@@ -1,11 +1,11 @@
#
# author: Jungtaek Kim (jtkim@postech.ac.kr)
# last updated: November 5, 2020
# last updated: February 8, 2021
#

import numpy as np

from benchmarks.benchmark_base import Function
from bayeso_benchmarks.benchmark_base import Function


def fun_target(bx, dim_bx, constant):
Expand Down
@@ -1,11 +1,11 @@
#
# author: Jungtaek Kim (jtkim@postech.ac.kr)
# last updated: November 5, 2020
# last updated: February 8, 2021
#

import numpy as np

from benchmarks.benchmark_base import Function
from bayeso_benchmarks.benchmark_base import Function


def fun_target(bx, dim_bx):
Expand Down
@@ -1,11 +1,11 @@
#
# author: Jungtaek Kim (jtkim@postech.ac.kr)
# last updated: November 5, 2020
# last updated: February 8, 2021
#

import numpy as np

from benchmarks.benchmark_base import Function
from bayeso_benchmarks.benchmark_base import Function


def fun_target(bx, dim_bx, slope):
Expand Down
@@ -1,11 +1,11 @@
#
# author: Jungtaek Kim (jtkim@postech.ac.kr)
# last updated: November 5, 2020
# last updated: February 8, 2021
#

import numpy as np

from benchmarks.benchmark_base import Function
from bayeso_benchmarks.benchmark_base import Function


def fun_target(bx, dim_bx, steps, step_values):
Expand Down

0 comments on commit 2a34823

Please sign in to comment.