def __init__(self):
     env_input_size: int = 6
     super().__init__(env_input_size)
     self.post_fn_remote = self.post_milp
     self.get_nn_fn = self.get_nn
     self.plot_fn = self.plot
     self.template_2d: np.ndarray = np.array([[1, 0, 0, 0, 0, 0],
                                              [1, -1, 0, 0, 0, 0]])
     input_boundaries, input_template = self.get_template(0)
     self.input_boundaries: List = input_boundaries
     self.input_template: np.ndarray = input_template
     _, template = self.get_template(1)
     self.analysis_template: np.ndarray = template
     collision_distance = 0
     distance = [Experiment.e(6, 0) - Experiment.e(6, 1)]
     # self.use_bfs = True
     # self.n_workers = 1
     self.rounding_value = 2**10
     self.use_rounding = False
     self.time_horizon = 40000
     self.unsafe_zone: List[Tuple] = [(distance,
                                       np.array([collision_distance]))]
     self.input_epsilon = 0
     # self.nn_path = os.path.join(utils.get_save_dir(),"tune_PPO_stopping_car/PPO_StoppingCar_acc24_00000_0_cost_fn=0,epsilon_input=0_2021-01-21_02-30-49/checkpoint_39/checkpoint-39")
     self.nn_path = os.path.join(
         utils.get_save_dir(),
         "tune_PPO_stopping_car/PPO_StoppingCar_acc24_00001_1_cost_fn=0,epsilon_input=0_2021-01-21_02-30-49/checkpoint_58/checkpoint-58"
     )
Ejemplo n.º 2
0
 def get_template(self, mode=0):
     p = Experiment.e(self.env_input_size, 0)
     v = Experiment.e(self.env_input_size, 1)
     if mode == 0:  # box directions with intervals
         # input_boundaries = [0, 0, 10, 10]
         input_boundaries = [9, -8, 0, 0.1]
         # optimise in a direction
         template = []
         for dimension in range(self.env_input_size):
             template.append(Experiment.e(self.env_input_size, dimension))
             template.append(-Experiment.e(self.env_input_size, dimension))
         template = np.array(template)  # the 6 dimensions in 2 variables
         return input_boundaries, template
     if mode == 1:  # directions to easily find fixed point
         input_boundaries = None
         template = np.array([v + p, -v - p, -p])
         return input_boundaries, template
Ejemplo n.º 3
0
 def __init__(self):
     env_input_size: int = 2
     super().__init__(env_input_size)
     self.post_fn_remote = self.post_milp
     self.get_nn_fn = self.get_nn
     self.plot_fn = self.plot
     self.template_2d: np.ndarray = np.array([[0, 1], [1, 0]])
     input_boundaries, input_template = self.get_template(0)
     self.input_boundaries: List = input_boundaries
     self.input_template: np.ndarray = input_template
     _, template = self.get_template(0)
     self.analysis_template: np.ndarray = template
     self.time_horizon = 500
     self.rounding_value = 2**8
     p = Experiment.e(self.env_input_size, 0)
     v = Experiment.e(self.env_input_size, 1)
     self.unsafe_zone: List[Tuple] = [([p, -v, v], np.array([0, 1, 0]))]
     self.nn_path = os.path.join(
         utils.get_save_dir(),
         "tune_PPO_bouncing_ball/PPO_BouncingBall_c7326_00000_0_2021-01-16_05-43-36/checkpoint_36/checkpoint-36"
     )
