Esempio n. 1
0
    def __init__(self,
                 map_data,
                 main_sensor='None',
                 k_name="RBF",
                 acq="gaussian_sei",
                 acq_mod="masked"):
        # self.agents = agents
        self.map_data = map_data
        self.acquisition = acq  # 'gaussian_sei' 'gaussian_ei' 'maxvalue_entropy_search''gaussian_pi'
        self.acq_mod = acq_mod  # 'masked' 'split_path' 'truncated', 'normal'
        self.k_name = k_name  # "RBF" Matern" "RQ"
        if k_name == "RBF_N":
            self.gp = gpr.GaussianProcessRegressor(kernel=kernels.RBF(100),
                                                   alpha=1e-7)
        elif k_name == "RBF":
            self.gp = gpr.GaussianProcessRegressor(kernel=kernels.RBF(100.0),
                                                   alpha=1e-7)
            # self.gp = gpr.GaussianProcessRegressor(kernel=kernels.Matern(100, nu=3.5), alpha=1e-7)
        elif k_name == "RQ":
            self.gp = gpr.GaussianProcessRegressor(kernel=kernels.RBF(100),
                                                   alpha=1e-7)
            # self.gp = gpr.GaussianProcessRegressor(kernel=kernels.RationalQuadratic(100, 0.1), alpha=1e-7)

        self.data = [np.array([[], []]), np.array([])]

        self.all_vector_pos = np.mgrid[0:self.map_data.shape[1]:1,
                                       0:self.map_data.shape[0]:1].reshape(
                                           2, -1).T
        self.vector_pos = np.fliplr(
            np.asarray(np.where(self.map_data == 0)).reshape(2, -1).T)

        self.main_sensor = main_sensor
        self.splitted_goals = []
    def __init__(self, agents, map_data, main_sensor='None', acq="RU"):
        self.agents = agents
        self.map_data = map_data
        self.acquisition = 'gaussian_sei'
        self.gp = gpr.GaussianProcessRegressor(kernel=kernels.RBF(100),
                                               alpha=1e-7)
        # self.gp = gpr.GaussianProcessRegressor(kernel=kernels.Matern(150, nu=3.5), alpha=1e-7)
        # self.gp = gpr.GaussianProcessRegressor(kernel=kernels.RationalQuadratic(150, 0.1), alpha=1e-7)
        #         self.gp = gpr.GaussianProcessRegressor(normalize_y=True, kernel=20 * kernels.RBF(150), alpha=1e-7)
        self.data = [np.array([[], []]), np.array([])]

        self.acq_method = acq

        self.all_vector_pos = np.mgrid[0:self.map_data.shape[1]:1,
                                       0:self.map_data.shape[0]:1].reshape(
                                           2, -1).T

        self.vector_pos = np.fliplr(
            np.asarray(np.where(self.map_data == 0)).reshape(2, -1).T)

        self.main_sensor = main_sensor
        _x, _y = self.obtain_shapely_polygon().exterior.coords.xy
        self.fpx, self.fpy = self.obtain_points(_x, _y)

        # dists = []
        # for i in range(len(self.fpx) - 1):
        #     dists.append(np.linalg.norm(
        #         np.subtract(np.array([self.fpx[i], self.fpy[i]]), np.array([self.fpx[i + 1], self.fpy[i + 1]]))))
        #
        import matplotlib.pyplot as plt
        # plt.Figure()
        # plt.hist(dists)
        # print(np.mean(dists))
        # print(np.std(dists))
        plt.plot(self.fpx, self.fpy, '-*')
Esempio n. 3
0
    def __init__(self,
                 map_data,
                 sensors: set,
                 k_names=None,
                 d=1.0,
                 no_drones=2,
                 acq=0):
        if k_names is None:
            k_names = ["RBF"] * len(sensors)
        self.map_data = map_data
        self.k_names = k_names  # "RBF" Matern" "RQ"
        self.sensors = sensors
        self.gps = dict()
        self.train_inputs = [np.array([[], []])]
        self.train_targets = dict()
        self.proportion = d
        self.nans = None

        self.mus = dict()
        self.stds = dict()
        self.has_calculated = dict()

        for sensor, kernel in zip(sensors, k_names):
            if kernel == "RBF":  # "RBF" Matern" "RQ"
                self.gps[sensor] = gprnew.GaussianProcessRegressor(
                    kernel=kernels.RBF(100), alpha=1e-7)
                self.train_targets[sensor] = np.array([])
                self.mus[sensor] = np.array([])
                self.stds[sensor] = np.array([])
                self.has_calculated[sensor] = False

        self.all_vector_pos = np.mgrid[0:self.map_data.shape[1]:1,
                                       0:self.map_data.shape[0]:1].reshape(
                                           2, -1).T
        self.vector_pos = np.fliplr(
            np.asarray(np.where(self.map_data == 0)).reshape(2, -1).T)
        self.acq_method = acq % 4

        _x, _y = self.obtain_shapely_polygon().exterior.coords.xy
        self.fpx_, self.fpy_ = self.obtain_points(_x, _y)
        no_wps = len(self.fpx_)
        self.fpx_ = list(self.fpx_)
        self.fpy_ = list(self.fpy_)

        self.fpx = [
            self.fpx_[int(i *
                          (no_wps / no_drones)):int(i * (no_wps / no_drones) +
                                                    no_wps / no_drones)]
            for i in range(no_drones)
        ]
        self.fpy = [
            self.fpy_[int(i *
                          (no_wps / no_drones)):int(i * (no_wps / no_drones) +
                                                    no_wps / no_drones)]
            for i in range(no_drones)
        ]
        self.current_goals = [[] for _ in range(no_drones)]
        for i in range(no_drones):
            self.current_goals[i] = np.array(
                [self.fpx[i].pop(0), self.fpy[i].pop(0)])
