<jupyter_start><jupyter_text>Simple pipeline exampleThis is intended to exercise the most basic of LEAP features, such as cloning, mutation, and selection.<jupyter_code>import sys, os
import toolz

from leap_ec.individual import Individual
from leap_ec.binary_rep.ops import mutate_bitflip
import leap_ec.ops as ops<jupyter_output><empty_output><jupyter_text>Let's create a simple population of three individuals that have a binary representation of two bits each.  Moreover, let's set their bits to be all zeroes.<jupyter_code>pop = []

pop.append(Individual([0, 0]))
pop.append(Individual([0, 0]))
pop.append(Individual([0, 0]))

pop<jupyter_output><empty_output><jupyter_text>Let's just do a simple mutation pipeline *without* cloning to demonstrate that mutating individuals will affect the original population.<jupyter_code>new_pop = toolz.pipe(pop,
                     ops.naive_cyclic_selection,
                     mutate_bitflip(expected_num_mutations=2),
                     ops.pool(size=3))
new_pop<jupyter_output><empty_output><jupyter_text>Note that all the bits have flipped, which confirms that the mutation operator was applied successfully.However, because we didn't clone the individuals, the *original* population was altered.  What's interesting is that it appears that not all the individuals were, but more than likely the iterator just moved ahead and over-wrote the last two individuals again.<jupyter_code>pop<jupyter_output><empty_output><jupyter_text>Let's try this exercise again, but this time add a clone operator.<jupyter_code>pop = []

pop.append(Individual([0, 0]))
pop.append(Individual([0, 0]))
pop.append(Individual([0, 0]))

pop
new_pop= toolz.pipe(pop,
                       ops.naive_cyclic_selection,
                       ops.clone,
                       mutate_bitflip(expected_num_mutations=2),
                       ops.pool(size=3))
print(new_pop)<jupyter_output>[Individual([1, 1], None, None), Individual([1, 1], None, None), Individual([1, 1], None, None)]<jupyter_text>And now we can show that `pop` is untouched, unlike in the previous example.<jupyter_code>pop<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0921358771521638, 'fraction_numerical': 0.010237319683573755, 'mean_word_length': 4.555555555555555, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '355191', 'license': 'AFL-3.0', 'n_tokens_mistral': 674, 'n_tokens_neox': 617, 'n_words': 193, 'path': 'examples/simple/simple_pipeline.ipynb', 'repo_name': 'kexinchenn/LEAP', 'size': '2149'}