예제 #1
0
    def __init__(self):
        # current state data
        self.state = {}
        self.reset_state()
        # training data
        self.training_data = set()

        launch(self, 0)
예제 #2
0
    def has_crashed(self):
        # the rocket has crashed and we are now moving onto another iteration
        # this is where we will fit the model to the training data

        global num_of_games
        global training_states
        global training_outputs
        global model
        global all_max_ys
        global all_max_xs

        # printing overall data for me
        print('rocket #', str(num_of_games + 1), 'crashed')
        print('max y:', self.state['max_y'])
        print('max_x:', self.state['max_x'])
        print('max velocity:', self.state['max_velocity'])
        print('max acceleration:', self.state['max_acceleration'])
        print('time:', self.state['time'])

        all_max_ys.append(self.state['max_y'])
        all_max_xs.append(self.state['max_x'])
        for state in self.states:
            if len(training_states) == 0:
                training_states = np.array([state])
                # if the array is empty we cannot v-stack, so we add the fist state
            else:
                training_states = np.vstack((training_states, state))
                # we have to use v-stack like before to keep the 2d array of states
        for output in self.outputs:
            if len(training_outputs) == 0:
                training_outputs = np.array([output])
            else:
                training_outputs = np.vstack((training_outputs, output))

        if num_of_games is not 0 and num_of_games % training_frequency is 0 and len(
                training_states) is not 0:
            # we only train every few games, and not every rocket is added to training data,
            # so we first check if we should train after the current game, and we check if there is data to train with
            train(training_states, training_outputs)
            # resetting the training arrays to not over train
            training_states = np.array([])
            training_outputs = np.array([])

        # preparing for next launch
        self.reset_state()

        # resetting rocket training data
        self.states = np.array([])
        self.outputs = np.array([])

        num_of_games += 1
        if num_of_games >= max_games:
            return
        print('finished game #', num_of_games)

        # continuing to play
        launch(self, num_of_games)
예제 #3
0
    def __init__(self):
        # current state data
        self.state = {}
        self.reset_state()

        # training data
        self.states = np.array([])
        self.outputs = np.array([])

        launch(self, 0)
예제 #4
0
파일: rocket.py 프로젝트: BBrixen/Rocket_AI
    def __init__(self):
        # current state data
        self.velocity = 0
        self.height = 0
        self.has_left_ground = False
        self.fuel = max_fuel  # setting this to a lower value for my testing cases
        self.acceleration = 0

        # overall data
        self.time = 0  # not measured in seconds, measured in frames
        self.max_height = 0
        self.max_velocity = 0

        # training data
        self.states = np.array([])
        self.outputs = np.array([])

        launch(self, 0)
예제 #5
0
    def has_crashed(self):
        # the rocket has crashed and we are now moving onto another iteration
        # this is where we will fit the model to the training data

        global num_of_games
        global overall_training_data
        global model
        global all_max_ys, all_max_xs, all_max_zs

        # printing overall data for me
        print('rocket #', str(num_of_games + 1), 'crashed')
        print('max y:', self.state['max_y'])
        print('max_x:', self.state['max_x'])
        print('max_z:', self.state['max_z'])
        print('max velocity:', self.state['max_velocity'])
        print('max acceleration:', self.state['max_acceleration'])
        print('time:', self.state['time'])

        all_max_ys.append(self.state['max_y'])
        all_max_xs.append(self.state['max_x'])
        all_max_zs.append(self.state['max_z'])

        # adding all values from current training data into overall training data
        overall_training_data = overall_training_data.union(self.training_data)

        if num_of_games is not 0 and num_of_games % TRAINING_FREQUENCY is 0 and len(
                overall_training_data) is not 0:
            # we only train every few games, and not every rocket is added to training data,
            train(overall_training_data)
            # resetting the training arrays to not over train
            overall_training_data = set()

        # preparing for next launch
        self.reset_state()
        self.training_data = set()

        num_of_games += 1
        if num_of_games >= MAX_GAMES:
            return
        print('finished game #', num_of_games)

        # continuing to play
        launch(self, num_of_games)
예제 #6
0
파일: rocket.py 프로젝트: BBrixen/Rocket_AI
    def has_crashed(self):
        # the rocket has crashed and we are now moving onto another iteration
        # this is where we will fit the model to the training data

        global num_of_games
        global previous_height
        global training_states
        global training_outputs
        global model
        global all_max_heights

        # printing overall data for me
        print('rocket #', str(num_of_games+1), 'crashed')
        print('max height:', self.max_height)
        print('max velocity:', self.max_velocity)
        print('time:', self.time)

        all_max_heights.append(self.max_height)
        for state in self.states:
            if len(training_states) == 0:
                training_states = state
                # if the array is empty we cannot v-stack, so we add the fist state
            else:
                training_states = np.vstack((training_states, state))
                # we have to use v-stack like before to keep the 2d array of states
        for output in self.outputs:
            training_outputs = np.append(training_outputs, output)

        if num_of_games is not 0 and num_of_games % training_frequency is 0 and len(training_states) is not 0:
            # we only train every few games, and not every rocket is added to training data,
            # so we first check if we should train after the current game,
            # and we check if there is data to train with
            train(training_states, training_outputs)
            # resetting the training arrays to not over train
            training_states = np.array([])
            training_outputs = np.array([])

        # changing the average_height for determining if future rockets are viable for training
        # previous_height = self.max_height

        # preparing for next launch
        # resetting all values
        self.velocity = 0
        self.height = 0
        self.has_left_ground = False
        self.fuel = max_fuel
        self.acceleration = 0

        # resetting rocket overall data
        self.time = 0
        self.max_height = 0
        self.max_velocity = 0

        # resetting rocket training data
        self.states = np.array([])
        self.outputs = np.array([])

        num_of_games += 1
        if num_of_games >= max_games:
            return
        print('finished game #', num_of_games)

        # continuing to play
        launch(self, num_of_games)