utils package

This package contains the base modules for function definition of attractors and iterative ODE solvers, along with helper functions for handling colormaps and video generation.

utils.base module

Base module which contains the BaseAttractors class.

attractors.utils.base.ATTRACTOR_PARAMS

Contains attributes of all attractors. Loaded from data/params.json file.

Type

dict

class attractors.utils.base.BaseAttractors(attractor: str, params: dict)[source]

Bases: object

Base class where all the attractors are defined with their respective ODE equations.

Note

The attributes for this class which involve the Attractor Parameters are dynamically generated during runtime.

attractor

attractor name

Type

str

__init__(attractor: str, params: dict)[source]

Constructor for BaseAttractors class

Parameters
  • attractor (str) – attractor name

  • params (dict) – dict of the attractor’s parameters

lorenz(coord: ndarray) ndarray[source]

Lorenz, E. N. (1963). “Deterministic Nonperiodic Flow”, Journal of Atmospheric Sciences, 20(2), 130-141.

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

sigma, beta, gamma

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

rabinovich_fabrikant(coord: ndarray) ndarray[source]

Rabinovich, M. I. and Fabrikant, A. L., “Stochastic self-modulation of waves in nonequilibrium media”, Soviet Journal of Experimental and Theoretical Physics, vol. 50, p. 311, 1979.

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

alpha, gamma

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

lotka_volterra(coord: ndarray) ndarray[source]

J. S. Costello, “Synchronization of chaos in a generalized Lotka–Volterra attractor,” The Nonlinear Journal, vol. 1, pp. 11–17, 1999.

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

a, b, c

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

rossler(coord: ndarray) ndarray[source]
    1. Rossler, “An Equation for Continuous Chaos,” Physics Letters A, Vol. 57, No. 5, 1976, pp. 397-398.

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

a, b, c

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

wang_sun(coord: ndarray) ndarray[source]

Wang, Z., Sun, Y., van Wyk, B. J., Qi, G. & van Wyk, M. A. “A 3-D four-wing attractor and its analysis, ” Brazilian J. Phys. 39, (2009) 547–553.

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

a, b, c, d, e, f

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

rikitake(coord: ndarray) ndarray[source]

Rikitake, Tsuneji. “Oscillations of a System of Disk Dynamos.” Mathematical Proceedings of the Cambridge Philosophical Society, vol. 54, no. 1, 1958, pp. 89–105.,

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

a, mu

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

nose_hoover(coord: ndarray) ndarray[source]

Posch et al. “Canonical dynamics of the Nosé oscillator: Stability, order, and chaos.” Physical review. A, General physics 33 6 (1986): 4253-4265.

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

a

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

langford(coord: ndarray) ndarray[source]

W. F. Langford, Numerical studies of torus bifurcations, Numerical methods for bifurcation problems ( Dortmund, 1983), Internat. Schriftenreihe Numer. Math., vol. 70, Birkhäuser, Basel, 1984, pp. 285–295. MR821035

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

alpha, beta, lmbda. omega, rho, epsilon

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

three_cell_cnn(coord: ndarray) ndarray[source]

Arena, P., Caponetto, R., Fortuna, L., and Porto, D., “Bifurcation and Chaos in Noninteger Order Cellular Neural Networks”, International Journal of Bifurcation and Chaos, vol. 8, no. 7, pp. 1527–1539, 1998

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

p1, p2, r, s

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

bouali_type_1(coord: ndarray) ndarray[source]

S. Bouali, A. Buscarino, L. Fortuna, M. Frasca, and L.V. Gambuzza, “Emulating complex business cycles by using an electronic analogue”, Nonlinear Analysis: Real World Applications, 13 (2012), pp. 2459–2465.

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

k, b, mu, p, q, s

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

bouali_type_2(coord: ndarray) ndarray[source]

Bouali, S. “A novel strange attractor with a stretched loop”. Nonlinear Dyn 70, 2375–2381 (2012).

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

a, b, c, s, alpha, beta

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

bouali_type_3(coord: ndarray) ndarray[source]

