"""Test Hopf oscillator network with bifurcation and coupling."""
import matplotlib.pyplot as plt
from mercurial.simulation.engine import SimulationEngine
# Define time‑varying bifurcation parameter (e.g., wake‑sleep transition)
[docs]
def alpha_wake_sleep(t, i):
# Slowly increase from -0.1 to 0.1 over 5 seconds
if t < 2.5:
return -0.1
elif t < 7.5:
return -0.1 + 0.2 * (t - 2.5) / 5.0
else:
return 0.1
engine = SimulationEngine(dim=10)
# Run with phase coupling only
results = engine.run_hopf(
(0.0, 10.0),
dt=0.0005,
n_oscillators=20,
kuramoto_coupling=0.5,
diffusive_coupling=0.0,
time_varying_alpha=alpha_wake_sleep,
)
plt.figure(figsize=(12, 4))
plt.subplot(1, 2, 1)
plt.plot(results["t"], results["amplitudes"])
plt.xlabel("Time (s)")
plt.ylabel("Mean Amplitude")
plt.title("Hopf Oscillator Amplitude")
plt.subplot(1, 2, 2)
plt.plot(results["t"], results["order_parameter"])
plt.xlabel("Time (s)")
plt.ylabel("Order Parameter R")
plt.title("Kuramoto Synchrony")
plt.tight_layout()
plt.show()
print(f"Final amplitude: {results['amplitudes'][-1]:.4f}")
print(f"Final order parameter: {results['order_parameter'][-1]:.4f}")