diff --git a/src/interaction_msgs/CMakeLists.txt b/src/interaction_msgs/CMakeLists.txt index 84bd50e..b23126b 100644 --- a/src/interaction_msgs/CMakeLists.txt +++ b/src/interaction_msgs/CMakeLists.txt @@ -10,6 +10,10 @@ find_package(rosidl_default_generators REQUIRED) rosidl_generate_interfaces(${PROJECT_NAME} "srv/Query.srv" + "msg/Opt2Rep.msg" + "msg/Opt2UI.msg" + "msg/Task2Opt.msg" + "msg/UI2Opt.msg" DEPENDENCIES ) diff --git a/src/interaction_msgs/msg/Opt2Rep.msg b/src/interaction_msgs/msg/Opt2Rep.msg new file mode 100644 index 0000000..ecc174f --- /dev/null +++ b/src/interaction_msgs/msg/Opt2Rep.msg @@ -0,0 +1,6 @@ +# Number of dimensions of the representation model +uint16 nr_dim +# Number of parameters per dimensions +uint16 nr_parameter +# Next parameters +float32[] x_next diff --git a/src/interaction_msgs/msg/Opt2UI.msg b/src/interaction_msgs/msg/Opt2UI.msg new file mode 100644 index 0000000..9b61c81 --- /dev/null +++ b/src/interaction_msgs/msg/Opt2UI.msg @@ -0,0 +1,5 @@ +# Best parameter set so far +float32[] x_best + +# parameters which were fixed by the user +bool[] fixed_parameters \ No newline at end of file diff --git a/src/interaction_msgs/msg/Task2Opt.msg b/src/interaction_msgs/msg/Task2Opt.msg new file mode 100644 index 0000000..3a3249c --- /dev/null +++ b/src/interaction_msgs/msg/Task2Opt.msg @@ -0,0 +1,4 @@ +# observed parameters +float32[] x_observed +# observed reward +float32 reward \ No newline at end of file diff --git a/src/interaction_msgs/msg/UI2Opt.msg b/src/interaction_msgs/msg/UI2Opt.msg new file mode 100644 index 0000000..bbcc997 --- /dev/null +++ b/src/interaction_msgs/msg/UI2Opt.msg @@ -0,0 +1,4 @@ +# parameters which were fixed by the user +bool[] fixed_parameters +# parameters set by the user +float32[] set_parameter_values \ No newline at end of file diff --git a/src/interaction_optimizers/interaction_optimizers/bayesian_optimization_node.py b/src/interaction_optimizers/interaction_optimizers/bayesian_optimization_node.py index 8b13789..6f7e4db 100644 --- a/src/interaction_optimizers/interaction_optimizers/bayesian_optimization_node.py +++ b/src/interaction_optimizers/interaction_optimizers/bayesian_optimization_node.py @@ -1 +1,56 @@ +import rclpy +from rclpy.node import Node + +from rclpy.callback_groups import ReentrantCallbackGroup + +from interaction_msgs.srv import Query + +from .optimizers.bayesian_optimization import BayesianOptimization + +import numpy as np +import time +import os + + +class BayesianOptimizationNode(Node): + def __init__(self): + super().__init__('bayesian_optimization_node') + + # reading parameters + self.kernel_type = self.declare_parameter('kernel_type', 'Matern').get_parameter_value().string_value + self.acquisition_function_name = (self.declare_parameter('acquisition_function_name', 'EI') + .get_parameter_value().string_value) + + # Subscribers + + # Publishers + + # Service Clients + self.query_client = self.create_client(Query, 'user_query') + + # Bayesian Optimization + self.bayesian_optimization = None + self.nr_bo_steps = 100 + self.nr_dimensions = 1 + self.nr_policy_parameters = 10 + + self.nr_init = 3 + self.seed = None + self.lower_bound = None + self.upper_bound = None + + def reset_bo(self, fixed_dimensions=None, **kwargs): + self.bayesian_optimization = BayesianOptimization(self.nr_bo_steps, + self.nr_dimensions, + self.nr_policy_parameters, + seed=self.seed, + fixed_dimensions=fixed_dimensions, + lower_bound=self.lower_bound, + upper_bound=self.upper_bound, + acquisition_function_name=self.acquisition_function_name, + kernel_type=self.kernel_type, **kwargs) + + + +