<jupyter_start><jupyter_text>Python Neural Genetic Algorithm Hybrids Tutorial: http://pyneurgen.sourceforge.net/tutorial_ge.htmlNeed to use python2  Grammatical Evolution Tutorial:This tutorial presents a short, easy problem to solve using Grammatical Evolution techniques with this software. The example uses only the grammatical evolution portion rather than a hybrid for clarity. InstallationThe quickest way to install is with easy_install. Since this is a Python library, at the Python prompt put:```basheasy_install pyneurgen```or:<jupyter_code>!python2 -m pip install pyneurgen --user
from pyneurgen.grammatical_evolution import GrammaticalEvolution
from pyneurgen.fitness import FitnessElites, FitnessTournament
from pyneurgen.fitness import ReplacementTournament, MAX, MIN, CENTER
bnf =   """
<expr>              ::= <expr> <biop> <expr> | <uop> <expr> | <real> |
                        math.log(abs(<expr>)) | <pow> | math.sin(<expr>)|
                        value | (<expr>)
<biop>              ::= + | - | * | /
<uop>               ::= + | -
<pow>               ::= pow(<expr>, <real>)
<plus>              ::= +
<minus>             ::= -
<real>              ::= <int-const>.<int-const>
<int-const>         ::= <int-const> | 1 | 2 | 3 | 4 | 5 | 6 |
                        7 | 8 | 9 | 0
<S>                 ::=
import math
total = 0.0
for i in xrange(100):
    value = float(i) / float(100)
    total += abs(<expr> - pow(value, 3))
fitness = total
self.set_bnf_variable('<fitness>', fitness)
        """
ges = GrammaticalEvolution()

ges.set_bnf(bnf)
ges.set_genotype_length(start_gene_length=20,
                        max_gene_length=50)
ges.set_population_size(50)
ges.set_wrap(True)

ges.set_max_generations(1000)
ges.set_fitness_type(MIN, .01)

ges.set_max_program_length(500)
ges.set_timeouts(10, 120)
ges.set_fitness_fail(100.0)

ges.set_fitness_selections(
    FitnessElites(ges.fitness_list, .05),
    FitnessTournament(ges.fitness_list, tournament_size=2))
ges.set_max_fitness_rate(.5)

ges.set_mutation_rate(.025)
ges.set_fitness_selections(
    FitnessElites(ges.fitness_list, .05),
    FitnessTournament(ges.fitness_list, tournament_size=2))
ges.set_max_fitness_rate(.5)

ges.set_crossover_rate(.2)
ges.set_children_per_crossover(2)
ges.set_mutation_type('m')
ges.set_max_fitness_rate(.25)

ges.set_replacement_selections(
        ReplacementTournament(ges.fitness_list, tournament_size=3))

ges.set_maintain_history(True)
ges.create_genotypes()
print ges.run()
sorted(ges.fitness_list)[:10]
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot(ges.get_fitness_history())<jupyter_output><empty_output><jupyter_text>Best generated program:<jupyter_code>print ges.get_best_member().get_program()<jupyter_output>import math
total = 0.0
for i in xrange(100):
    value = float(i) / float(100)
    total += abs(pow(value, 3.0) - pow(value, 3))
fitness = total
self.set_bnf_variable('<fitness>', fitness)<jupyter_text>Worst generated program:<jupyter_code>print ges.get_worst_member().get_program()<jupyter_output>import math
total = 0.0
for i in xrange(100):
    value = float(i) / float(100)
    total += abs(6.2*+math.log(abs(math.log(abs(pow(++-math.sin(math.log(abs(++5.6)))/pow(pow(value, 3.9), 4.7)*value, 3.8))))) - pow(value, 3))
fitness = total
self.set_bnf_variable('<fitness>', fitness)
{'fraction_non_alphanumeric': 0.13619963920625375, 'fraction_numerical': 0.027961515333734217, 'mean_word_length': 4.033282904689864, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '221603', 'license': 'MIT', 'n_tokens_mistral': 1269, 'n_tokens_neox': 1179, 'n_words': 229, 'path': '6/z2.ipynb', 'repo_name': 'iCarrrot/Evol-algs', 'size': '3326'}