def __init__(self, BOdict, PolicyDict): self.PID_Object = PID_Objective(BOdict, PolicyDict) self.PIDMODE = BOdict['POLICYMODE'] evals = BOdict['ITERATIONS'] zeros = [0, 0, 0] maximums = [300, 150, 20] if self.PIDMODE == 'EULER': self.n_parameters = 9 elif self.PIDMODE == 'HYBRID': self.n_parameters = 12 elif self.PIDMODE == 'RATE' or self.PIDMODE == 'ALL': self.n_parameters = 18 else: print("Invalid PID mode selected") sys.exit(0) self.task = OptTask(f=self.PID_Object, n_parameters=self.n_parameters, n_objectives=1, bounds=bounds( min=zeros * int(self.n_parameters / 3), max=maximums * int(self.n_parameters / 3)), task={'minimize'}, vectorized=False) # labels_param = ['KP_pitch','KI_pitch','KD_pitch', 'KP_roll' 'KI_roll', 'KD_roll', 'KP_yaw', 'KI_yaw', 'KD_yaw', 'KP_pitchRate', 'KI_pitchRate', 'KD_pitchRate', 'KP_rollRate', # 'KI_rollRate', 'KD_rollRate', "KP_yawRate", "KI_yawRate", "KD_yawRate"]) self.Stop = StopCriteria(maxEvals=evals) self.sim = BOdict['sim']
def __init__(self, cfg, opt_function): # self.Objective = SimulationOptimizer(bo_cfg, policy_cfg) self.b_cfg = cfg.bo self.p_cfg = cfg.policy self.cfg = cfg self.t_c = self.p_cfg.pid.params.terminal_cost self.l_c = self.p_cfg.pid.params.living_cost self.norm_cost = 1 self.policy = PidPolicy(cfg) evals = cfg.bo.iterations param_min = [0] * len(list(cfg.pid.params.min_values)) param_max = [1] * len(list(cfg.pid.params.max_values)) self.n_parameters = self.policy.numParameters self.n_pids = self.policy.numpids params_per_pid = self.n_parameters / self.n_pids assert params_per_pid % 1 == 0 params_per_pid = int(params_per_pid) self.task = OptTask(f=opt_function, n_parameters=self.n_parameters, n_objectives=1, bounds=bounds(min=param_min * self.n_pids, max=param_max * self.n_pids), task={'minimize'}, vectorized=False) # labels_param = ['KP_pitch','KI_pitch','KD_pitch', 'KP_roll' 'KI_roll', 'KD_roll', 'KP_yaw', 'KI_yaw', 'KD_yaw', 'KP_pitchRate', 'KI_pitchRate', 'KD_pitchRate', 'KP_rollRate', # 'KI_rollRate', 'KD_rollRate', "KP_yawRate", "KI_yawRate", "KD_yawRate"]) self.Stop = StopCriteria(maxEvals=evals) self.sim = cfg.bo.sim
from opto.opto.classes import StopCriteria from opto.utils import bounds from opto.opto.acq_func import EI from opto import regression from objective_functions import * import numpy as np import matplotlib.pyplot as plt from dotmap import DotMap init_vrep() load_scene('scenes/normal.ttt') obj_f = generate_f(parameter_mode='normal', objective_mode='single', steps=400) task = OptTask(f=obj_f, n_parameters=4, n_objectives=1, \ bounds=bounds(min=[1, -np.pi, 0, 0], max=[60, np.pi, 1, 1]), \ vectorized=False) stopCriteria = StopCriteria(maxEvals=50) p = DotMap() p.verbosity = 1 p.acq_func = EI(model=None, logs=None) p.optimizer = opto.CMAES p.model = regression.GP opt = opto.BO(parameters=p, task=task, stopCriteria=stopCriteria) opt.optimize() logs = opt.get_logs() print("Parameters: " + str(logs.get_parameters())) print("Objectives: " + str(logs.get_objectives())) exit_vrep()