Example #1
0
    def __init__(self, creator: TensorCreator, params: GridWorldParams):
        super().__init__(creator.device)

        self.validate_params(params)

        self.params = params

        # render a world map
        tile_size = self.params.tile_size
        width = self.params.world_width * self.params.tile_size
        height = self.params.world_height * self.params.tile_size
        self.bit_map = creator.zeros([height, width], dtype=torch.uint8)

        if isinstance(creator, MeasuringCreator):
            self.last_image = creator.zeros([height, width], dtype=self._float_dtype, device=self._device)
            self.circle = creator.zeros([tile_size, tile_size], dtype=self._float_dtype, device=self._device)
            self.circle_wall = creator.zeros([tile_size, tile_size, 3], dtype=self._float_dtype, device=self._device)
            self.triangle_wall = creator.zeros([tile_size, tile_size, 3], dtype=self._float_dtype, device=self._device)
        else:

            self.circle = interpolate(creator.tensor(self.circle_template).view(1, 1, 9, 9),
                                      size=[tile_size, tile_size]).view(tile_size, tile_size).type(torch.uint8)
            self.triangle_wall = interpolate(creator.tensor(self.triangle_wall_template).view(1, 1, 9, 9),
                                      size=[tile_size, tile_size]).view(tile_size, tile_size).type(torch.uint8)
            self.circle_wall = interpolate(creator.tensor(self.circle_wall_template).view(1, 1, 9, 9),
                                      size=[tile_size, tile_size]).view(tile_size, tile_size).type(torch.uint8)

        self.bit_map_last_action = creator.zeros([height + 1, width], dtype=self._float_dtype, device=self._device)
        self.bit_map_padding = width - 4

        self.render_map(self.bit_map)

        self.pos = creator.tensor(self.params.agent_pos[::-1], dtype=self._float_dtype, device=self._device)
        self.last_position = creator.zeros(2, dtype=self._float_dtype, device=self._device)
        self.last_position_one_hot_matrix = creator.zeros((params.world_height, params.world_width),
                                                          dtype=self._float_dtype, device=self._device)
        self.last_action = creator.zeros(4, dtype=self._float_dtype, device=self._device)
        self.reward = creator.zeros(1, dtype=self._float_dtype, device=self._device)
        width = self.params.egocentric_width * self.params.tile_size
        height = self.params.egocentric_height * self.params.tile_size

        self.egocentric_image = creator.zeros((width, height), dtype=self._float_dtype, device=self._device)
        self.ego_last_action = creator.zeros((width+1, height), dtype=self._float_dtype, device=self._device)
        self.ego_padding = height - 4

        if not isinstance(creator, MeasuringCreator):
            # Initial rendering of the outputs, all further renderings will be just updates
            self.last_image = creator.tensor(self.bit_map, dtype=self._float_dtype, device=self._device)
            self.last_position.copy_(self.pos)
            self._render_outputs()
Example #2
0
    def __init__(self,
                 creator: TensorCreator,
                 output_height: int,
                 output_width: int,
                 params: WeightedAvgNodeParams,
                 num_weights: int = 0):

        super().__init__(creator.device)

        self._params = params
        self._creator = creator

        if self._params.weights_on_input:
            self.num_weights = num_weights

            weights = np.ones((output_height, output_width, self.num_weights))
        else:
            assert len(
                self._params.weights) != 0, 'Parametric weights not set!'
            assert self._params.num_inputs == len(self._params.weights)
            self.num_weights = len(self._params.weights)

            weights = np.ones((output_height, output_width, self.num_weights))
            for i in range(self.num_weights):
                weights[i] = np.dot(weights[i], params.weights[i])

        self.node_weights = creator.tensor(weights,
                                           dtype=creator.float,
                                           device=creator.device)
        self.last_output = creator.zeros([output_width, output_height],
                                         dtype=creator.float,
                                         device=creator.device)
Example #3
0
    def __init__(self, creator: TensorCreator, noise_amplitude=0.2):
        super().__init__(creator.device)
        self._noise_amplitude = noise_amplitude

        self.bitmap = creator.zeros([1, 2],
                                    dtype=self._float_dtype,
                                    device=self._device)

        self._current_step = 0

        self._data = creator.tensor([[0., 0], [1., 0], [0., 1], [1, 1]],
                                    dtype=self._float_dtype,
                                    device=self._device)
        self._no_data = self._data.shape[1]
Example #4
0
def _tensor_from_data(creator: TensorCreator):
    return creator.tensor([1, 2, 3], dtype=creator.float64, device='cpu')