Ejemplo n.º 1
0
    def __init__(self,
                 pretrained_model=None,
                 learning_rate=0.0001,
                 std=1,
                 screen_size=None,
                 display=True):
        """
		Init the agent with the necessary values
		"""
        self.name = 'policy gradient agent gaussian linear'
        if screen_size is None:
            self.screen_size = [400, 400]
        else:
            self.screen_size = screen_size
        self.env = catcher.ContinuousCatcher(width=self.screen_size[0],
                                             height=self.screen_size[1])
        if pretrained_model:
            # linear model
            self.theta = pretrained_model
        else:
            # linear model
            w_bar_center, w_bar_vel, w_fruit_center0, w_fruit_center1 = 0, 0, 0, 0
            self.theta = [
                w_bar_center, w_bar_vel, w_fruit_center0, w_fruit_center1
            ]
        # learning rate for the update
        self.learning_rate = learning_rate
        # standard deviation of the Gaussian.
        self.std = std
        self.display = display
        if display:
            self.Display = Display.Display()
Ejemplo n.º 2
0
    def __init__(self, screen_size=None, color_style=None):
        if screen_size is None:
            screen_size = [400, 400]
        if color_style is None:
            self.color_style = DefaultColorStyle()

        self.running = True
        self.screen_size = screen_size
        pygame.display.init()
        pygame.font.init()
        self.surface = pygame.display.set_mode(self.screen_size)
        pygame.display.set_caption("Catcher")

        self.game = catcher.ContinuousCatcher(width=self.screen_size[0],
                                              height=self.screen_size[1])
        self.bar_size = self.game.bar.size
        self.fruit_size = self.game.fruit.size
Ejemplo n.º 3
0
    def __init__(self,
                 show_display=True,
                 screen_size=None,
                 agent=None,
                 color_style=None):
        """
        Create the emulator with all the necessary variables

        :param show_display: Whether to show a display or not
        :param screen_size: The size of the screen
        :param agent: The agent to use (None for user controlled)
        :param color_style: The color style to use
        """
        if screen_size is None:
            screen_size = [400, 400]
        if color_style is None:
            self.color_style = DefaultColorStyle()

        self.running = True
        self.user_right = 0
        self.user_left = 0

        self.display = show_display
        self.screen_size = screen_size
        if show_display is True:
            pygame.display.init()
            pygame.font.init()
            self.surface = pygame.display.set_mode(self.screen_size)
            pygame.display.set_caption("Catcher")

        self.game = catcher.ContinuousCatcher(width=self.screen_size[0],
                                              height=self.screen_size[1])
        self.bar_size = self.game.bar.size
        self.fruit_size = self.game.fruit.size

        self.agent = agent
Ejemplo n.º 4
0
    def __init__(self, options, agent=None):
        """
        Create the emulator with all the necessary variables

        :param options: The options used to set up the emulator
        :param agent: The agent to use (None for user controlled)
        """
        option_tmp = options.get_option("screen_size")

        if option_tmp is None:
            self.screen_size = [400, 400]

        option_tmp = options.get_option("color_style")
        self.color_style = DefaultColorStyle(
        ) if option_tmp is None else option_tmp

        option_tmp = options.get_option("max_generations")
        self.max_generations = 1000 if option_tmp is None else option_tmp
        option_tmp = options.get_option("display_generations_gap")
        self.display_generations_gap = 250 if option_tmp is None else option_tmp
        option_tmp = options.get_option("infinite_generations")
        self.infinite_generations = False if option_tmp is None else option_tmp

        option_tmp = options.get_option("fps")
        self.fps = 30 if option_tmp is None else option_tmp

        option_tmp = options.get_option("max_frames")
        self.max_frames = 0 if option_tmp is None else option_tmp

        self.running = True
        self.current_gen = 0
        self.user_right = 0
        self.user_left = 0

        option_tmp = options.get_option("show_display")
        self.display = True if option_tmp is None else option_tmp

        if self.display is True:
            pygame.display.init()
            pygame.font.init()
            self.surface = pygame.display.set_mode(self.screen_size)
            pygame.display.set_caption("Catcher")

        option_tmp = options.get_option("compute_plot")
        self.compute_plot = False if option_tmp is None else option_tmp

        self.game = catcher.ContinuousCatcher(width=self.screen_size[0],
                                              height=self.screen_size[1])
        self.bar_size = self.game.bar.size
        self.fruit_size = self.game.fruit.size

        option_tmp = options.get_option("discrete")
        self.discrete = True if option_tmp is None else option_tmp

        if self.discrete:
            self.actions = [
                -self.screen_size[0] + i * self.fruit_size[0]
                for i in range(0, 1 +
                               (self.screen_size[0] // self.fruit_size[0]))
            ]
            self.actions.extend([
                self.screen_size[0] - i * self.fruit_size[0]
                for i in range(0, 1 +
                               (self.screen_size[0] // self.fruit_size[0]))
            ])
            self.actions.append(0.0)

            self.actions.sort()
        else:
            self.discrete = False
            self.actions = [-self.screen_size[0], self.screen_size[0]]

        self.agent = agent
        if self.agent is not None:
            self.agent.init(self.actions,
                            [self.screen_size, self.fruit_size, self.bar_size])
            option_tmp = options.get_option("online_feed")
            self.online_feed = True if option_tmp is None else option_tmp
        else:
            self.online_feed = False

        self.trainer_agent = options.get_option("trainer_agent")
        if self.trainer_agent is not None:
            self.trainer_agent.init(
                self.actions,
                [self.screen_size, self.fruit_size, self.bar_size])