def add_action(self, action: Action) -> None: assert action.get_index() == len(self._actions) self._actions.append(action) if action.get_index() == 0: self._min_speed = action.get_speed() self._max_speed = action.get_speed() else: self._min_speed = min(self._min_speed, action.get_speed()) self._max_speed = max(self._max_speed, action.get_speed()) self._speed_range = self._max_speed - self._min_speed
def _get_action_space_from_json(received_json): action_space = ActionSpace() for action_json in received_json["action_space"]: speed = action_json["speed"] steering_angle = action_json["steering_angle"] index = action_json["index"] action_space.add_action(Action(index, speed, steering_angle)) return action_space
def _parse_actions(line_of_text: str, log_meta: LogMeta, starts_with: str): raw_actions = line_of_text[len(starts_with):].replace("'", "\"") actions = json.loads(raw_actions) for index, a in enumerate(actions): if "index" in a: assert a["index"] == index new_action = Action(index, a["speed"], a["steering_angle"]) log_meta.action_space.add_action(new_action)
def parse_intro_event(str, log_meta: LogMeta): if contains_hyper(str, HYPER_BATCH_SIZE): log_meta.hyper.batch_size = get_hyper_integer_value( str, HYPER_BATCH_SIZE) if contains_hyper(str, HYPER_ENTROPY): log_meta.hyper.entropy = get_hyper_float_value(str, HYPER_ENTROPY) if contains_hyper(str, HYPER_DISCOUNT_FACTOR): log_meta.hyper.discount_factor = get_hyper_float_value( str, HYPER_DISCOUNT_FACTOR) if contains_hyper(str, HYPER_LOSS_TYPE): log_meta.hyper.loss_type = get_hyper_string_value(str, HYPER_LOSS_TYPE) if contains_hyper(str, HYPER_LEARNING_RATE): log_meta.hyper.learning_rate = get_hyper_float_value( str, HYPER_LEARNING_RATE) if contains_hyper(str, HYPER_EPISODES_BETWEEN_TRAINING): log_meta.hyper.episodes_between_training = get_hyper_integer_value( str, HYPER_EPISODES_BETWEEN_TRAINING) if contains_hyper(str, HYPER_EPOCHS): log_meta.hyper.epochs = get_hyper_integer_value(str, HYPER_EPOCHS) if contains_parameter(str, PARAM_WORLD_NAME): log_meta.world_name = get_parameter_string_value(str, PARAM_WORLD_NAME) if contains_parameter(str, PARAM_RACE_TYPE): log_meta.race_type = get_parameter_string_value(str, PARAM_RACE_TYPE) if contains_parameter(str, PARAM_JOB_TYPE): log_meta.job_type = get_parameter_string_value(str, PARAM_JOB_TYPE) if str.startswith(MISC_MODEL_NAME): log_meta.model_name = str.split("/")[1] # print("FOUND MODEL NAME:", log_meta.model_name) if str.startswith(MISC_ACTION_SPACE): raw_actions = str[len(MISC_ACTION_SPACE):].replace("'", "\"") actions = json.loads(raw_actions) for a in actions: new_action = Action(a["index"], a["speed"], a["steering_angle"]) log_meta.action_space[a["index"]] = new_action
def is_low_speed_action(self, action: Action): return self.is_low_speed(action.get_speed())
def is_medium_speed_action(self, action: Action): return self.is_medium_speed(action.get_speed())
def is_straight_action(action: Action): return action.is_steering_straight()