<jupyter_start><jupyter_text>an interactive version of Tensorflow Mandelbrot set tutorialbased on original tutorial at https://www.tensorflow.org/tutorials/mandelbrot<jupyter_code># imports for simulation
import tensorflow as tf
import numpy as np

# imports for visualization
import PIL.Image
from io import BytesIO
from IPython.display import Image, display

# imports for interaction 
from ipywidgets import interact, FloatSlider
def DisplayFractal(a, fmt='jpeg'):
  """Display an array of iteration counts as a
     colorful picture of a fractal."""
  a_cyclic = (6.28*a/20.0).reshape(list(a.shape)+[1])
  img = np.concatenate([10+20*np.cos(a_cyclic),
                        30+50*np.sin(a_cyclic),
                        155-80*np.cos(a_cyclic)], 2)
  img[a==a.max()] = 0
  a = img
  a = np.uint8(np.clip(a, 0, 255))
  f = BytesIO()
  PIL.Image.fromarray(a).save(f, fmt)
  display(Image(data=f.getvalue()))
def recalc(zoom, xoffset, yoffset): 
    print("scale=" + str(zoom) + ", center=[" + str(xoffset) + ":" + str(yoffset) + "]")
    Y, X = np.mgrid[(-2.0/zoom)+yoffset:(2.0/zoom)+yoffset:0.005/zoom, 
                    (-2.0/zoom)+xoffset:(2.0/zoom)+xoffset:0.005/zoom] 
    Z = X+1j*Y
    sess = tf.InteractiveSession()

    xs = tf.constant(Z.astype(np.complex64))
    zs = tf.Variable(xs)
    ns = tf.Variable(tf.zeros_like(xs, tf.float32))

    tf.global_variables_initializer().run()

    # Compute the new values of z: z^2 + x
    zs_ = zs*zs + xs

    # Have we diverged with this new value?
    not_diverged = tf.abs(zs_) < 4

    # Operation to update the zs and the iteration count
    step = tf.group(
      zs.assign(zs_),
      ns.assign_add(tf.cast(not_diverged, tf.float32))
      )

    for i in range(200): step.run()
    DisplayFractal(ns.eval())
    sess.close()
def zoom_changed(zoomer, xoff, yoff):
    zoom = zoomer
    recalc(zoomer, xoff, yoff)
    
interact(zoom_changed, 
         zoomer = FloatSlider(min=1,max=50,step=0.5,value=1, continuous_update=False), 
         xoff = FloatSlider(min=-2, max=2, step=0.05, value=-0.5, continuous_update=False), 
         yoff = FloatSlider(min=-2, max=2, step=0.05, value=0.0, continuous_update=False));<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14595571622232265, 'fraction_numerical': 0.03389064618165386, 'mean_word_length': 3.3326810176125243, 'pattern_counts': {'":': 1, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '449079', 'license': 'Apache-2.0', 'n_tokens_mistral': 865, 'n_tokens_neox': 813, 'n_words': 174, 'path': 'mandelbrot/interactive_mandelbrot.ipynb', 'repo_name': 'GreggHelt2/fractalflow', 'size': '2213'}