Ejemplo n.º 4
0
 def get_template(self, mode=0):
     x = Experiment.e(self.env_input_size, 0)
     x_dot = Experiment.e(self.env_input_size, 1)
     theta = Experiment.e(self.env_input_size, 2)
     theta_dot = Experiment.e(self.env_input_size, 3)
     if mode == 0:  # box directions with intervals
         # input_boundaries = [0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05]
         input_boundaries = [0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05]
         # input_boundaries = [0.04373426, -0.04373426, -0.04980056, 0.04980056, 0.045, -0.045, -0.51, 0.51]
         # optimise in a direction
         template = []
         for dimension in range(self.env_input_size):
             template.append(Experiment.e(self.env_input_size, dimension))
             template.append(-Experiment.e(self.env_input_size, dimension))
         template = np.array(template)  # the 6 dimensions in 2 variables
         return input_boundaries, template
     if mode == 1:  # directions to easily find fixed point
         input_boundaries = None
         template = np.array([
             theta, -theta, theta_dot, -theta_dot, theta + theta_dot,
             -(theta + theta_dot), (theta - theta_dot), -(theta - theta_dot)
         ])  # x_dot, -x_dot,theta_dot - theta
         return input_boundaries, template
     if mode == 2:
         input_boundaries = None
         template = np.array([theta, -theta, theta_dot, -theta_dot])
         return input_boundaries, template
     if mode == 3:
         input_boundaries = None
         template = np.array([theta, theta_dot, -theta_dot])
         return input_boundaries, template
     if mode == 4:
         input_boundaries = [0.09375, 0.625, 0.625, 0.0625, 0.1875]
         # input_boundaries = [0.09375, 0.5, 0.5, 0.0625, 0.09375]
         template = np.array([
             theta, theta_dot, -theta_dot, theta + theta_dot,
             (theta - theta_dot)
         ])
         return input_boundaries, template
     if mode == 5:
         input_boundaries = [0.125, 0.0625, 0.1875]
         template = np.array(
             [theta, theta + theta_dot, (theta - theta_dot)])
         return input_boundaries, template
    def get_template(self, mode=0):
        x_lead = Experiment.e(6, 0)
        x_ego = Experiment.e(6, 1)
        v_lead = Experiment.e(6, 2)
        v_ego = Experiment.e(6, 3)
        a_lead = Experiment.e(6, 4)
        a_ego = Experiment.e(6, 5)
        if mode == 0:  # box directions with intervals
            input_boundaries = [
                50, -40, 10, -0, 28, -28, 36, -36, 0, -0, 0, -0, 0
            ]
            # optimise in a direction
            template = []
            for dimension in range(6):
                template.append(Experiment.e(6, dimension))
                template.append(-Experiment.e(6, dimension))
            template = np.array(template)  # the 6 dimensions in 2 variables

            # t1 = [0] * 6
            # t1[0] = -1
            # t1[1] = 1
            # template = np.vstack([template, t1])
            return input_boundaries, template
        if mode == 1:  # directions to easily find fixed point

            input_boundaries = [20]

            template = np.array([
                a_lead, -a_lead, a_ego, -a_ego, -v_lead, v_lead,
                -(v_lead - v_ego), (v_lead - v_ego), -(x_lead - x_ego),
                (x_lead - x_ego)
            ])
            return input_boundaries, template
        if mode == 2:
            input_boundaries = [
                0, -100, 30, -31, 20, -30, 0, -35, 0, -0, -10, -10, 20
            ]
            # optimise in a direction
            template = []
            for dimension in range(6):
                t1 = [0] * 6
                t1[dimension] = 1
                t2 = [0] * 6
                t2[dimension] = -1
                template.append(t1)
                template.append(t2)
            # template = np.array([[0, 1], [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [-1, 1]])  # the 8 dimensions in 2 variables
            template = np.array(template)  # the 6 dimensions in 2 variables

            t1 = [0] * 6
            t1[0] = 1
            t1[1] = -1
            template = np.vstack([template, t1])
            return input_boundaries, template
        if mode == 3:  # single point box directions +diagonal
            input_boundaries = [
                30, -30, 0, -0, 28, -28, 36, -36, 0, -0, 0, -0, 0
            ]
            # optimise in a direction
            template = []
            for dimension in range(6):
                t1 = [0] * 6
                t1[dimension] = 1
                t2 = [0] * 6
                t2[dimension] = -1
                template.append(t1)
                template.append(t2)
            # template = np.array([[0, 1], [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [-1, 1]])  # the 8 dimensions in 2 variables
            template = np.array(template)  # the 6 dimensions in 2 variables

            t1 = [0] * 6
            t1[0] = -1
            t1[1] = 1
            template = np.vstack([template, t1])
            return input_boundaries, template
        if mode == 4:  # octagon, every pair of variables
            input_boundaries = [20]
            template = []
            for dimension in range(6):
                t1 = [0] * 6
                t1[dimension] = 1
                t2 = [0] * 6
                t2[dimension] = -1
                template.append(t1)
                template.append(t2)
                for other_dimension in range(dimension + 1, 6):
                    t1 = [0] * 6
                    t1[dimension] = 1
                    t1[other_dimension] = -1
                    t2 = [0] * 6
                    t2[dimension] = -1
                    t2[other_dimension] = 1
                    t3 = [0] * 6
                    t3[dimension] = 1
                    t3[other_dimension] = 1
                    t4 = [0] * 6
                    t4[dimension] = -1
                    t4[other_dimension] = -1
                    template.append(t1)
                    template.append(t2)
                    template.append(t3)
                    template.append(t4)
            return input_boundaries, np.array(template)