Bouali, S. “A 3D Strange Attractor with a Distinctive Silhouette. The Butterfly Effect Revisited”. arXiV, (2013).

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

gamma, mu, alpha, beta

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

finance(coord: ndarray) ndarray[source]

Cai, Guoliang & Huang, Juanjuan. (2007). A new finance chaotic attractor. International Journal of Nonlinear Science. vol 3. pp. 1479-3889.

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

a, b, c

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

burke_shaw(coord: ndarray) ndarray[source]

Shaw, Robert. “Strange Attractors, Chaotic Behavior, and Information Flow” Zeitschrift für Naturforschung A, vol. 36, no. 1, 1981, pp. 80-112.

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

s, v

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

moore_spiegel(coord: ndarray) ndarray[source]

Moore, D. W. and Spiegel, E. A., “A Thermally Excited Non-Linear Oscillator”, The Astrophysical Journal, vol. 143, p. 871, 1966.

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

t, r

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

sakarya(coord: ndarray) ndarray[source]

NA

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

a, b

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

dadras(coord: ndarray) ndarray[source]

Dadras, Sara & Momeni, Hamid. (2009). A novel three-dimensional autonomous chaotic system generating two, three and four-scroll attractors. Physics Letters A. 373. 3637-3642.

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

a, b, c, d, h

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

halvorsen(coord: ndarray) ndarray[source]
    1. Sprott and J. C. Sprott, Chaos and time-series analysis, Vol. 69 (Citeseer, 2003)

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

a

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

hadley(coord: ndarray) ndarray[source]
    1. Sprott and J. C. Sprott, Chaos and time-series analysis, Vol. 69 (Citeseer, 2003)

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

a, b, f, g

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

chen(coord: ndarray) ndarray[source]

Chen, G. & Ueta, T. “Yet another chaotic attractor,” International Journal of Bifurcation and Chaos 9, 1465–1466. [1999]

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

a, b, c

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

chen_lee(coord: ndarray) ndarray[source]

Chen HK, Lee CI. “Anti-control of chaos in rigid body motion.”, Chaos, Solitons & Fractals (2004), vol. 21, pp. 957–65

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

a, b, c

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

chen_lu(coord: ndarray) ndarray[source]

Lu, Jinhu & Chen, Guanrong. (2002). “A New Chaotic Attractor Coined.”. International Journal of Bifurcation and Chaos. vol. 12. pp-659-661.

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

a, b, c

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

thomas(coord: ndarray) ndarray[source]

Thomas, René. “DETERMINISTIC CHAOS SEEN IN TERMS OF FEEDBACK CIRCUITS: ANALYSIS, SYNTHESIS, “LABYRINTH CHAOS”.” International Journal of Bifurcation and Chaos 9 (1999): 1889-1905.

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

b

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

dequan_li(coord: ndarray) ndarray[source]

Li, Dequan., “A three-scroll chaotic attractor.” Physics Letters A. 372. 387-393. (2008).

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

a, c, d, e, k, f

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

yu_wang(coord: ndarray) ndarray[source]

F. Yu, C. H. Wang, and J. W. Yin, “A 4-D chaos with fully qualified four-wing type,” Acta Physica Sinica, vol. 61, (2012).

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

a, b, c, d

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

newton_leipnik(coord: ndarray) ndarray[source]

Leipnik, R. B. & Newton, T. A. “Double strange attractors in rigid body motion with linear feedback control, ” Phys. Lett. A86, 63–67. (1981)

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor Parameters

alpha, beta

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

rucklidge(coord: ndarray) ndarray[source]

Rucklidge, A. Chaos in models of double convection. J. Fluid Mech. 1992, 237, 209–229.

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor parameters

k,alpha

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

shimizu_morioka(coord: ndarray) ndarray[source]

Shimizu, T.; Morioka, N. On the bifurcation of a symmetric limit cycle to an asymmetric one in a simple model. Phys. Lett. A 1980, 76, 201–204.

Parameters

coord (np.ndarray) – Initial coordinate array [x, y, z]

Attractor parameters

a,B

Returns

ODE for single step [dx, dy, dz]

