<jupyter_start><jupyter_text>Species  Code<jupyter_code>from importer import *
from helpers import Distributions

class Species:
    Organism = loader.load_module("Organism").Organism
    unique_id = 0
    
    def __init__(self, input_dim, output_dim, generation):
        self.id = Species.unique_id
        Species.unique_id+=1
        self.organisms={}
        self.origin = generation
        self.cached_organism = None #to be used for speciation after clear
    
    def add_organism(self, organism):
        assert organism.id not in self.organisms, 'Organism {} already in dictionary'.format(organism.id)
        self.organisms[organism.id] = organism
        organism.species_hint = self.id
        
        
    def get_random_member(self):
        return Distributions.choice(self.organisms)
    
    @property
    def size(self):
        return len(self.organisms)
    
    @staticmethod
    def generate_initial_species(size, input_dim, output_dim, generation):
        first_species = Species(input_dim, output_dim, generation)
        for i in range(size):
            org = Species.Organism.genesis(species_hint=first_species.id, input_dim=input_dim, output_dim=output_dim, generation=generation)
            first_species.add_organism(org)
        return first_species
    
    def clear(self):
        self.cached_organism = self.get_random_member()
        self.organisms = {}
        
    def __repr__(self):
        return '<Species-id:{},origin:{},size:{}>'.format(self.id, self.origin, self.size)<jupyter_output><empty_output><jupyter_text>Testing<jupyter_code>a = Species.generate_initial_species(100, 1, 2, 1)
a<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09778044391121776, 'fraction_numerical': 0.004799040191961607, 'mean_word_length': 3.233502538071066, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '254212', 'license': 'MIT', 'n_tokens_mistral': 538, 'n_tokens_neox': 506, 'n_words': 97, 'path': 'notebooks/Species.ipynb', 'repo_name': 'kdonbekci/neuroevolution', 'size': '1667'}