# Attractors panel¶ Strange attractors are a type of iterative equation that traces the path of a particle through a 2D space, forming interesting patterns in the trajectories.

There are many attractor families determined by a set of attractor equations, each with associated numerical parameters. To make the parameter space easy to explore, we'll build an app that selects between the attractor families and allows you to manipulate their parameter values. Using this app requires conda install -c pyviz/label/dev panel param datashader and a live, running Python process (not just a static web page or anaconda.org viewer). You may wish to check out the much simpler Clifford-only app first, to understand the basic structure of an app and of how to compute an attractor.

## Attractor definitions¶

First, we'll define a function for collecting the values of any attractor function with up to six parameters, using Numba to make it 50X faster than bare Python:

In :
import numpy as np, pandas as pd
from numba import jit

@jit(nopython=True)
def trajectory_coords(fn, x0, y0, a, b, c, d, e, f, n):
x, y = np.zeros(n), np.zeros(n)
x, y = x0, y0
for i in np.arange(n-1):
x[i+1], y[i+1] = fn(x[i], y[i], a, b, c, d, e, f)
return x, y

def trajectory(fn, x0, y0, a, b=None, c=None, d=None, e=None, f=None, n=1000000):
xs, ys = trajectory_coords(fn, x0, y0, a, b, c, d, e, f, n)
return pd.DataFrame(dict(x=xs,y=ys))


Next, we'll define a class hierarchy to provide a shared interface for the various attractor types:

In :
import param, panel as pn, inspect
pn.extension('katex')

class Attractor(param.Parameterized):
"""A parameterized object that can evaluate an attractor trajectory"""

x = param.Number(0,  softbounds=(-2, 2), doc="Starting x value", precedence=-1)
y = param.Number(0,  softbounds=(-2, 2), doc="Starting y value", precedence=-1)

a = param.Number(1.7, bounds=(-3, 3), doc="Attractor parameter a")
b = param.Number(1.7, bounds=(-3, 3), doc="Attractor parameter b")

colormap = param.ObjectSelector("kgy", precedence=0.7, check_on_set=False,
objects=['bgy', 'bmw', 'bgyw', 'bmy', 'fire', 'gray', 'kgy', 'kbc', 'viridis', 'inferno'])

equations = param.List([], class_=str, precedence=-1, readonly=True)

__abstract = True

def __call__(self, n, x=None, y=None):
"""Return a dataframe with *n* points"""
if x is not None: self.x=x
if y is not None: self.y=y
args = [getattr(self,p) for p in self.sig()]
return trajectory(self.fn, *args, n=n)

def vals(self):
return [self.__class__.name] + [self.colormap] + [getattr(self,p) for p in self.sig()]

def sig(self):
"""Returns the calling signature expected by this attractor function"""
return list(inspect.signature(self.fn).parameters.keys())[:-1]

class FourParamAttractor(Attractor):
"""Base class for most four-parameter attractors"""
c = param.Number(0.6, softbounds=(-3, 3), doc="Attractor parameter c")
d = param.Number(1.2, softbounds=(-3, 3), doc="Attractor parameter d")

__abstract = True
{"ft_lang_label":"__label__en","ft_lang_prob":0.5294765,"math_prob":0.98328936,"size":3050,"snap":"2019-51-2020-05","text_gpt3_token_len":849,"char_repetition_ratio":0.13657255,"word_repetition_ratio":0.045346063,"special_character_ratio":0.2885246,"punctuation_ratio":0.22105263,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99686956,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-01-19T12:53:21Z\",\"WARC-Record-ID\":\"<urn:uuid:3ec7600d-0a69-4d8d-9f13-8881d0e5074a>\",\"Content-Length\":\"1049294\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:5a6b9742-1233-494f-bcf0-e4813a0ed01d>\",\"WARC-Concurrent-To\":\"<urn:uuid:46f8569a-e288-454b-9149-7d403dad861f>\",\"WARC-IP-Address\":\"185.199.111.153\",\"WARC-Target-URI\":\"https://examples.pyviz.org/attractors/attractors_panel.html\",\"WARC-Payload-Digest\":\"sha1:YP6AATI4JGB7QLP4KRGFRNFISQAMISPI\",\"WARC-Block-Digest\":\"sha1:6ARUE46OFFTCWMP24FWB5PFXHHD5QLWO\",\"WARC-Truncated\":\"length\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-05/CC-MAIN-2020-05_segments_1579250594603.8_warc_CC-MAIN-20200119122744-20200119150744-00053.warc.gz\"}"}