jes icon indicating copy to clipboard operation
jes copied to clipboard

"Big mutations" can take a really long time in later generations

Open valadaptive opened this issue 1 year ago • 2 comments

I'm not 100% sure if this is the actual root cause, or why exactly this only occurs in very late generations (it starts occurring around generation ~1700).

As evolution goes on for a while, some generations will, with increasing likelihood, take an extremely long time:

image

Whenever I Ctrl+C in the middle of one of these long generations, the traceback lands in getMutatedDNA, in the part that deals with "big mutations":

^CTraceback (most recent call last):
  File "/home/va_erie/Projects/jes/jes.py", line 31, in <module>
    sim.checkALAP()
    ~~~~~~~~~~~~~^^
  File "/home/va_erie/Projects/jes/jes_sim.py", line 165, in checkALAP
    self.doGeneration(self.ui.doGenButton)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/home/va_erie/Projects/jes/jes_sim.py", line 213, in doGeneration
    nextCreatures[loser] = self.mutate(self.creatures[gen][winner],(gen+1)*self.c_count+loser)
                           ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/va_erie/Projects/jes/jes_sim.py", line 242, in mutate
    newDNA, newSpecies, cwc = parent.getMutatedDNA(self)
                              ~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/home/va_erie/Projects/jes/jes_creature.py", line 115, in getMutatedDNA
    while abs(delta) < 0.5 or (i == 2 and result[big_mut_loc+i]+delta < 0.5):
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyboardInterrupt

I hypothesize that the problem is with i == 2 and result[big_mut_loc+i]+delta < 0.5 being False increasingly more often as evolution continues (or at some point, we hit some "unlucky" species for which that happens, and the simulation freezes for too long for us to progress past it). Not sure why this would be the case.

valadaptive avatar Jan 03 '25 11:01 valadaptive

It's almost definitely the rejection sampling--I added some logging if it takes over 1000 tries to generate a valid delta, and on a "long" generation, it logs something like Creature 745086 (Nonero) took 8613282 attempts to generate a big mutation (that one took 8 seconds). Maybe it's possible to use a truncated normal distribution instead?

valadaptive avatar Jan 03 '25 13:01 valadaptive

I see, thanks for pointing it out. I think I know how to fix this!

carykh avatar Jan 03 '25 22:01 carykh