Return type

np.ndarray

utils.colortable module

Module that handles palettes and colormaps

attractors.utils.colortable.hex_to_rgb(value: str) List[float][source]

Converts hex to normalized rgb colours

Parameters

value (str) – string of 6 characters representing a hex colour

Returns

rgb color list

Return type

list[float]

attractors.utils.colortable.get_continuous_cmap(hex_list: List[str]) LinearSegmentedColormap[source]

Creates and returns a color map from a given hex list.

Parameters

hex_list (list[str]) – list of hex code strings

Returns

Colormap of given hex list.

Return type

matplotlib.colors.LinearSegmentedColormap

utils.des module

Module which contains iterative methods for solving Ordinary Differential Equations (ODE)

class attractors.utils.des.DES(attractor: str, init_coord: ndarray, params: dict)[source]

Bases: BaseAttractors

Differential Equations Solver (DES) class contains iterative methods for solving Ordinary Differential Equations (ODE). Currently includes the following methods: Euler, RK2, RK3, RK4, RK5. For more info: see https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods

coord

current coordinate of the attractor as (3,) ndarray

Type

np.ndarray

X

current X coordinate of the attractor

Type

float

Y

current Y coordinate of the attractor

Type

float

Z

current Z coordinate of the attractor

Type

float

ts

current time step

Type

int

N

number of points set for simulating the attractor

Type

int

__init__(attractor: str, init_coord: ndarray, params: dict)[source]

Constructor for DES class

Parameters
  • attractor (str) – attractor name

  • init_coord (np.ndarray) – initial coordinate array

  • params (dict) – dict of the attractor’s parameters

euler(a: int, b: int, n: int) Iterator[DES][source]

First order Euler method

Parameters
  • a (int) – simulation initial time step

  • b (int) – simulation final time step

  • n (int) – simulation points

Yields

object – instance of DES

rk2(a: int, b: int, n: int, method: str) Iterator[DES][source]

Second order Runge-Kutta method

Euler’s method is a simple one-step method used for solving ODEs. In Euler’s method, the slope is estimated in the most basic manner by using the first derivative.

Parameters
  • a (int) – simulation initial time step

  • b (int) – simulation final time step

  • n (int) – simulation points

  • method (str) – RK2 method to be used

Yields

object – instance of DES

rk3(a: int, b: int, n: int) Iterator[DES][source]

Third order Runge-Kutta method

Parameters
  • a (int) – simulation initial time step

  • b (int) – simulation final time step

  • n (int) – simulation points

Yields

object – instance of DES

rk4(a: int, b: int, n: int) Iterator[DES][source]

Fourth order Runge-Kutta method

Parameters
  • a (int) – simulation initial time step

  • b (int) – simulation final time step

  • n (int) – simulation points

Yields

object – instance of DES

rk5(a: int, b: int, n: int) Iterator[DES][source]

Fifth order Runge-Kutta method

Parameters
  • a (int) – simulation initial time step

  • b (int) – simulation final time step

  • n (int) – simulation points

Yields

object – instance of DES

utils.video module

Module that handles video generation by piping matplotlib figure canvas to ffmpeg

Note

This module does not explicitly check for ffmpeg installation and does not handle errors related to that.

attractors.utils.video.drawer(frame: int, fig: Figure, ufunc: callable) bytes[source]

Update function for pathos pool map which returns an RGB byte string of the canvas for ffmpeg pipe

Parameters
  • frame (int) – index to set data and draw canvas

  • fig (matplotlib.figure.Figure) – matplotlib figure instance

  • ufunc (callable) – animation function from Attractors class

Returns

canvas as RGB byte-string

Return type

bytes

attractors.utils.video.ffmpeg_video(fig: Figure, update_func: callable, points: int, fps: int, outf: str)[source]

Generates output video given a animation function via ffmpeg

Parameters
  • fig (matplotlib.figure.Figure) – matplotlib figure instance

  • update_func (callable) – animation function from Attractors class

  • points (int) – number of points used for the simulation

  • fps (int) – frames per second for output video

  • outf (str) – output video filename