Chapter 10 · Code Snippet 10.2
The Circuit Breaker
FTSeffect 2.0 entropy engine
Reference implementation of the FTSeffect 2.0 Entropy Engine: a probabilistic model that scores velocity, sentiment, the Provenance Gap, and bot-style repetition into a single chaos score, and trips a throttling circuit breaker above 0.85.
fts_entropy_engine.py87 lines · Python
# File: fts_entropy_engine.py# Purpose: The 'Circuit Breaker' algorithm for throttling viral disinformation.## Note on variable names (FTSeffect 2.0 deconfliction):# The original FTSeffect formula (Chapter 5) reserves V = Volume,# R = Rational Deliberation, and P is unused. To avoid collisions,# the 2.0 additions use two-letter codes:# VE = Velocity (rate of spread, distinct from Volume)# RP = Repetition (bot-swarm pattern, distinct from R)# PG = Provenance Gap (share of unsigned content) import math class FTSeffectCalculator: """ The Entropy Engine (FTSeffect 2.0): a probabilistic model for detecting saturation attacks by measuring the Provenance Gap. """ def __init__(self, provenance_weight: float = 1.5, repetition_weight: float = 1.0): # provenance_weight: penalty multiplier applied when content lacks # C2PA credentials. 1.5 means unsigned content is treated as 50% # more 'chaotic' than signed content of equivalent reach. self.provenance_weight = provenance_weight self.repetition_weight = repetition_weight self.signal_buffer: list[dict] = [] def ingest_stream(self, data_packet: dict) -> None: """ Ingests a real-time social signal. Expected packet shape: { 'velocity': float, # shares per second 'sentiment': float, # 0.0 (neutral) to 1.0 (extreme rage) 'has_c2pa': bool, # True if cryptographically signed 'syntax_hash': str, # hash of normalized message text } """ self.signal_buffer.append(data_packet) def calculate_entropy_score(self) -> float: """ Returns the current chaos score in [0.0, 1.0]. A score above 0.85 should trigger the 'circuit breaker' (throttling). """ if not self.signal_buffer: return 0.0 n = len(self.signal_buffer) # 1. Velocity (VE) — the speed of the lie. avg_velocity = sum(p["velocity"] for p in self.signal_buffer) / n # 2. Sentiment polarization (the outrage factor). avg_sentiment = sum(p["sentiment"] for p in self.signal_buffer) / n # 3. Provenance Gap (PG) — the Liar's Dividend made measurable. unverified = sum(1 for p in self.signal_buffer if not p["has_c2pa"]) provenance_ratio = unverified / n provenance_penalty = provenance_ratio * self.provenance_weight # 4. Repetition (RP) — share of accounts using near-identical syntax. # A unique-syntax ratio near 0 indicates coordinated/bot behavior. unique_hashes = len({p.get("syntax_hash", id(p)) for p in self.signal_buffer}) repetition_ratio = 1 - (unique_hashes / n) repetition_penalty = repetition_ratio * self.repetition_weight # 5. Master formula (normalized, non-negative). # Logic: log(VE) * Sentiment + Provenance Penalty + Repetition Penalty raw_score = ( math.log(avg_velocity + 1) * avg_sentiment + provenance_penalty + repetition_penalty ) # Sigmoid squashes output to [0.0, 1.0]. The +3 shift calibrates the # midpoint so organic, low-velocity, signed traffic stays below 0.5. normalized_score = 1 / (1 + math.exp(-raw_score + 3)) return round(normalized_score, 4) def circuit_breaker_triggered(self, threshold: float = 0.85) -> bool: """Returns True if the platform should throttle algorithmic boost on the current signal until verification can catch up.""" return self.calculate_entropy_score() > threshold