CodeReclaimers / neat-python

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

Assert error in get_new_node_key during reproduction #172

Open realimposter opened 5 years ago

realimposter commented 5 years ago

I'm using neat-python inside of the program Houdini. I am trying to train biped movements. The program runs great until at a random generation usually between 4 and 100 where the the organisms stop reproducing. I tracked the problem down to the species members list suddenly being empty, because the reproduce function stops at the assert line in this code in genome.py:

` def get_new_node_key(self, node_dict):

    if self.node_indexer is None:

        self.node_indexer = count(max(list(iterkeys(node_dict))) + 1)

    new_id = next(self.node_indexer)

    assert new_id not in node_dict

    return new_id`

Anyone know whats causing this?

unsightedmetal6 commented 1 year ago

Did you ever find a solution to this? I am getting the same AssertionError.

unsightedmetal6 commented 1 year ago

I found a solution! Replace the definition of the function get_new_node_key() in genome.py with this:

def get_new_node_key(self, node_dict):

        if self.node_indexer is None:
            self.node_indexer = count(max(list(iterkeys(node_dict))) + 1)

        new_id = next(self.node_indexer)

        if new_id in node_dict:
            new_id = next(self.node_indexer)

        return new_id

I still have an unrelated issue where NEAT stops learning though.

TERESH1 commented 1 year ago

I found a solution! Replace the definition of the function get_new_node_key() in genome.py with this:

def get_new_node_key(self, node_dict):

        if self.node_indexer is None:
            self.node_indexer = count(max(list(iterkeys(node_dict))) + 1)

        new_id = next(self.node_indexer)

        if new_id in node_dict:
            new_id = next(self.node_indexer)

        return new_id

I still have an unrelated issue where NEAT stops learning though.

It looks better if you replace "if new_id in node_dict" with while