-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added examples folder and updated project readme.
- also added new attractor_animation.gif.
- Loading branch information
1 parent
18fafea
commit 0017aa8
Showing
8 changed files
with
182 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Examples: | ||
|
||
### Contents | ||
- ``double_pendulum_lyapunov_spectrum.py``: Plot the lyapunov spectrum of the double pendulum. | ||
- ``lyapunov_spectra_of_3d_autonomous_flows.py``: Plot the Lyapunov spectrum of all 3D autonomous dissipative flow systems. | ||
|
||
⚠️ Not many examples here yet, and examples might be flawed. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
"""Lyapunov Spectrum of single system.""" | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
from lorenzpy import measures as meas | ||
from lorenzpy import simulations as sims | ||
|
||
sys_obj = sims.DoublePendulum(dt=0.1) | ||
dt = sys_obj.dt | ||
|
||
# Calculate exponents: | ||
m = 4 | ||
deviation_scale = 1e-10 | ||
steps = 1000 | ||
part_time_steps = 15 | ||
steps_skip = 0 | ||
|
||
iterator_func = sys_obj.iterate | ||
starting_point = sys_obj.get_default_starting_pnt() | ||
|
||
le_spectrum = meas.lyapunov_exponent_spectrum( | ||
iterator_func=iterator_func, | ||
starting_point=starting_point, | ||
deviation_scale=deviation_scale, | ||
steps=steps, | ||
part_time_steps=part_time_steps, | ||
steps_skip=steps_skip, | ||
dt=dt, | ||
m=m, | ||
initial_pert_directions=None, | ||
return_convergence=True, | ||
) | ||
|
||
fig, ax = plt.subplots( | ||
1, 1, figsize=(6, 6), layout="constrained", sharex=True, sharey=False | ||
) | ||
|
||
# x and y titles: | ||
fig.supxlabel("Number of renormalization steps") | ||
fig.supylabel("Lyapunov exponent convergence") | ||
|
||
x = np.arange(1, steps + 1) | ||
ax.plot( | ||
x, | ||
le_spectrum, | ||
linewidth=1, | ||
) | ||
ax.grid(True) | ||
|
||
final_les = np.round(le_spectrum[-1, :], 4).tolist() | ||
final_les = [str(x) for x in final_les] | ||
le_string = "\n".join(final_les) | ||
le_string = "Final LEs: \n" + le_string | ||
x_position = 0.1 # X-coordinate of the upper-left corner for each subplot | ||
y_position = 0.5 | ||
ax.text( | ||
x_position, | ||
y_position, | ||
le_string, | ||
fontsize=10, | ||
bbox=dict(facecolor="white", edgecolor="black", boxstyle="round"), | ||
verticalalignment="center", | ||
horizontalalignment="left", | ||
transform=ax.transAxes, | ||
) | ||
|
||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
"""Calculate and plot the Lyapunov Spectra of all three-dimensional chaotic flows.""" | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
from lorenzpy import measures as meas | ||
from lorenzpy import simulations as sims | ||
|
||
systems = [ | ||
"Lorenz63", | ||
"Chen", | ||
"ChuaCircuit", | ||
"ComplexButterfly", | ||
"DoubleScroll", | ||
"Halvorsen", | ||
"Roessler", | ||
"Rucklidge", | ||
"Thomas", | ||
"WindmiAttractor", | ||
] | ||
|
||
# Calculate exponents: | ||
m = 3 | ||
deviation_scale = 1e-10 | ||
steps = 1000 | ||
part_time_steps = 15 | ||
steps_skip = 50 | ||
|
||
solver = "rk4" | ||
# solver = sims.solvers.create_scipy_ivp_solver(method="RK45") | ||
|
||
lyap_dict = {} | ||
for i_sys, system in enumerate(systems): | ||
print(system) | ||
sys_obj = getattr(sims, system)(solver=solver) | ||
iterator_func = sys_obj.iterate | ||
starting_point = sys_obj.get_default_starting_pnt() | ||
dt = sys_obj.dt | ||
|
||
lyap_dict[system] = meas.lyapunov_exponent_spectrum( | ||
iterator_func=iterator_func, | ||
starting_point=starting_point, | ||
deviation_scale=deviation_scale, | ||
steps=steps, | ||
part_time_steps=part_time_steps, | ||
steps_skip=steps_skip, | ||
dt=dt, | ||
m=m, | ||
initial_pert_directions=None, | ||
return_convergence=True, | ||
) | ||
|
||
fig, axs = plt.subplots( | ||
2, 5, figsize=(15, 8), layout="constrained", sharex=True, sharey=False | ||
) | ||
|
||
# x and y titles: | ||
fig.supxlabel("Number of renormalization steps") | ||
fig.supylabel("Lyapunov exponent convergence") | ||
|
||
axs = axs.flatten() | ||
x = np.arange(1, steps + 1) | ||
for i_ax, ax in enumerate(axs): | ||
system = systems[i_ax] | ||
le_spectrum = lyap_dict[system] | ||
ax.title.set_text(system) | ||
ax.plot( | ||
x, | ||
le_spectrum, | ||
linewidth=1, | ||
) | ||
ax.grid(True) | ||
|
||
final_les = np.round(le_spectrum[-1, :], 4).tolist() | ||
final_les = [str(x) for x in final_les] | ||
le_string = "\n".join(final_les) | ||
le_string = "Final LEs: \n" + le_string | ||
x_position = 0.1 # X-coordinate of the upper-left corner for each subplot | ||
y_position = 0.5 | ||
ax.text( | ||
x_position, | ||
y_position, | ||
le_string, | ||
fontsize=10, | ||
bbox=dict(facecolor="white", edgecolor="black", boxstyle="round"), | ||
verticalalignment="center", | ||
horizontalalignment="left", | ||
transform=ax.transAxes, | ||
) | ||
|
||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters