Skip to content

Commit bc56779

Browse files
authored
Merge pull request #67 from ajnisbet/store-xy-during-init
Update X and Y during init
2 parents f243cfc + bac164e commit bc56779

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

bayes_opt/bayesian_optimization.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,28 +94,26 @@ def init(self, init_points):
9494
# points from self.explore method.
9595
self.init_points += list(map(list, zip(*l)))
9696

97-
# Create empty list to store the new values of the function
98-
y_init = []
97+
# Create empty arrays to store the new points and values of the function.
98+
self.X = np.empty((0, self.bounds.shape[0]))
99+
self.Y = np.empty(0)
99100

100101
# Evaluate target function at all initialization
101102
# points (random + explore)
102103
for x in self.init_points:
103-
104-
y_init.append(self.f(**dict(zip(self.keys, x))))
104+
self.X = np.vstack((self.X, np.asarray(x).reshape((1, -1))))
105+
self.Y = np.append(self.Y, self.f(**dict(zip(self.keys, x))))
105106

106107
if self.verbose:
107-
self.plog.print_step(x, y_init[-1])
108+
self.plog.print_step(x, self.Y[-1])
108109

109110
# Append any other points passed by the self.initialize method (these
110111
# also have a corresponding target value passed by the user).
111112
self.init_points += self.x_init
113+
self.X = np.vstack((self.X, np.asarray(self.x_init).reshape(-1, self.X.shape[1])))
112114

113115
# Append the target value of self.initialize method.
114-
y_init += self.y_init
115-
116-
# Turn it into np array and store.
117-
self.X = np.asarray(self.init_points)
118-
self.Y = np.asarray(y_init)
116+
self.Y = np.concatenate((self.Y, self.y_init))
119117

120118
# Updates the flag
121119
self.initialized = True

0 commit comments

Comments
 (0)