<jupyter_start><jupyter_text>Import Module<jupyter_code>from random import random,randint,choice
import genetic as g<jupyter_output><empty_output><jupyter_text>Build Dataset<jupyter_code>def hiddenfunction(x,y):
    return x**2+2*y + 7

def buildhiddenset(): 
    rows=[]
    for i in range(200):
        x=randint(0,40)
        y=randint(0,40)
        rows.append([x,y,hiddenfunction(x,y)])
    return rows

hiddenset=buildhiddenset()
help(g.evolve)<jupyter_output>Help on function evolve in module genetic:

evolve(pc, popsize, rankfunction, maxgen=500, mutationrate=0.1, breedingrate=0.4, pexp=0.7, pnew=0.05)
    rankfunction
        The function used on the list of programs to rank them from best to worst.
    mutationrate
        The probability of a mutation, passed on to mutate.
    breedingrate
        The probability of crossover, passed on to crossover.
    popsize
        The size of the initial population.
    probexp
        The rate of decline in the probability of selecting lower-ranked programs. A higher value makes the selection process more stringent, choosing only programs with the best ranks to replicate.
    probnew
        The probability when building the new population that a completely new, ran- dom program is introduced. probexp and probnew will be discussed further in the upcoming section “The Importance of Diversity.”<jupyter_text>Evolution<jupyter_code>rank_func=g.getrankfunction(buildhiddenset())
best = g.evolve(2,500,rank_func,mutationrate=0.2,breedingrate=0.2,pexp=0.7,pnew=0.3)
best.display()<jupyter_output>add
  add
   if
    add
    p1
    8
    add
     if
     1
      subtract
      7
       subtract
       7
        add
        p1
         subtract
         3
         4
     p0
    8
    add
     if
      if
       isgreater
       2
        subtract
         add
         5
         1
        p0
       isgreater
       6
        multiply
        p1
         subtract
         4
          isgreater
          p0
           add
           p0
           0
      0
     9
     p0
    2
  p1
  multiply
   if
   1
   p0
   p0
  p0
{'fraction_non_alphanumeric': 0.061332055582175374, 'fraction_numerical': 0.03114518447532343, 'mean_word_length': 2.158850226928896, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '668065', 'license': 'MIT', 'n_tokens_mistral': 694, 'n_tokens_neox': 666, 'n_words': 200, 'path': 'models/genetic_programming/example.ipynb', 'repo_name': 'shawlu95/Data_Science_Toolbox', 'size': '2087'}