<jupyter_start><jupyter_text>Imports<jupyter_code>import importlib
import build
import matplotlib.pyplot as plt
import seaborn as sns

importlib.reload(build)<jupyter_output><empty_output><jupyter_text>Instantiate Model<jupyter_code>model = build.GeneticAlgo(N=80,
                          mutate_proba=0.01,
                          max_epochs=1,
                         auto_plot=False)
model.run()
d = build.DynamicTuner(model,max_epochs=2000)
d.run()<jupyter_output>Generation: 81 Fitness: 88.3
Generation: 101 Fitness: 96.3<jupyter_text>Uncomment this section to watch the realtime evolution<jupyter_code># model.auto_plot=False
# model.max_epochs=-1
# model.run()<jupyter_output><empty_output><jupyter_text>Generate Animation<jupyter_code>import animatplot as amp
import numpy as np

# Animation duration
skip_interval =1
t = range(0,len(model.generation_list),skip_interval)
worlds = [model.generation_list[i].world for i in t] 

# Setup Fitness array
fitness_idx = [[x] for x in range(0,len(model.generation_fitness),skip_interval)]
fitness_values = [[model.generation_fitness[x]] for x in range(0,len(model.generation_fitness),skip_interval)]

# Create Figure
fig, (ax1, ax2) = plt.subplots(1, 2)
ax2.set_xlim(0,len(model.generation_fitness))
ax2.set_ylim(0,max(model.generation_fitness))
ax2.set_xlabel('Generation')
ax2.set_ylabel('Fitness Function')
ax2.set_title('Generation vs Fitness')
plt.gca().set_aspect('auto')
plt.tight_layout()

# Animation Settings
print(np.array(worlds).shape)
timeline = amp.Timeline(t, fps=30)
block = amp.blocks.Imshow(worlds,ax=ax1)
block2 = amp.blocks.Scatter(fitness_idx,fitness_values,ax=ax2)
anim = amp.Animation([block,block2], timeline)

anim.controls()
anim.save_gif('generation_fitness11')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1226890756302521, 'fraction_numerical': 0.025210084033613446, 'mean_word_length': 6.172690763052209, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '595064', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 691, 'n_tokens_neox': 654, 'n_words': 107, 'path': 'build.ipynb', 'repo_name': 'nightvision04/genetic_world_building', 'size': '1785'}