added random, regular, max acquisition & improvement metric
This commit is contained in:
parent
952ee10b67
commit
c5f00a4069
@ -86,7 +86,7 @@ class BayesianOptimization:
|
|||||||
|
|
||||||
self.Y[i] = reward
|
self.Y[i] = reward
|
||||||
|
|
||||||
self.GP = GaussianProcessRegressor(Matern(nu=1.5))
|
self.GP = GaussianProcessRegressor(Matern(nu=1.5, length_scale_bounds=(1e-8, 1e5)), n_restarts_optimizer=5, )
|
||||||
self.GP.fit(self.X, self.Y)
|
self.GP.fit(self.X, self.Y)
|
||||||
|
|
||||||
def next_observation(self):
|
def next_observation(self):
|
||||||
@ -147,6 +147,8 @@ class BayesianOptimization:
|
|||||||
self.X = np.vstack((self.X, x_new))
|
self.X = np.vstack((self.X, x_new))
|
||||||
self.Y = np.vstack((self.Y, reward))
|
self.Y = np.vstack((self.Y, reward))
|
||||||
|
|
||||||
|
self.GP.fit(self.X, self.Y)
|
||||||
|
|
||||||
if self.episode == 0:
|
if self.episode == 0:
|
||||||
self.best_reward[0] = max(self.Y)
|
self.best_reward[0] = max(self.Y)
|
||||||
else:
|
else:
|
||||||
|
@ -132,12 +132,20 @@ class ActiveBOTopic(Node):
|
|||||||
|
|
||||||
def active_rl_callback(self, msg):
|
def active_rl_callback(self, msg):
|
||||||
if self.active_rl_pending:
|
if self.active_rl_pending:
|
||||||
self.get_logger().info('Active Reinforcement Learning response pending!')
|
self.get_logger().info('Active Reinforcement Learning response received!')
|
||||||
self.active_rl_pending = False
|
|
||||||
self.rl_weights = msg.weights
|
self.rl_weights = msg.weights
|
||||||
self.rl_final_step = msg.final_step
|
self.rl_final_step = msg.final_step
|
||||||
self.rl_reward = msg.reward
|
self.rl_reward = msg.reward
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.BO.add_new_observation(self.rl_reward, self.rl_weights)
|
||||||
|
self.get_logger().info('Active Reinforcement Learning added new observation!')
|
||||||
|
except Exception as e:
|
||||||
|
self.get_logger().error(f'Active Reinforcement Learning failed to add new observation: {e}')
|
||||||
|
|
||||||
|
self.active_rl_pending = False
|
||||||
|
self.reset_rl_response()
|
||||||
|
|
||||||
def mainloop_callback(self):
|
def mainloop_callback(self):
|
||||||
if self.active_bo_pending:
|
if self.active_bo_pending:
|
||||||
|
|
||||||
@ -181,18 +189,26 @@ class ActiveBOTopic(Node):
|
|||||||
else:
|
else:
|
||||||
if self.active_rl_pending:
|
if self.active_rl_pending:
|
||||||
pass
|
pass
|
||||||
elif self.rl_weights is not None and not self.active_rl_pending:
|
|
||||||
try:
|
|
||||||
self.BO.add_new_observation(self.rl_reward, self.rl_weights)
|
|
||||||
self.reset_rl_response()
|
|
||||||
except Exception as e:
|
|
||||||
self.get_logger().error(f'Active Reinforcement Learning failed to add new observation: {e}')
|
|
||||||
else:
|
else:
|
||||||
if self.current_episode < self.bo_episodes:
|
if self.current_episode < self.bo_episodes:
|
||||||
# metrics
|
# metrics
|
||||||
if self.bo_metric == "RandomQuery":
|
if self.bo_metric == "random":
|
||||||
user_query = RandomQuery(self.bo_metric_parameter)
|
user_query = RandomQuery(self.bo_metric_parameter)
|
||||||
|
|
||||||
|
elif self.bo_metric == "regular":
|
||||||
|
user_query = RegularQuery(self.bo_metric_parameter)
|
||||||
|
|
||||||
|
elif self.bo_metric == "max acquisition":
|
||||||
|
user_query = MaxAcqQuery(self.bo_metric_parameter,
|
||||||
|
self.BO.GP,
|
||||||
|
100,
|
||||||
|
self.bo_nr_weights,
|
||||||
|
acq=self.bo_acq_fcn,
|
||||||
|
X=self.BO.X)
|
||||||
|
|
||||||
|
elif self.bo_metric == "improvement":
|
||||||
|
user_query = ImprovementQuery(self.bo_metric_parameter, 10)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@ -234,7 +250,6 @@ class ActiveBOTopic(Node):
|
|||||||
self.get_logger().info(f'Current Run: {self.current_run}')
|
self.get_logger().info(f'Current Run: {self.current_run}')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main(args=None):
|
def main(args=None):
|
||||||
rclpy.init(args=args)
|
rclpy.init(args=args)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user