Welcome to chaoseverywhere’s documentation!

This package was made as a project in the software devlopment course. The main goal here is to observe the behaviour of both the Mandelbrot set and the logistic map. And because we mainly learn with examples, detailled explanations of the objects and their construction are presented in the gallery.

Guide

How to install chaoseverywhere

Install from github

In order to install this package, one can simply put in the prompt:

$ pip install git+https://github.com/tanglef/chaoseverywhere

Special dependencies

In order to fully use this package, one must have Mayavi installed and ready to use and also the FFMPEG writer.

  • Mayavi: VTK and PyQt5 (or another supported GUI toolkit for Python 3) are necessary please refer to this tutorial.

  • FFMPEG: simply run sudo apt install ffmpeg if you’re using a UBUNTU distribution.

Tip

If you’re using Windows, you will need to install FFMPEG by downloading the folder of the latest version, save it where you’d like (usually the root of the disk) and add the path to its bin folder to the PATH environment variables. If you’re using Windows 7/8, add a semicolon at the end of the added path.

Once you’re done, you can test your installation by running the plot_bifurcation.py file in the \examples directory.

Contacts

If you have an improvment to make or point out an error, you can fill out a pull request on Github.

One can also reach us using the emails adress right below :

Sources and some more

The mathematics behind and more explainations

Some inspiring videos

We sorted these links by increasing difficulty. This in no way means, that one shouldn’t consider to watch them all. They all deal with fractals and the math around them and one can learn a lot (just like us) with those.

The Mandelbrot set

The creation

The Mandelbrot set \(\mathcal{M}\) is defined as :

\[\mathcal{M}=\left\{ c\in\mathbb{C},\ (z_n)_n \text{ is bounded},\ \text{with } z_{n+1}=z_n^2+c,\ z_0=0\right\}.\]

Given the fact that it is a set of points, we can compute it using a class Python object. Thus, determine which arguments to pass in order to instantiate one set, and what methods to compute. What a user (you hopefully) might want to ask oneself is:

  • where should I center the picture of the Mandelbrot set?

  • do I want the whole set or just a special part? If the latest, what square exactly would I want to look at?

  • do I need of lot of iterations of the sequence: meaning more time to make, or can I be satisfied with a reasonable number of iterations?

Note

For only aesthetics purposes, we chose not to let the user display a rectangular part of the Mandelbrot set but only a square one.

So, the windows that will be displayed will be a square centered at the point \(a+bi\). The user will input this point separating the real part and the imaginary part in the two arguments x and y. The size of the square is determined by the facteur argument representing the half-length of the side of the square one’d like to display.

A summary to keep in mind

Methods Output
numpy array saved video matplotlib plot
anim_puiss_mandel X
anim_pics_mandel X
animate_mandel_plt X
disp_mandel X
mandel_loop X
mandel_transform X
mandelbrot
X

The class methods

Additional function in the submodule

As part of the link with the logistic map, we needed a function that could return a stairs-like data about the different values that would take the map \(z_{n+1}=z_n^2+c\) with different values for \(c\). See the bifurcation video in the gallery for the actual plot.

One can use this function to produce the same plot in the top-right of the video in the bifurcation diagram section of the gallery using the code below.

plt.style.use(['ggplot', 'dark_background'])

data = zip(*chaos.mandel_branch_points(0,-1,50))
ax2 = plt.subplot()
x = np.linspace(-2, 1, 400)

line, = ax2.plot([],[], color='red', alpha=1, lw=4)
line.set_data(data)

courbe, = ax2.plot([], [], color='dodgerblue', alpha=1, lw=2)
courbe.set_data(x, x**2-1)
ax2.plot(x, x, color='orange')
plt.show()

The logistic map

Introduced by the biologist Robert May in 1976, the logistic map turned out to be a lot more complex that meets the eye.

Definitions

The logistic map is a recursive sequence defined as:

\[x_{n+1}=rx_n(1-x_n),\]

where \(r\in [1,4]\) is the growth ratio and with \(x_0\in[0,1]\). The goal of this module is to be able tu visualize the logistic map, but also to create its bifurcation diagram and link it to the Mandelbrot set.

The bifurcation diagram is a plot of where the logistic map tends to. It shows us that as the growth ratio approaches \(4\), the chaotic behaviour appears.

Summary of the outputs

Methods Output
float video matplotlib plot
animate_logistic X
connections X
logistic X
logistic_draw X
bifurcation X X
logi_branch_points X
plot_logi_interact X

Some other requirements for the project

Sparse matrix

Sparse matrix are very efficient when we need to use a matrix with a lot of zeros-values. To illustrate its use, we need a function that will randomly spread numbers with a chosen density.

Pixel colors

When we use the mandel_loop function, one can visualize the speed of divergence of the \((z_n)_n\) sequence. We built an histogram representing each color for the speed of divergence on the \((0,x)\) axis and the associated number of pixels in a chosen window on the \((0,y)\) axis.

