-
Notifications
You must be signed in to change notification settings - Fork 1
/
discrete_chaos.py
executable file
·59 lines (44 loc) · 1.59 KB
/
discrete_chaos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
import numpy as np
from itertools import count
from functools import partial
from matthew import show_pointcloud
def kaplan_yorke(alpha, initial_value, n, b=18014398241046527):
def kaplan_yorke_map():
a = 1
x = initial_value
yield x.copy()
for _ in range(n - 1):
a = (2 * a) % b
x[0] = a / b
x[1] = alpha * x[1] + np.cos(4 * np.pi * x[0])
yield x.copy()
return np.array([*kaplan_yorke_map()])
def henon(b, a, initial_value, n):
def henon_map():
x = initial_value
yield x.copy()
for _ in range(n - 1):
x[0] = 1 - a * x[0] ** 2 + x[1]
x[1] = b * x[0]
yield x.copy()
return np.array([*henon_map()])
if __name__ == "__main__":
n_points_per_alpha = 1000
worker = partial(henon,
a=1.4,
initial_value=np.array([0.5, 0.2]),
n=n_points_per_alpha)
from multiprocessing import Pool
n_alpha = 500
alpha = np.linspace(-.7, 2.7, n_alpha)
points = np.empty((n_alpha * n_points_per_alpha, 3))
with Pool() as p:
for i, alpha, traj in zip(count(), alpha, p.map(worker, alpha)):
points[i * n_points_per_alpha:(i + 1) * n_points_per_alpha, 0:2] = traj
points[i * n_points_per_alpha:(i + 1) * n_points_per_alpha, 2] = alpha
from matplotlib.cm import get_cmap
for i in [0, 1, 2]:
p = points[:, i]
points[:, i] = (p - p.min()) / (p.max() - p.min())
show_pointcloud(points, colors=get_cmap()(points[:, 2]))