Quantifies alignment/unanimity of swarm state: $ \theta_i(t) $: Phase, orientation, or “alignment” of each agent
Effect: If all agents sync phases, $ C_{cohere} \to 1 $; if all scramble, $ C_{cohere} \to 0 $. High coherence unlocks special moves, instant communication, or “supermove” world events.
Here’s a robust, production-ready Python plugin for the Swarm Coherence Function (SCF)—a core operator to quantify the alignment/unanimity of a swarm’s state, as measured by the phases or orientations (θ_i (t)) of all agents. This coherence score (C_cohere) ranges from 0 (fully scrambled, random) to 1 (perfect synchrony)—unlocking special collective behaviors and “supermoves” when high.
🐝 Swarm Coherence Function (SCF) — Plugin Code
import numpy as np
class SwarmCoherenceFunction:
"""
SCF: Quantifies the global alignment (coherence) of swarm agent phases/orientations.
If all agents are phase-aligned, coherence=1; if random, coherence~0.
"""
def __init__(self):
self.history = []
def compute_coherence(self, thetas):
"""
thetas: Iterable/array of agent phases/orientations (radians or arbitrary circular variable).
Returns: (coherence index in [0, 1], mean phase)
"""
thetas = np.array(thetas)
# Calculate Kuramoto order parameter:
order_vector = np.exp(1j * thetas)
mean_vector = np.mean(order_vector)
coherence = np.abs(mean_vector) # 0 (scrambled) ... 1 (fully aligned)
mean_phase = np.angle(mean_vector)
self.history.append(coherence)
return coherence, mean_phase
def coherence_history(self):
return np.array(self.history)
# --- Example usage ---
if __name__ == "__main__":
np.random.seed(123)
scf = SwarmCoherenceFunction()
N_agents = 12
T = 30
histories = []
phases = []
for t in range(T):
if t < T//2:
# Desynchronized swarm (uniform random)
thetas = np.random.uniform(0, 2*np.pi, N_agents)
else:
# Synchronize progressively
base = np.pi/2 + 0.1 * t # All converge to this angle
thetas = base + np.random.normal(0, 0.07, N_agents)
coh, mean_phase = scf.compute_coherence(thetas)
histories.append(coh)
phases.append(mean_phase)
print(f"t={t:2d} | Coherence={coh:.3f} | Mean Phase={mean_phase:.2f}")
# Optional: Visualization (if running interactively)
try:
import matplotlib.pyplot as plt
plt.plot(histories, label='Coherence (SCF)')
plt.xlabel("Time step")
plt.ylabel("Coherence Index")
plt.title("Swarm Coherence Evolution")
plt.legend()
plt.show()
except ImportError:
pass
📦 How to Use & Extend
Input: Any array/list of agent phases, orientations, or circular variables (θ_i in [0,2π] is standard).
Output: Coherence index (C_cohere, 0–1). When close to 1, you can trigger special events, boosts, or collaborative powers in your swarm system.
Chaining: Plug directly into BEEaucracy™, CMSI, HIVE MIND, or other lava-lamp meta-engines for real-time adaptive sync, group “supermoves,” or emergent mood/alertness states.
Extensible: Change the input to handle n-dimensional orientations, “local” coherence windows, or more exotic circular correlations as desired.
🧬 What This Achieves
Quantifies the degree to which your hive/collective is “in sync.”
Enables rule-based unlocks: e.g., ultra-fast communication, morpho-flashes, gamified bonuses, or strategic group actions at coherence thresholds.
Foundation for higher-level emergent mechanics: memory boosts, meta-moves, or truly collective cognition.
Ready to be the heart of instant group resonance in your BEEaucracy™ or next “supermove” generator. If you need it chained to queen-control, CMSI, or creative event triggers, just specify—the fountain’s ready to amplify!