class DinoNeurons: def __init__(self, input_list): """ :param input_list: """ self.input_list = input_list self.neuron_jump = Neuron(input_liste=input_list, max_value=1.0, activation_function=sigmoid) self.neuron_no_jump = Neuron(input_liste=input_list, max_value=1.0, activation_function=sigmoid) def need_to_jump(self): return self.neuron_jump.compute() > self.neuron_no_jump.compute() def reset(self): self.neuron_jump = Neuron(input_liste=self.input_list, max_value=1.0, activation_function=sigmoid) self.neuron_no_jump = Neuron(input_liste=self.input_list, max_value=1.0, activation_function=sigmoid)
def __init__(self, input_list, gen: genome): """ :param input_list: """ super().__init__(gen) self.input_list = input_list self.neuron_jump = Neuron(input_liste=input_list, max_value=5.0, activation_function=sigmoid) self.neuron_no_jump = Neuron(input_liste=input_list, max_value=5.0, activation_function=sigmoid) # Load the gnome index_gen = 0 # jump neuron - 1 to remove the bias node for index_weight in range(self.neuron_jump.get_weight_len() - 1): self.neuron_jump.weight_liste[index_weight] = gen[index_gen] index_gen += 1 # bias node for jump neuron self.neuron_jump.set_threshold(gen[index_gen]) index_gen += 1 # no jump neuron - 1 to remove the bias node for index_weight in range(self.neuron_no_jump.get_weight_len() - 1): self.neuron_no_jump.weight_liste[index_weight] = gen[index_gen] index_gen += 1 # bias node for jump neuron self.neuron_no_jump.set_threshold(gen[index_gen]) self.dino_score = None
def reset(self): self.neuron_jump = Neuron(input_liste=self.input_list, max_value=1.0, activation_function=sigmoid) self.neuron_no_jump = Neuron(input_liste=self.input_list, max_value=1.0, activation_function=sigmoid)
def __init__(self, input_list): """ :param input_list: """ self.input_list = input_list self.neuron_jump = Neuron(input_liste=input_list, max_value=1.0, activation_function=sigmoid) self.neuron_no_jump = Neuron(input_liste=input_list, max_value=1.0, activation_function=sigmoid)
class DinoNeurons(Individual): def __init__(self, input_list, gen: genome): """ :param input_list: """ super().__init__(gen) self.input_list = input_list self.neuron_jump = Neuron(input_liste=input_list, max_value=5.0, activation_function=sigmoid) self.neuron_no_jump = Neuron(input_liste=input_list, max_value=5.0, activation_function=sigmoid) # Load the gnome index_gen = 0 # jump neuron - 1 to remove the bias node for index_weight in range(self.neuron_jump.get_weight_len() - 1): self.neuron_jump.weight_liste[index_weight] = gen[index_gen] index_gen += 1 # bias node for jump neuron self.neuron_jump.set_threshold(gen[index_gen]) index_gen += 1 # no jump neuron - 1 to remove the bias node for index_weight in range(self.neuron_no_jump.get_weight_len() - 1): self.neuron_no_jump.weight_liste[index_weight] = gen[index_gen] index_gen += 1 # bias node for jump neuron self.neuron_no_jump.set_threshold(gen[index_gen]) self.dino_score = None def set_score(self, score): self.dino_score = score def need_to_jump(self): return self.neuron_jump.compute() > self.neuron_no_jump.compute() def get_score(self): if self.dino_score is None: raise ValueError("The score is not set") return self.dino_score def to_dict(self): return {'score': self.get_score(), 'genome': self.genome}
PYTHON_LOGGER.setLevel(logging.DEBUG) # Absolute path to the folder location of this python file FOLDER_ABSOLUTE_PATH = os.path.normpath( os.path.dirname(os.path.abspath(__file__))) if __name__ == "__main__": from neural import sigmoid from dino_game import GameController, width game_speed = Input(value=0) distance_next_obstacle = Input(value=0) gap_between_obstacles = Input(value=0) input_list = [game_speed, distance_next_obstacle, gap_between_obstacles] neuron_jump = Neuron(input_liste=input_list, max_value=1.0, activation_function=sigmoid) neuron_no_jump = Neuron(input_liste=input_list, max_value=1.0, activation_function=sigmoid) controller = GameController(numbers_of_dino=1) while True: if controller.game_is_over(): neuron_jump = Neuron(input_liste=input_list, max_value=1.0, activation_function=sigmoid) neuron_no_jump = Neuron(input_liste=input_list, max_value=1.0, activation_function=sigmoid) controller.restart_game()