Skip to content

Commit 1b04115

Browse files
committed
updates following recent writeup, using node with best LLB as best node
1 parent 3b61d83 commit 1b04115

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

src/hiopbbpy/opt/bnbalgorithm.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,7 @@ def initialize(self, l0 = None, u0 = None, queue = None):
724724
# Least upper bound (LUB)
725725
self.best_node = root
726726
self.LUB = self.best_node.aq_U
727+
self.LLB = self.best_node.aq_L
727728
if queue is not None:
728729
print("root node acqf_L, acqf_U = ", root.aq_L, root.aq_U)
729730
for _, _, node in queue:
@@ -827,19 +828,23 @@ def bnboptimize(self, l_init, u_init):
827828
print("upper-bound = ", child.aq_U)
828829
assert child.aq_U >= child.aq_L, "ERROR: child upper bound < child lower bound for child"
829830
if child.aq_U <= self.LUB:
831+
self.LUB = child.aq_U
832+
if child.aq_L <= self.LLB:
830833
self.best_node = child
831-
self.LUB = self.best_node.aq_U
834+
self.LLB = self.best_node.aq_L
832835
updated_best_node = True
833-
gap_history.append(self.best_node.aq_U - self.best_node.aq_L)
834836
if not updated_best_node:
835837
print("best node not updated")
836-
print("min |child.aq_U - LUB| = ", min([abs(child.aq_U - self.LUB) for child in children]))
838+
print("min |child.aq_L - LLB| = ", min([abs(child.aq_L - self.LLB) for child in children]))
837839
if self.pure_BBS and self.sync_mode:
838-
idx = np.argmin([child.aq_U for child in children])
840+
print("forcing best node update")
841+
idx = np.argmin([child.aq_L for child in children])
839842
self.best_node = children[idx]
840-
self.LUB = self.best_node.aq_U
843+
self.LLB = self.best_node.aq_L
844+
updated_best_node = True
841845
else:
842846
print("best node updated")
847+
gap_history.append(self.best_node.aq_U - self.best_node.aq_L)
843848

844849
# pre-prune
845850
children_lower_bounds = [child.aq_L for child in children]
@@ -1387,7 +1392,6 @@ def compute_acqf_bounds(self, l, u, skip_LB=False):
13871392
acqf_solve_success = False
13881393
if not self.acqf_UB_solver == "MINEVAL": # local gradient-based optimization method
13891394
constraints = []
1390-
#box_bounds = [[l[i], u[i]] for i in range(len(l))]
13911395
box_bounds = np.array([l, u]).T
13921396
acqf_callback = {'obj' : self.acqf.scalar_evaluate}
13931397
if self.acqf.has_gradient:

src/hiopbbpy/opt/boalgorithm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
import numpy as np
99
from numpy.random import uniform
1010
from scipy.stats import qmc
11+
from scipy.optimize import minimize
1112
from ..surrogate_modeling.gp import GaussianProcess
1213
from .acquisition import LCBacquisition, EIacquisition
1314
from ..problems.problem import Problem
1415
from ..utils.util import Evaluator, Logger
1516
from .bnbalgorithm import BnBAlgorithm
1617
from .opt_utils import minimizer_wrapper
1718

19+
20+
1821
# A base class defining a general framework for Bayesian Optimization
1922
class BOAlgorithmBase:
2023
def __init__(self):

src/hiopbbpy/problems/BraninProblem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def _evaluate(self, x: np.ndarray) -> np.ndarray:
2929
ne, nx = x.shape
3030
assert nx == self.ndim
3131

32-
y = np.zeros((ne, 1), complex)
32+
y = np.zeros((ne, 1))
3333
b = 5.1 / (4.0 * (np.pi) ** 2)
3434
c = 5.0 / np.pi
3535
r = 6.0

src/hiopbbpy/surrogate_modeling/krg.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,26 @@
1212

1313

1414
class smtKRG(GaussianProcess):
15-
def __init__(self, theta, xlimits, ndim, corr="pow_exp", pow_exp_power=1.0, noise0=0.0, nugget = 100. * np.finfo(np.double).eps, random_state=None, hyper_opt="TNC", eval_noise=False):
15+
def __init__(self, theta0, xlimits, ndim, corr="pow_exp", pow_exp_power=1.0, noise0=0.0, nugget = 100. * np.finfo(np.double).eps, random_state=None, hyper_opt="TNC", eval_noise=False, fix_theta = False, theta_bounds=[0.1,10.]):
1616
super().__init__(ndim, xlimits)
1717
if random_state is None:
1818
random_state = 42
1919
design_space = DesignSpace(xlimits, random_state=random_state)
2020

21-
theta_bounds = [(10.0e0)**(-1.), 10.0e0]
21+
if fix_theta:
22+
theta_bounds_ = [theta0-1.e-8, theta0+1.e-8]
23+
else:
24+
theta_bounds_ = theta_bounds
2225
self.surrogatesmt = KRG(design_space=design_space,
2326
print_global=False,
2427
noise0=[noise0],
2528
eval_noise=False,
2629
corr=corr,
2730
pow_exp_power=pow_exp_power,
2831
hyper_opt=hyper_opt,
29-
theta0 = [theta],
32+
theta0 = [theta0] * ndim,
3033
nugget=nugget,
31-
theta_bounds=theta_bounds,
34+
theta_bounds=theta_bounds_,
3235
)
3336
self.trained = False
3437

0 commit comments

Comments
 (0)