<jupyter_start><jupyter_text><jupyter_code>#@title INSTALLS
!pip install livelossplot --quiet
import random
import time
import matplotlib.pyplot as plt
from livelossplot import PlotLosses
RPRD_BOUNDS = 25
DEATH_BOUNDS = 25

def create_cell():
  return dict(
      health = random.randint(1, 100),
      strength = random.randint(1, 100)
    )                     

def birth(offspring):
  return [create_cell() for i in range(offspring)]

def evaluate(cells):
  for cell in cells:
    cell["health"] *= cell["strength"]/100 
  return cells
  
def reproduce(cells):
  return [create_cell() for cell in cells if cell["health"] > RPRD_BOUNDS]  

def death(cells):  
  return [cell for cell in cells if cell["health"] > DEATH_BOUNDS ]

def run_generation(cells):
  cells = evaluate(cells)
  cells.extend(reproduce(cells))
  return death(cells)
#@title Default title text
generations = 25 #@param {type:"slider", min:1, max:25, step:1}
initial_offspring = 10 #@param {type:"slider", min:10, max:1000, step:1}
reproduction_bounds = 50#@param {type:"slider", min:1, max:100, step:1}
death_bounds = 25 #@param {type:"slider", min:1, max:100, step:1}

RPRD_RATE = reproduction_bounds
DEATH_RATE = death_bounds
cells = birth(initial_offspring)

groups = {'Population': ['population'], 'Attributes' : ['avg_strength','avg_health']}
liveloss = PlotLosses(groups=groups)

history = {}
for i in range(generations):  
  cells = run_generation(cells)  
  history["population"] = len(cells)
  history["avg_strength"] = sum([cell["strength"] for cell in cells])/(len(cells)+1) 
  history["avg_health"] = sum([cell["health"] for cell in cells])/(len(cells)+1) 
  liveloss.update(history)
  liveloss.send()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14044289044289043, 'fraction_numerical': 0.026806526806526808, 'mean_word_length': 5.221014492753623, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '484436', 'license': 'Apache-2.0', 'n_tokens_mistral': 643, 'n_tokens_neox': 583, 'n_words': 146, 'path': 'EDL_2_3_Simulating_Life.ipynb', 'repo_name': 'cxbxmxcx/EvolutionaryDeepLearning', 'size': '1716'}