CodeReclaimers / neat-python

Python implementation of the NEAT neuroevolution algorithm
BSD 3-Clause "New" or "Revised" License
1.42k stars 493 forks source link

Question? winner genome - statistics #136

Closed richban closed 5 years ago

richban commented 6 years ago

I am trying to evolve a robot navigation controller. I've started from the xor2.py example and proceeded to my own implementation according the example.

As the docs describes once the populations object run returns, I can query some statistics about the population and get the best genome.

    # N_GENERATIONS.
    winner = p.run(eval_genomes, N_GENERATIONS)

    # Display the winning genome.
    print('\nBest genome:\n{!s}'.format(winner))

I get this nice output:

Best genome:
Key: 322
Fitness: 3.21099591255188
Nodes:

        0 DefaultNodeGene(key=0, bias=0.3905814413093136, response=1.0, activation=sigmoid, aggregation=sum)
        1 DefaultNodeGene(key=1, bias=-1.1939329206813274, response=1.0, activation=sigmoid, aggregation=sum)

Connections:                                                                                                                                                    
        DefaultConnectionGene(key=(-16, 1), weight=-0.10227128664719665, enabled=True)                                                                          
        DefaultConnectionGene(key=(-15, 1), weight=-0.15253099091854805, enabled=True)                                                                          
        DefaultConnectionGene(key=(-14, 0), weight=-3.7932962968056247, enabled=False)                                                                          
        DefaultConnectionGene(key=(-14, 1), weight=3.135898639598952, enabled=True)                                                                             
        DefaultConnectionGene(key=(-13, 0), weight=1.283452355565779, enabled=True)                                                                             
        DefaultConnectionGene(key=(-12, 0), weight=3.0548574907775947, enabled=True)                                                                            
        DefaultConnectionGene(key=(-12, 1), weight=0.5923903178560455, enabled=True)                                                                            
        DefaultConnectionGene(key=(-11, 0), weight=3.1386417179843193, enabled=True)                                                                            
        DefaultConnectionGene(key=(-11, 1), weight=1.6228324282598583, enabled=False)                                                                           
        DefaultConnectionGene(key=(-10, 0), weight=1.2140635957324064, enabled=True)                                                                            
        DefaultConnectionGene(key=(-10, 1), weight=-1.618456679779314, enabled=True)                                                                            
        DefaultConnectionGene(key=(-9, 0), weight=0.2448517114583711, enabled=False)                                                                            
        DefaultConnectionGene(key=(-9, 1), weight=-0.5698322068031862, enabled=True)                                                                            
        DefaultConnectionGene(key=(-8, 0), weight=-1.6740095432907984, enabled=False)                                                                           
        DefaultConnectionGene(key=(-8, 1), weight=0.1057016688230496, enabled=True)                                                                             
        DefaultConnectionGene(key=(-7, 0), weight=-1.2298703938979563, enabled=True)                                                                            
        DefaultConnectionGene(key=(-7, 1), weight=-1.4761568767819315, enabled=True)                                                                            
        DefaultConnectionGene(key=(-6, 1), weight=1.8654311755568236, enabled=True)                                                                             
        DefaultConnectionGene(key=(-5, 0), weight=-3.5820146385425593, enabled=False)                                                                           
        DefaultConnectionGene(key=(-5, 1), weight=1.6657468990576016, enabled=True)                                                                             
        DefaultConnectionGene(key=(-4, 1), weight=-0.17637441757907302, enabled=False)                                                                          
        DefaultConnectionGene(key=(-3, 1), weight=-0.3683064724282509, enabled=True)                                                                            
        DefaultConnectionGene(key=(-2, 1), weight=1.7994375602312356, enabled=True)                                                                                  DefaultConnectionGene(key=(-1, 0), weight=-1.4365569719721825, enabled=True)

However, I am kinda confused regarding the number of Nodes and Connections and the way they are connected. Since I have defined the network:

# network parameters
num_hidden              = 1
num_inputs              = 16
num_outputs             = 2

Therefore I am expecting to have at least 16 nodes. Which represents 16 sensors and 2 outputs - wheel speeds.

Could anyone explain why there are only 2 Nodes in the Genome and the strange Phenotype

Entire configuration

[NEAT]
fitness_criterion     = max
fitness_threshold     = 1.0
no_fitness_termination = True
pop_size              = 10
reset_on_extinction   = False

[DefaultGenome]
# node activation options
activation_default      = sigmoid
activation_mutate_rate  = 0.0
activation_options      = sigmoid

# node aggregation options
aggregation_default     = sum
aggregation_mutate_rate = 0.0
aggregation_options     = sum

# node bias options
bias_init_mean          = 0.0
bias_init_stdev         = 1.0
bias_max_value          = 30.0
bias_min_value          = -30.0
bias_mutate_power       = 0.5
bias_mutate_rate        = 0.7
bias_replace_rate       = 0.1

# genome compatibility options
compatibility_disjoint_coefficient = 1.0
compatibility_weight_coefficient   = 0.5

# connection add/remove rates
conn_add_prob           = 0.5
conn_delete_prob        = 0.5

# connection enable options
enabled_default         = True
enabled_mutate_rate     = 0.01

feed_forward            = True
initial_connection      = full_direct

# node add/remove rates
node_add_prob           = 0.2
node_delete_prob        = 0.2

# network parameters
num_hidden              = 1
num_inputs              = 16
num_outputs             = 2

# node response options
response_init_mean      = 1.0
response_init_stdev     = 0.0
response_max_value      = 30.0
response_min_value      = -30.0
response_mutate_power   = 0.0
response_mutate_rate    = 0.0
response_replace_rate   = 0.0

# connection weight options
weight_init_mean        = 0.0
weight_init_stdev       = 1.0
weight_max_value        = 30
weight_min_value        = -30
weight_mutate_power     = 0.5
weight_mutate_rate      = 0.8
weight_replace_rate     = 0.1

[DefaultSpeciesSet]
compatibility_threshold = 3.0

[DefaultStagnation]
species_fitness_func = max
max_stagnation       = 20

[DefaultReproduction]
elitism            = 2
survival_threshold = 0.2
evolvingfridge commented 6 years ago

Probably deleted.