Skip to content

Commit

Permalink
UPDATE: move gp and others
Browse files Browse the repository at this point in the history
  • Loading branch information
jungtaekkim committed Aug 7, 2020
1 parent 35b5ef9 commit 637e9a4
Show file tree
Hide file tree
Showing 38 changed files with 1,690 additions and 956 deletions.
26 changes: 15 additions & 11 deletions bayeso/bo.py
Expand Up @@ -15,9 +15,10 @@
cma = None
import sobol_seq

from bayeso import gp
from bayeso import acquisition
from bayeso import constants
from bayeso.gp import gp
from bayeso.gp import gp_common
from bayeso.utils import utils_common
from bayeso.utils import utils_covariance
from bayeso.utils import utils_logger
Expand Down Expand Up @@ -539,8 +540,8 @@ def optimize(self, X_train, Y_train,
:param str_mlm_method: the name of marginal likelihood maximization method for Gaussian process regression.
:type str_mlm_method: str., optional
:returns: acquired example, candidates of acquired examples, acquisition function values over the candidates, covariance matrix by `hyps`, inverse matrix of the covariance matrix, hyperparameters optimized, and execution times. Shape: ((d, ), (`int_samples`, d), (`int_samples`, ), (n, n), (n, n), dict., dict.).
:rtype: (numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, dict., dict.)
:returns: acquired example, a dictionary of information. Shape: ((d, ), dict.).
:rtype: (numpy.ndarray, dict.)
:raises: AssertionError
Expand Down Expand Up @@ -577,9 +578,7 @@ def optimize(self, X_train, Y_train,
else: # pragma: no cover
if self.debug: logger.debug('hyps converged.')
hyps = self.historical_hyps[-1]
cov_X_X, inv_cov_X_X, _ = gp.get_kernel_inverse(X_train, hyps, self.str_cov, is_fixed_noise=is_fixed_noise, debug=self.debug)
elif str_mlm_method == 'probabilistic': # pragma: no cover
raise NotImplementedError('optimize: it will be added.')
cov_X_X, inv_cov_X_X, _ = gp_common.get_kernel_inverse(X_train, hyps, self.str_cov, is_fixed_noise=is_fixed_noise, debug=self.debug)
else: # pragma: no cover
raise ValueError('optimize: missing condition for str_mlm_method.')
time_end_gp = time.time()
Expand All @@ -597,12 +596,17 @@ def optimize(self, X_train, Y_train,

time_end = time.time()

times = {
'overall': time_end - time_start,
'gp': time_end_gp - time_start_gp,
'acq': time_end_acq - time_start_acq,
dict_info = {
'next_points': next_points,
'acquisitions': acquisitions,
'cov_X_X': cov_X_X,
'inv_cov_X_X': inv_cov_X_X,
'hyps': hyps,
'time_overall': time_end - time_start,
'time_gp': time_end_gp - time_start_gp,
'time_acq': time_end_acq - time_start_acq,
}

if self.debug: logger.debug('overall time consumed to acquire: {:.4f} sec.'.format(time_end - time_start))

return next_point, next_points, acquisitions, cov_X_X, inv_cov_X_X, hyps, times
return next_point, dict_info
3 changes: 2 additions & 1 deletion bayeso/constants.py
Expand Up @@ -37,7 +37,7 @@
TIME_PAUSE = 2.0
RANGE_SHADE = 1.96

ALLOWED_OPTIMIZER_METHOD_GP = ['BFGS', 'L-BFGS-B', 'DIRECT', 'CMA-ES']
ALLOWED_OPTIMIZER_METHOD_GP = ['BFGS', 'L-BFGS-B', 'DIRECT']
ALLOWED_OPTIMIZER_METHOD_BO = ['L-BFGS-B', 'DIRECT', 'CMA-ES']
# INFO: Do not use _ (underscore) in base str_cov.
ALLOWED_GP_COV_BASE = ['se', 'matern32', 'matern52']
Expand All @@ -48,6 +48,7 @@
ALLOWED_INITIALIZATIONS_AO = ALLOWED_INITIALIZATIONS_BO + ['grid']
ALLOWED_MLM_METHOD = ['regular', 'converged']
ALLOWED_MODELSELECTION_METHOD = ['ml', 'loocv']
ALLOWED_FRAMEWORK_GP = ['scipy', 'tensorflow']

KEYS_INFO_BENCHMARK = ['dim_fun', 'bounds', 'global_minimum_X', 'global_minimum_y']

Expand Down

0 comments on commit 637e9a4

Please sign in to comment.