Let’s play with the Mandelbrot equation

3d_vision

3d_transform

puiss4

The Mandelbrot set with three dimensions

Some setup
import chaoseverywhere as chaos
from mayavi import mlab
Is it really a fractal in 3-dimensional fractal ?

The Mandelbrot set is defined by its famous equation \(z_{n+1}=z_n^2+c\). Having a 3-dimensional visualization of this set is very complex and to be considered a 3D fractal, we need to keep the fractal part of the object. We often consider the Mandelbulb as the 3-dimensional representation of the Mandelbrot set. However, we can’t make a 3D Mandelbrot set in the way we’d like to be. So in this package you won’t be able to see a Mandelbulb or some bootleg version of that can be found of it. Here we will only use the third dimension to see the speed of divergence of the points.

Construction

First, we define the function of the Mandelbrot set \(f(z,c):\mathbb{C}\times\mathbb{C}\longrightarrow\mathbb{C}\) as above.

def transform(z,c):
    return(z**2 + c)

Then, we use the Mandelbrot_disp class in this package to create a basis for the set, and then we use mayavi to display our work.

mandel = chaos.Mandelbrot_disp(1.5,0,2.5, precision=600).mandel_transform(FUN=transform)
mlab.figure(size=(800, 800))
mlab.surf(mandel, colormap='bones', warp_scale='auto', vmax=1.5)
mlab.view(elevation=18)
mlab.close()
The hidden part of the iceberg

We can clearly see the different speed of divergence, so let’s take a look around them. On one side we see the points inside the Mandelbrot set and we can observe a denser part at the extrimity along the the real axis. On the flipped side, we can see that there is a sharp contrast between the speed of divergence of most of the points, and the one the nearest to boundary.

You can produce the same animation using the code below.

chaos.Mandelbrot_disp(-.5,0,1.5, 200,500).anim_pics_mandel(go_up=False)

The Magnet 1 transformation

Some setup
import chaoseverywhere as chaos
from mayavi import mlab
import os
Transformed Mandelbrot set

The Mandelbrot set is defined by its famous equation \(z_{n+1}=z_n^2+c\). Now, what happens if we change that formula.

\[z_{n+1}=f(z_n,c)=\left(\dfrac{z_n^2+c-1}{2z_n+c-2}\right)^2,\]

with \(z_0=0\in\mathbb{C}\).

Construction

First, we define the function \(f(z,c):\mathbb{C}\times\mathbb{C}\longrightarrow\mathbb{C}\) as above.

def transform(z,c):
    return(((z ** 2 + c -1)/(2*z +c-2))**2)

Then, we use the Mandelbrot_disp class in this package to create a basis for the set, and then we use mayavi to display our work.

mandel = chaos.Mandelbrot_disp(1.5,0,2.5, precision=600).mandel_transform(FUN=transform)
mlab.figure(size=(800, 800))
mlab.surf(mandel, colormap='hot', warp_scale='auto', vmax=1.5)
mlab.view(elevation=180)
mlab.close()
What are we looking at ?

This transformation is called the Magnet (1) and represents the way magnets behave under high temperatures. It was discovered by two physicits Yang and Lee who dit not expect to see a fractal in their study.

Changing the power in the equation

Some setup
import chaoseverywhere as chaos
from mayavi import mlab
An example with a power of 4

The Mandelbrot set is defined by its famous equation \(z_{n+1}=z_n^2+c\). But one could rightfully ask : why \(2\) exactly ? So let’s fulfill our curious needs and see what happens if we take \(z_{n+1}=z_n^4+c\) as our equation.

Construction

First, we define the function of the Mandelbrot set \(f(z,c):\mathbb{C}\times\mathbb{C}\longrightarrow\mathbb{C}\) as above.

def transform(z,c):
    return(z**4 + c)

Then, we use the Mandelbrot_disp class in this package to create a basis for the set, and then we use mayavi to display our work.

mandel = chaos.Mandelbrot_disp(1.5,0,2.5, precision=600).mandel_transform(FUN=transform)
mlab.figure(size=(800, 800))
mlab.surf(mandel, colormap='hot', warp_scale='auto', vmax=1.5)
mlab.view(elevation=18)
mlab.close()

We can clearly see some king of duplicates into three of Mandelbrot sets displaying themselves around the main bulb and allowing for each of them a third of the space to grow.

And for the other powers ?

For a power of \(2\), we see one big ramification extending over the real axis. For a power of \(4\) we see three of them. So we can conjecture that for any positive integer \(p\) as the power, we will see \(p-1\) main ramifications around the main bulb. Let’s see if that checks out for the first hundred powers.

One can reproduce this animation using the code below.

chaos.Mandelbrot_disp(0,0,2,t_max=150, precision=500).anim_puiss_mandel(remove=True)

Indices and tables