<jupyter_start><jupyter_text>Exploring Fractal SetsWith ths notebook, you can navigate through a fractal set and render pictures from the plot. First some imports and definitions: You also can define a complex polynomial here, that will applied to the numbers in the complex plane.<jupyter_code>import numpy as np
import slfractals as slf
from matplotlib import pyplot as plt
from matplotlib import cm

def poly(z, c):
    return z**2 + c<jupyter_output><empty_output><jupyter_text>* Define the polynomial in terms of variable (``z``) and initial value (``c``) that is going to be iterated on ``z``.* You cannot render in parallel with ``poly``, you must use a pre-defined function from ``slf.polynomials``. Rendering in serial way is fine.We can now run the iteration and investigate the occurring values for the iteration in the selected portion of the complex plain. First, we set some parameters for the preview.* List of colormaps: https://matplotlib.org/tutorials/colors/colormaps.html<jupyter_code>params = {
    "max_iter": 200,
    "max_value": 2,
    "xb": (-1.8, 0.67),
    "yb": (-1.2, 1.2),
    "reswidth": 301,
    "cmap": cm.RdYlGn.reversed()
}<jupyter_output><empty_output><jupyter_text>PreviewNavigate the figure (zoom and pan) to explore the fractal set. A recomputation will be issued on the fly. Experiment with the parameters ``max_iter`` and ``max_value`` to get a feeling for what they do.<jupyter_code>%matplotlib notebook

def onzoom(event, ax):
    xb = ax.get_xlim()
    yb = ax.get_ylim()
    C = slf.get_grid(xb, yb, resw=params["reswidth"])
    G = slf.serial_compute(poly, C, max_value=params["max_value"], max_iter=params["max_iter"], colorexp=2)
    ax.clear()
    ax.imshow(
        G,
        cmap=params["cmap"],
        extent=[*xb, *yb],
        aspect="equal"
    )

fig = plt.figure(num=1, figsize=(4.5, 3.5), dpi=200)
fig.clear()
ax = fig.add_subplot(111)
ax.set_xlim(*params["xb"])
ax.set_ylim(*params["yb"])
onzoom(_, ax)
cid = fig.canvas.mpl_connect("button_release_event", lambda event: onzoom(
    event,
    ax
))<jupyter_output><empty_output><jupyter_text>RenderingYou can set different parameters for rendering here:<jupyter_code>renderwidth = 1920
print_max_iter = 300
xb = ax.get_xlim()
yb = ax.get_ylim()
print(xb, yb)<jupyter_output><empty_output><jupyter_text>Serial renderingUse rendering on one core, if you have defined a custom polynomial in ``poly``.<jupyter_code>%%timeit -r 1 -n 1
G = slf.serial_compute(
    poly,
    slf.get_grid(xb, yb, resw=renderwidth, ratio="16:9"),
    max_value=params["max_value"],
    max_iter=print_max_iter
)
slf.render_picture(G, "files", cmap=params["cmap"])<jupyter_output><empty_output><jupyter_text>Parallel rendering Parallel rendering on multiple cores is restricted to pre-defined polynomials from ``slf.polynomials``. It is an issue with ``multiprocessing.Pool`` not allowing being able to pickle lambda functions or functions defined in the notebook. Adapt ``nproc`` to the available computing cores.<jupyter_code>%%timeit -r 1 -n 1
G = slf.parallel_compute(
    slf.mandel,
    slf.get_grid(xb, yb, resw=renderwidth, ratio="16:9"),
    max_value=params["max_value"],
    max_iter=print_max_iter,
    nproc=2
)
slf.render_picture(G, "files", cmap=params["cmap"])
from matplotlib.cm import inferno
inferno(100)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12099430967355496, 'fraction_numerical': 0.01497454327643007, 'mean_word_length': 5.0071942446043165, 'pattern_counts': {'":': 6, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 1, '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': '255738', 'license': 'MIT', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1137, 'n_words': 340, 'path': 'notebooks/explore.ipynb', 'repo_name': 'scherbertlemon/slfractals', 'size': '3339'}