"""Test Jansen‑Rit neural mass model with noise and time‑varying input."""
import matplotlib.pyplot as plt
import numpy as np
from mercurial.simulation.engine import SimulationEngine
engine = SimulationEngine(dim=10)
results = engine.run_jansen_rit(
(0.0, 2.0), dt=0.0005, n_columns=1, coupling_strength=0.0, external_input=pulsed_input
)
# Plot
plt.figure(figsize=(12, 4))
plt.plot(results["t"], results["EEG"])
plt.xlabel("Time (s)")
plt.ylabel("EEG (mV)")
plt.title("Jansen‑Rit Column Output (with noise and pulsed input)")
plt.grid(True, alpha=0.3)
plt.show()
print(f"Final EEG: {results['final_EEG']:.4f} mV")
# Compute standard deviation only if enough points exist
eeg_data = results["EEG"]
if len(eeg_data) > 1:
# Use the second half of the data to avoid initial transient
half = len(eeg_data) // 2
eeg_std = np.std(eeg_data[half:])
print(f"EEG std (second half): {eeg_std:.4f}")
else:
print("Not enough data points to compute standard deviation.")