Esempio n. 4
0
    def __init__(self, agents, map_data, main_sensor='None'):
        self.agents = agents
        self.map_data = map_data
        self.acquisition = 'gaussian_lcb'
        self.gp = gpr.GaussianProcessRegressor(normalize_y=True, kernel=1000 * kernels.RBF(2))

        self.data = [np.array([[], []]), np.array([])]

        # self.vector_pos = np.mgrid[0:self.map_data.shape[1]:1, 0:self.map_data.shape[0]:1].reshape(2, -1).T
        self.vector_pos = np.asarray(np.where(self.map_data == 0)).reshape(2, -1).T

        self.main_sensor = main_sensor
Esempio n. 5
0
    def __init__(self,
                 map_data,
                 sensors: set,
                 k_names=None,
                 acq="gaussian_ei",
                 acq_mod="masked",
                 acq_fusion="decoupled",
                 d=1.0):
        if k_names is None:
            k_names = ["RBF"] * len(sensors)
        self.map_data = map_data
        self.acquisition = acq  # 'gaussian_sei' 'gaussian_ei' 'maxvalue_entropy_search''gaussian_pi'
        self.acq_mod = acq_mod  # 'masked' 'split_path' 'truncated', 'normal'
        self.k_names = k_names  # "RBF" Matern" "RQ"
        self.sensors = sensors
        self.gps = dict()
        self.train_inputs = [np.array([[], []])]
        self.train_targets = dict()
        self.proportion = d

        self.mus = dict()
        self.stds = dict()
        self.has_calculated = dict()

        for sensor, kernel in zip(sensors, k_names):
            if kernel == "RBF":  # "RBF" Matern" "RQ"
                helper = gpr.GaussianProcessRegressor(kernel=kernels.RBF(100),
                                                      alpha=1e-7)
                self.gps[sensor] = convert(helper, 'torch')
                self.gps[sensor].to('cuda')
                self.train_targets[sensor] = np.array([])
                self.mus[sensor] = np.array([])
                self.stds[sensor] = np.array([])
                self.has_calculated[sensor] = False

        self.all_vector_pos = np.mgrid[0:self.map_data.shape[1]:1,
                                       0:self.map_data.shape[0]:1].reshape(
                                           2, -1).T
        self.vector_pos = np.fliplr(
            np.asarray(np.where(self.map_data == 0)).reshape(2, -1).T)

        self.acq_fusion = acq_fusion
        # simple_max: maximum value found
        # max_sum: sum of acq on max for each maximum

        self.splitted_goals = []
        self.nans = None
Esempio n. 6
0
    def __init__(self,
                 map_data,
                 sensors: set,
                 k_names=None,
                 acq="gaussian_ei",
                 acq_mod="masked",
                 acq_fusion="decoupled",
                 d=0.375):
        if k_names is None:
            k_names = ["RBF"] * len(sensors)
        self.map_data = map_data
        self.acquisition = acq  # 'gaussian_sei' 'gaussian_ei' 'maxvalue_entropy_search''gaussian_pi'
        self.acq_mod = acq_mod  # 'masked' 'split_path' 'truncated', 'normal',
        self.k_names = k_names  # "RBF" Matern" "RQ"
        self.sensors = sensors
        self.gps = dict()
        self.train_inputs = [np.array([[], []])]
        self.train_targets = dict()
        self.proportion = d

        self.mus = dict()
        self.stds = dict()
        self.has_calculated = dict()

        for sensor, kernel in zip(sensors, k_names):
            if kernel == "RBF":  # "RBF" Matern" "RQ"
                self.gps[sensor] = gpr.GaussianProcessRegressor(
                    kernel=kernels.RBF(100), alpha=1e-7)
                # self.gps[sensor] = gprnew.GaussianProcessRegressor(kernel=kernels.RBF(100), alpha=1e-7, noise=0.01)
                self.train_targets[sensor] = np.array([])
                self.mus[sensor] = np.array([])
                self.stds[sensor] = np.array([])
                self.has_calculated[sensor] = False

        self.all_vector_pos = np.mgrid[0:self.map_data.shape[1]:1,
                                       0:self.map_data.shape[0]:1].reshape(
                                           2, -1).T
        self.vector_pos = np.fliplr(
            np.asarray(np.where(self.map_data == 0)).reshape(2, -1).T)

        self.problem = MyProblem(gps=self.gps,
                                 train_targets=self.train_targets,
                                 map_data=map_data)
        self.algorithm = NSGA2(pop_size=50)

        self.splitted_goals = []
        self.nans = None
