Article #005: Chaos Theory

Published: 01/15/2023

Chaos can be found everywhere because it is a natural attribute of life. Nature tends to be chaotic in general.
In this article, I deep dive into how mathematical maps and functions can be used to convey and measure chaos. We will try to take steps towards understanding how chaos works in this universe.

All of the manim and matplotlib code written for the conducted research can be found in BooleanCube/chaos-theory

Logistic Map

The Logistic Map is derived from a simple mathematical recursive function: x_(n+1) = r * (x_n) * (1-x_n)
In this case, I would like to take the example of a population percentage over time (years) graph to explain the logistic map.

  • x_(n+1) represents population percentage next year (a value in the interval [0,1])
  • x_n represents the population percentage this year (a value in the interval [0,1])
  • r represents the fertility rate (a value in the interval [0,4])

The very simple equation has extremely complex behaviour that becomes very chaotic (hard to predict) at high rate (r) values.
These types of maps are often used to be able to predict population percentage or visualize repetitive chaos until the repeating window is so large that it is considered to be arbitrary. When you graph out the logistic map for population percentage over time, we see that for each rate of change value (r) there is a set equilibrium value regardless of initial population percentage (x_0) which is where all randomness and chaos ceases and settles in at a particular point. So, let's explore how the equilibrium point is related to the rate of change (fertility rate) values.


Relationship between rate of change and equilibrium points

  • When the rate of change (fertility rate) is too low, for example less than 1.00, the equilibrium point will be 0.00 which means the species has gone extinct.
    image
  • When the rate of change (fertility rate) is decently large, for example less than 3.00, the equilibrium point will be at a set value above 0.00 so the population settles in at a percentage, the equilibrium point, without going extinct. This phenomenon is common in nature, as we usually see the populations start to stabilize over time as long as there are no external events causing the population percentage to falter. In this example we can see the equilibrium point to be ~0.65. image
  • So far, the equilibrium graph seems reasonable and appropriate. However, this is where the chaos begins. When the rate of change (fertility rate) is too high, for example greater than or equal to 3.00, we start to see more than 1 equilibrium point and more arbitrary results. As the fertility rate (rate of change) increases, the chaos (randomness) also grows exponentially and splits into more equilibrium points exponentially. When the equilibrium point splits into multiple points again, we call it a bifurcation. At r=3.6 we start to see fractal-like behaviour in the logistic map because of the amount of bifurcations. This phenomenon is also fairly common in nature, as some populations could oscillate between different percentage values over a window of time repeatedly. In this example, we can see there are 4 equilbirium points, so there must have been 3 period-doubling bifurcations in the equilibrium graph (First splits into 2, and then the 2 split into 4).
    image


Bifurcation Diagram

The Bifurcation Diagram graphically represents the behaviors observed between the rate of change and the equilibrium points as mentioned above in "Chaos Theory" The figure below graphs the detailed complexity of how the rate of change affects equilibrium, in other words, how the rate of change relates to chaos. We can visually see most of the periodically doubling bifurcation but after r=3.6 it starts to get really chaotic and the equilibrium points are almost entirely random.

image


Feigenbaum Constant

