def add_successful_genome_for_test(self, current_gen, use_this_genome): """ This function adds a pre programmed genome which is known to converge for the XOR dataset. :param current_gen: :param use_this_genome: Whether this genome should be added to the population or not :return: """ # Wait for current_gen > 1 because if using backprop the first gen skips using backprop. if current_gen > 1 and use_this_genome: node_list = [ NodeGene(node_id=0, node_type='source'), NodeGene(node_id=1, node_type='source'), NodeGene(node_id=2, node_type='output', bias=0.5), NodeGene(node_id=3, node_type='hidden', bias=1), NodeGene(node_id=4, node_type='hidden', bias=1), NodeGene(node_id=5, node_type='hidden', bias=1), NodeGene(node_id=6, node_type='hidden', bias=1), ] connection_list = [ConnectionGene(input_node=0, output_node=3, innovation_number=1, enabled=True, weight=np.random.randn()), ConnectionGene(input_node=1, output_node=3, innovation_number=2, enabled=True, weight=np.random.randn()), ConnectionGene(input_node=0, output_node=4, innovation_number=3, enabled=True, weight=np.random.randn()), ConnectionGene(input_node=1, output_node=4, innovation_number=4, enabled=True, weight=np.random.randn()), ConnectionGene(input_node=3, output_node=5, innovation_number=5, enabled=True, weight=np.random.randn()), ConnectionGene(input_node=4, output_node=5, innovation_number=6, enabled=True, weight=np.random.randn()), ConnectionGene(input_node=3, output_node=6, innovation_number=7, enabled=True, weight=np.random.randn()), ConnectionGene(input_node=4, output_node=6, innovation_number=8, enabled=True, weight=np.random.randn()), ConnectionGene(input_node=5, output_node=2, innovation_number=9, enabled=True, weight=np.random.rand()), ConnectionGene(input_node=6, output_node=2, innovation_number=10, enabled=True, weight=np.random.randn()) ] test_genome = Genome(connections=connection_list, nodes=node_list, key=1) test_genome.fitness = -99999999999 self.population[32131231] = test_genome
def pole_evaluate(genome: Genome): numnodes: int = len(genome.nodes) # how many visits is allowed in every activation thresh: int = numnodes * 2 # TODO organism and trait # cross MAX_STEPS means it's the winner MAX_STEPS = 100000 # balance the pole genome.fitness = go_crat(genome, MAX_STEPS, thresh) # print("genome fitness {}".format(genome.fitness)) if genome.fitness > MAX_STEPS: genome.winner = True return True else: genome.winner = False return False