Esempio n. 7
0
    def __init__(self, map_data, sensors: set, k_names=None, d=1.0):
        if k_names is None:
            k_names = ["RBF"] * len(sensors)
        self.map_data = map_data
        self.k_names = k_names  # "RBF" Matern" "RQ"
        self.sensors = sensors
        self.gps = dict()
        self.train_inputs = [np.array([[], []])]
        self.train_targets = dict()
        self.proportion = d

        self.mus = dict()
        self.stds = dict()
        self.has_calculated = dict()

        for sensor, kernel in zip(sensors, k_names):
            if kernel == "RBF":  # "RBF" Matern" "RQ"
                self.gps[sensor] = gprnew.GaussianProcessRegressor(
                    kernel=kernels.RBF(100), alpha=1e-7)
                self.train_targets[sensor] = np.array([])
                self.mus[sensor] = np.array([])
                self.stds[sensor] = np.array([])
                self.has_calculated[sensor] = False

        self.all_vector_pos = np.mgrid[0:self.map_data.shape[1]:1,
                                       0:self.map_data.shape[0]:1].reshape(
                                           2, -1).T
        self.vector_pos = np.fliplr(
            np.asarray(np.where(self.map_data == 0)).reshape(2, -1).T)

        self.splitted_goals = []
        self.nans = None
        self.fpx, self.fpy = self.obtain_points()
        self.fpx = list(self.fpx)
        self.fpy = list(self.fpy)
        self.current_goal = np.array([self.fpx.pop(0), self.fpy.pop(0)])
Esempio n. 8
0
    def __init__(self,
                 scenario_map,
                 initial_position=None,
                 battery_budget=100,
                 resolution=1,
                 seed=0):

        self.id = "Continuous BO Ypacarai"

        # Map of the environment #
        self.scenario_map = scenario_map

        # Environment boundaries
        self.map_size = self.scenario_map.shape
        self.map_lims = np.array(self.map_size) - 1

        # Action space and sizes #
        self.action_space = gym.spaces.Box(low=np.array([0, 0]),
                                           high=np.array([1, 1]))
        self.action_size = 2

        # Internal state of the Markov Decision Process #
        self.state = None
        self.next_state = None
        self.reward = None
        self.done = False

        # Create the ground truth object #
        self.gt = GroundTruth(1 - self.scenario_map, 1, max_number_of_peaks=5)

        # Initial position, referred as a [X,Y] vector #
        self.initial_position = initial_position
        self.step_count = 0

        # Penalization for a collision in the reward funcion #
        self.collision_penalization = 10

        # Seed for deterministic replication #
        self.seed = seed
        np.random.seed(self.seed)

        # Battery budget
        self.battery = battery_budget

        # Battery cost -> Cost of the battery per 1m movement
        # This is calculated approximately using the long size of the map ~ 15km in the Ypacarai case
        self.battery_cost = 100 / np.max(self.map_size) / resolution

        # Gaussian Process parameters
        # GP with RBF kernel of 10% long-size of the map lengthscale (in pixels)
        self.gp = gpr.GaussianProcessRegressor(kernel=kernels.RBF(
            0.1 * np.min(self.map_size)),
                                               alpha=1e-7)

        # Matrix de (num_muestra, features): num_muestra: numero de posiciones en la que se tomaron muestras
        #                                    features: cada una de las dimenciones, i.e., features son y, x
        self.train_inputs = None

        # Solution vector: y = f(x)
        self.train_targets = None

        #  Matrix de (num_pos, features): num_pos: numero de posiciones en la que puede encontrarse el ASV
        #                                 features: cada una de las dimenciones, i.e., features son y, x
        # [[2 17]
        #  [2 18]
        # ...
        #  [y x]
        # ...
        # [54 31]
        # [54 32]]
        self.possible_locations = np.asarray(
            np.where(self.scenario_map == 1)).reshape(2, -1).T
        # Generate vector of possible gt (speeds up the reward MSE process)
        self.target_locations = None

        # Vector!! de dimension 1 fila x (mxn) columnas representando el mapa de incertidumbre anterior
        self.current_std = None
        # Vector!! de dimension 1 fila x (mxn) columnas representando el mapa de media anterior
        self.current_mu = None
        # Current MSE for reward
        self.previous_mse = None
        self._max_step_distance = np.min(self.map_size)

        # Initial position #
        # The initial position HAS PIXEL UNITS:
        #    The action spaces translates to PIXEL UNITS TO FORM THE STATE
        self.position = None
        self.place_agent()
        self.reset()