Mitchell J. Feigenbaum observed that there was a common ratio between the widths of the periodically doubling bifurcations. Even though Feigenbaum originally related to the period-doubling bifurcations in the logistic map, it showed universality (observed as a property in large independent systems. Therefore, we can conclude that every chaotic system that fits the requirements will bifurcate at the same constant rate.

The feigenbaum constant is the limit as n approaches infinity of the ratio between each bifurcation interval width to the next between every period-doubling.

image
image

As we can see from our graphed bifurcation diagram figure above, the bifurcation intervals and the interval widths match the description in the table above and so I can conclude with my calculations that the feigenbaum constant is indeed ~4.669.



Usage


Static Equilibrium Graphing Simulation

Note: Make sure you have installed the matplotlib python package before running this python script.
To start the static equilibrium graph simulation, run the following command:

$ python3 static_equilibrium_graph.py

You will then be greeted with a prompt for input data. The script allows you to configure the variables to your choosing before visualizing the results. The prompt will look something similar to this:

image

After completing the input data prompts, the application will open a graph visualizer with the equilibrium graph (helps visualize the population percentage over time ratio) and a visual comparison between x_(n+1) and x_n to help explain how the population percentage may jump up and down but settle in at an equilibrium point.

image


Dynamic Manim Equilibrium Graph

Note: Make sure you have installed all REQUIRED AND OPTIONAL dependencies for manim first, and then installed the manim library itself.
To start the dynamic manim equilibrium graph, run the following command:

$ manim -p -ql dynamic_equilibrium_graph.py DynamicEquilibriumGraph

Similar to the Static Equilibrium Graph, this script also generates all equilibrium graphs by iterating through the interval values for the rate of change variable. This equilibrium graph script is animated with manim and is not as configurable as the equilibrium graph with the matplotlib package.

dynamicequilibriumgraph


Bifurcation Diagram

Note: Make sure you have installed all REQUIRED AND OPTIONAL dependencies for manim first, and then installed the manim library itself.
To start the bifurcation diagram figure animation, run the following command:

$ manim -p -ql bifurcation_diagram.py BifurcationDiagram

As described in the Bifurcation Diagram Analysis, this is nothing more than an animation of the Bifurcation Diagram being generated. You can also see the animation without having to run the manim code:

bifurcationdiagram


Feigenbaum Constant Calculator

Note: You must have any version of python3 installed on your computer. Preferably one of the more recent versions (Versions 3.7.9+) To start the feigenbaum calculator, run the following command:

$ python3 feigenbaum_calculator.py

This runs a simulation of ALL equilibrium graphs with r values that iterates every 0.00001. Such a small iteration amount makes the calculator very slow to make calculations but also makes it more precise. As described in the Feigenbaum Constant Analysis, the calculator finds the bifurcation parameters where the number of equilibrium points double. The calculations are not entirely precise and accurate because of the rounding of the rate of change values and the bifurcation parameter values. There is no way to really calculate where the period-doubling bifurcations are, so we have to run simulations with perfect precision to observe where they appear. Here are the most precise results I could produce:

image
image

We can see from the calculations, the ratio that is being calculated as n approaches infinity continuously moves towards ~4.669 which is the feigenbaum constant.



Installation

REQUIREMENT: Must install Python 3.7+ (Versions of Python under 3.7 will not work for manim)

Before we download the chaos-theory project and run it, we need to install manim, a mathematics animation tool, and a bunch of other python packages that were used for the project.
Note: Please download all the REQUIRED AND OPTIONAL dependencies before moving on to installing manim.


Linux

Follow the installation instructions on the manim installation documentation page to completely install manim. To finally install manim after installing the dependencies and rebooting your system, run the following command in a terminal:

$ pip3 install manim

Windows

Follow the installation instructions using a package manager or installer of your choice from the manim installation documentation page. To finally install manim after installing the dependencies, run the following command in your command prompt:

$ python -m pip install manim

MacOS

Follow the installation instructions using a package manager or installer of your choice form the manim installation documentation page. To finally install manim after downloading the dependencies, run the following command in your terminal:

$ pip3 install manim

Python Packages

After installing manim successfully, we have to install some other python packages for GUI.
Matplotlib, a graphing math utility for python, can be installed through pip just like manim and is necessary to run some parts of this application.

$ pip3 install matplotlib

or

$ python3 -m pip install matplotlib

Download Project

Run the following commands to downloads the project to be able to run the scripts:

$ cd /temp/directory/for/project/
$ git clone https://github.com/BooleanCube/chaos-theory.git

Look at the usages of the project to see how to run the different scripts.



References

Veritasium is a channel of science and engineering videos featuring experiments, expert interviews, cool demos, and discussions with the public about everything science.
I recently came across a very intriguing video about chaos theory that they produced and was inspired to build this myself because I wanted to explore the logistic map and chaos for myself.
u/streamer3222 reached out to me on reddit and introduced me to the henon map, which also has chaotic attributes. Their code and simulations can be found in this GitHub repository in the henon_map/ folder. Check out their visualization video


Packages Used:

IEEE COMPUTER SOC. (2007). Matplotlib: A 2D graphics environment (Version 3.6.0) [Computing in Science \& Engineering]. 10.1109/MCSE.2007.55
The Manim Community Developers. (2022). Manim – Mathematical Animation Framework (Version v0.16.0) [Computer software]. https://www.manim.community/



Written by BooleanCube :]