started with bo node

This commit is contained in:
Niko Feith 2024-02-15 18:24:31 +01:00
parent 4b7dd8621a
commit 220d590c05
6 changed files with 78 additions and 0 deletions

View File

@ -10,6 +10,10 @@ find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME} rosidl_generate_interfaces(${PROJECT_NAME}
"srv/Query.srv" "srv/Query.srv"
"msg/Opt2Rep.msg"
"msg/Opt2UI.msg"
"msg/Task2Opt.msg"
"msg/UI2Opt.msg"
DEPENDENCIES DEPENDENCIES
) )

View File

@ -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

View File

@ -0,0 +1,5 @@
# Best parameter set so far
float32[] x_best
# parameters which were fixed by the user
bool[] fixed_parameters

View File

@ -0,0 +1,4 @@
# observed parameters
float32[] x_observed
# observed reward
float32 reward

View File

@ -0,0 +1,4 @@
# parameters which were fixed by the user
bool[] fixed_parameters
# parameters set by the user
float32[] set_parameter_values

View File

@ -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)