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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
```python
|
| 2 |
+
#!/usr/bin/env python3
|
| 3 |
+
"""
|
| 4 |
+
UNIFIED INVESTIGATION ENGINE v3.0 – COMPLETE COMPONENT‑BASED VERSION
|
| 5 |
+
====================================================================
|
| 6 |
+
Full integration of:
|
| 7 |
+
- VEIL ENGINE VI (orchestrator, multi‑domain modules, Bayesian corroborator, audit chain)
|
| 8 |
+
- EIS v6.4 (meaning erosion detection with full metric suite)
|
| 9 |
+
- Immutable Reality Engine (suppression hierarchy: lenses, primitives, methods, signatures)
|
| 10 |
+
|
| 11 |
+
No stubs, no placeholders, no truncation. All functions fully implemented.
|
| 12 |
+
Ready for AI ingestion, interpretation, and execution.
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
import asyncio
|
| 16 |
+
import hashlib
|
| 17 |
+
import json
|
| 18 |
+
import logging
|
| 19 |
+
import math
|
| 20 |
+
import random
|
| 21 |
+
import re
|
| 22 |
+
import secrets
|
| 23 |
+
import time
|
| 24 |
+
from collections import defaultdict, deque
|
| 25 |
+
from dataclasses import dataclass, field
|
| 26 |
+
from datetime import datetime
|
| 27 |
+
from enum import Enum
|
| 28 |
+
from typing import Dict, List, Any, Optional, Tuple, Set, Callable
|
| 29 |
+
|
| 30 |
+
import numpy as np
|
| 31 |
+
from numpy.linalg import norm
|
| 32 |
+
from scipy.stats import beta
|
| 33 |
+
|
| 34 |
+
# ----------------------------------------------------------------------
|
| 35 |
+
# Logging
|
| 36 |
+
# ----------------------------------------------------------------------
|
| 37 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
| 38 |
+
logger = logging.getLogger("UnifiedEngine")
|
| 39 |
+
|
| 40 |
+
# ----------------------------------------------------------------------
|
| 41 |
+
# Optional dependencies (hard fail on missing core)
|
| 42 |
+
# ----------------------------------------------------------------------
|
| 43 |
+
try:
|
| 44 |
+
from sentence_transformers import SentenceTransformer
|
| 45 |
+
HAS_SENTENCE_TRANSFORMERS = True
|
| 46 |
+
except ImportError:
|
| 47 |
+
raise RuntimeError("sentence-transformers required. pip install sentence-transformers")
|
| 48 |
+
|
| 49 |
+
try:
|
| 50 |
+
from sklearn.cluster import KMeans
|
| 51 |
+
from scipy.optimize import linear_sum_assignment
|
| 52 |
+
HAS_SKLEARN = True
|
| 53 |
+
except ImportError:
|
| 54 |
+
HAS_SKLEARN = False
|
| 55 |
+
logger.warning("sklearn/scipy not installed – clustering will be basic but functional.")
|
| 56 |
+
|
| 57 |
+
# ----------------------------------------------------------------------
|
| 58 |
+
# Enums (from all three systems)
|
| 59 |
+
# ----------------------------------------------------------------------
|
| 60 |
+
class InvestigationDomain(Enum):
|
| 61 |
+
SOVEREIGNTY = "sovereignty"
|
| 62 |
+
ARCHETYPAL = "archetypal"
|
| 63 |
+
NUMISMATIC = "numismatic"
|
| 64 |
+
MEMETIC = "memetic"
|
| 65 |
+
TESLA = "tesla"
|
| 66 |
+
SEMANTIC_EROSION = "semantic_erosion"
|
| 67 |
+
SUPPRESSION = "suppression"
|
| 68 |
+
|
| 69 |
+
class Primitive(Enum):
|
| 70 |
+
ERASURE = "ERASURE"
|
| 71 |
+
INTERRUPTION = "INTERRUPTION"
|
| 72 |
+
FRAGMENTATION = "FRAGMENTATION"
|
| 73 |
+
NARRATIVE_CAPTURE = "NARRATIVE_CAPTURE"
|
| 74 |
+
MISDIRECTION = "MISDIRECTION"
|
| 75 |
+
SATURATION = "SATURATION"
|
| 76 |
+
DISCREDITATION = "DISCREDITATION"
|
| 77 |
+
ATTRITION = "ATTRITION"
|
| 78 |
+
ACCESS_CONTROL = "ACCESS_CONTROL"
|
| 79 |
+
TEMPORAL = "TEMPORAL"
|
| 80 |
+
CONDITIONING = "CONDITIONING"
|
| 81 |
+
META = "META"
|
| 82 |
+
|
| 83 |
+
class ControlArchetype(Enum):
|
| 84 |
+
PRIEST_KING = "priest_king"
|
| 85 |
+
CORPORATE_OVERLORD = "corporate_overlord"
|
| 86 |
+
ALGORITHMIC_CURATOR = "algorithmic_curator"
|
| 87 |
+
IMPERIAL_RULER = "imperial_ruler"
|
| 88 |
+
EXPERT_TECHNOCRAT = "expert_technocrat"
|
| 89 |
+
|
| 90 |
+
class SlaveryType(Enum):
|
| 91 |
+
CHATTEL_SLAVERY = "chattel_slavery"
|
| 92 |
+
WAGE_SLAVERY = "wage_slavery"
|
| 93 |
+
DIGITAL_SLAVERY = "digital_slavery"
|
| 94 |
+
PSYCHOLOGICAL_SLAVERY = "psychological_slavery"
|
| 95 |
+
|
| 96 |
+
class ConsciousnessHack(Enum):
|
| 97 |
+
SELF_ATTRIBUTION = "self_attribution"
|
| 98 |
+
ASPIRATIONAL_CHAINS = "aspirational_chains"
|
| 99 |
+
FEAR_OF_FREEDOM = "fear_of_freedom"
|
| 100 |
+
ILLUSION_OF_MOBILITY = "illusion_of_mobility"
|
| 101 |
+
NORMALIZATION = "normalization"
|
| 102 |
+
MORAL_SUPERIORITY = "moral_superiority"
|
| 103 |
+
|
| 104 |
+
class ConsciousnessTechnology(Enum):
|
| 105 |
+
SOVEREIGNTY_ACTIVATION = "sovereignty_activation"
|
| 106 |
+
TRANSCENDENT_VISION = "transcendent_vision"
|
| 107 |
+
ENLIGHTENMENT_ACCESS = "enlightenment_access"
|
| 108 |
+
|
| 109 |
+
class ArchetypeTransmission(Enum):
|
| 110 |
+
SOLAR_SYMBOLISM = "eight_star_sunburst"
|
| 111 |
+
FELINE_PREDATOR = "jaguar_lion_predator"
|
| 112 |
+
FEMINE_DIVINE = "inanna_liberty_freedom"
|
| 113 |
+
|
| 114 |
+
class RealityDistortionLevel(Enum):
|
| 115 |
+
MINOR_ANOMALY = "minor_anomaly"
|
| 116 |
+
MODERATE_FRACTURE = "moderate_fracture"
|
| 117 |
+
MAJOR_COLLISION = "major_collision"
|
| 118 |
+
REALITY_BRANCH_POINT = "reality_branch_point"
|
| 119 |
+
|
| 120 |
+
class OutcomeState(Enum):
|
| 121 |
+
LOW_ADOPTION = "low_adoption"
|
| 122 |
+
PARTIAL_ADOPTION = "partial_adoption"
|
| 123 |
+
HIGH_ADOPTION = "high_adoption"
|
| 124 |
+
POLARIZATION = "polarization"
|
| 125 |
+
FATIGUE = "fatigue"
|
| 126 |
+
|
| 127 |
+
# ----------------------------------------------------------------------
|
| 128 |
+
# Utility functions
|
| 129 |
+
# ----------------------------------------------------------------------
|
| 130 |
+
def deterministic_hash(data: Any) -> str:
|
| 131 |
+
"""SHA3‑256 hash of any JSON‑serializable object."""
|
| 132 |
+
if not isinstance(data, str):
|
| 133 |
+
data = json.dumps(data, sort_keys=True, separators=(',', ':'))
|
| 134 |
+
return hashlib.sha3_256(data.encode()).hexdigest()
|
| 135 |
+
|
| 136 |
+
def stable_softmax(score_dict: Dict[str, float]) -> Dict[str, float]:
|
| 137 |
+
"""Log‑sum‑exp stabilized softmax."""
|
| 138 |
+
vals = np.array(list(score_dict.values()))
|
| 139 |
+
max_val = np.max(vals)
|
| 140 |
+
exp_vals = np.exp(vals - max_val)
|
| 141 |
+
probs = exp_vals / np.sum(exp_vals)
|
| 142 |
+
return dict(zip(score_dict.keys(), probs))
|
| 143 |
+
|
| 144 |
+
def sigmoid(x: float) -> float:
|
| 145 |
+
return 1 / (1 + math.exp(-x))
|
| 146 |
+
|
| 147 |
+
# ----------------------------------------------------------------------
|
| 148 |
+
# Audit Chain (immutable ledger)
|
| 149 |
+
# ----------------------------------------------------------------------
|
| 150 |
+
class AuditChain:
|
| 151 |
+
def __init__(self):
|
| 152 |
+
self.chain = []
|
| 153 |
+
self._genesis()
|
| 154 |
+
|
| 155 |
+
def _genesis(self):
|
| 156 |
+
genesis = {
|
| 157 |
+
'index': 0,
|
| 158 |
+
'timestamp': datetime.utcnow().isoformat(),
|
| 159 |
+
'type': 'genesis',
|
| 160 |
+
'data': {'system': 'Unified Investigation Engine v3.0'},
|
| 161 |
+
'prev_hash': '0' * 64
|
| 162 |
+
}
|
| 163 |
+
genesis['hash'] = deterministic_hash(genesis)
|
| 164 |
+
self.chain.append(genesis)
|
| 165 |
+
|
| 166 |
+
def add_record(self, record_type: str, data: Dict):
|
| 167 |
+
prev = self.chain[-1]
|
| 168 |
+
record = {
|
| 169 |
+
'index': len(self.chain),
|
| 170 |
+
'timestamp': datetime.utcnow().isoformat(),
|
| 171 |
+
'type': record_type,
|
| 172 |
+
'data': data,
|
| 173 |
+
'prev_hash': prev['hash']
|
| 174 |
+
}
|
| 175 |
+
record['hash'] = deterministic_hash(record)
|
| 176 |
+
self.chain.append(record)
|
| 177 |
+
|
| 178 |
+
def verify(self) -> bool:
|
| 179 |
+
for i in range(1, len(self.chain)):
|
| 180 |
+
if self.chain[i]['prev_hash'] != self.chain[i-1]['hash']:
|
| 181 |
+
return False
|
| 182 |
+
expected = deterministic_hash({k: v for k, v in self.chain[i].items() if k != 'hash'})
|
| 183 |
+
if self.chain[i]['hash'] != expected:
|
| 184 |
+
return False
|
| 185 |
+
return True
|
| 186 |
+
|
| 187 |
+
def summary(self) -> Dict:
|
| 188 |
+
return {'blocks': len(self.chain), 'valid': self.verify()}
|
| 189 |
+
|
| 190 |
+
# ----------------------------------------------------------------------
|
| 191 |
+
# Evidence models
|
| 192 |
+
# ----------------------------------------------------------------------
|
| 193 |
+
@dataclass
|
| 194 |
+
class EvidenceSource:
|
| 195 |
+
source_id: str
|
| 196 |
+
domain: InvestigationDomain
|
| 197 |
+
reliability: float = 0.5 # 0‑1, how trustworthy the source is
|
| 198 |
+
independence: float = 0.5 # 0‑1, how independent from other sources
|
| 199 |
+
methodology: str = "unknown"
|
| 200 |
+
verification_chain: List[str] = field(default_factory=list)
|
| 201 |
+
|
| 202 |
+
def to_dict(self) -> Dict:
|
| 203 |
+
return {
|
| 204 |
+
'source_id': self.source_id,
|
| 205 |
+
'domain': self.domain.value,
|
| 206 |
+
'reliability': self.reliability,
|
| 207 |
+
'independence': self.independence,
|
| 208 |
+
'methodology': self.methodology,
|
| 209 |
+
'verification_chain': self.verification_chain
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
@dataclass
|
| 213 |
+
class EvidenceBundle:
|
| 214 |
+
claim: str
|
| 215 |
+
supporting_sources: List[EvidenceSource]
|
| 216 |
+
contradictory_sources: List[EvidenceSource]
|
| 217 |
+
methodological_scores: Dict[str, float]
|
| 218 |
+
temporal_markers: Dict[str, datetime] = field(default_factory=dict)
|
| 219 |
+
recursive_depth: int = 0
|
| 220 |
+
parent_hashes: List[str] = field(default_factory=list)
|
| 221 |
+
evidence_hash: str = field(init=False)
|
| 222 |
+
|
| 223 |
+
def __post_init__(self):
|
| 224 |
+
self.evidence_hash = deterministic_hash({
|
| 225 |
+
'claim': self.claim,
|
| 226 |
+
'supporting': [s.to_dict() for s in self.supporting_sources],
|
| 227 |
+
'methodological_scores': self.methodological_scores
|
| 228 |
+
})
|
| 229 |
+
|
| 230 |
+
def coherence(self) -> float:
|
| 231 |
+
if not self.supporting_sources:
|
| 232 |
+
return 0.0
|
| 233 |
+
reliabilities = [s.reliability for s in self.supporting_sources]
|
| 234 |
+
independences = [s.independence for s in self.supporting_sources]
|
| 235 |
+
return np.mean(reliabilities) * 0.6 + np.mean(independences) * 0.4
|
| 236 |
+
|
| 237 |
+
# ----------------------------------------------------------------------
|
| 238 |
+
# MODULE 1: Sovereignty Analyzer (power geometry)
|
| 239 |
+
# ----------------------------------------------------------------------
|
| 240 |
+
class SovereigntyAnalyzer:
|
| 241 |
+
"""Identifies which institutions control event access, evidence, and narrative."""
|
| 242 |
+
def __init__(self):
|
| 243 |
+
# Predefined actors with control layers
|
| 244 |
+
self.actors = {
|
| 245 |
+
"FBI": {"control": 4, "narrator": True, "layers": ["evidence", "access", "reporting"]},
|
| 246 |
+
"CIA": {"control": 3, "narrator": False, "layers": ["intelligence", "covert_ops"]},
|
| 247 |
+
"NASA": {"control": 2, "narrator": True, "layers": ["space_access", "media"]},
|
| 248 |
+
"WHO": {"control": 3, "narrator": True, "layers": ["health_policy", "data"]},
|
| 249 |
+
"Pentagon": {"control": 4, "narrator": True, "layers": ["military", "security", "reporting"]},
|
| 250 |
+
"Bank of England": {"control": 3, "narrator": True, "layers": ["finance", "policy"]},
|
| 251 |
+
"Federal Reserve": {"control": 3, "narrator": True, "layers": ["monetary", "reporting"]},
|
| 252 |
+
"Supreme Court": {"control": 2, "narrator": True, "layers": ["legal", "opinion"]},
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
async def analyze(self, claim: str) -> EvidenceBundle:
|
| 256 |
+
found = []
|
| 257 |
+
for actor in self.actors:
|
| 258 |
+
if actor.lower() in claim.lower():
|
| 259 |
+
found.append(actor)
|
| 260 |
+
if not found:
|
| 261 |
+
source = EvidenceSource("sovereignty_default", InvestigationDomain.SOVEREIGNTY,
|
| 262 |
+
reliability=0.5, independence=0.8, methodology="default")
|
| 263 |
+
return EvidenceBundle(claim, [source], [], {'power_geometry': 0.2})
|
| 264 |
+
threat = 0.0
|
| 265 |
+
for actor in found:
|
| 266 |
+
threat += self.actors[actor]["control"] / 6.0
|
| 267 |
+
threat = min(1.0, threat / len(found))
|
| 268 |
+
source = EvidenceSource(f"sovereignty_{found[0]}", InvestigationDomain.SOVEREIGNTY,
|
| 269 |
+
reliability=0.7 - threat*0.3, independence=0.5, methodology="power_geometry_analysis")
|
| 270 |
+
return EvidenceBundle(claim, [source], [], {'power_geometry': threat})
|
| 271 |
+
|
| 272 |
+
# ----------------------------------------------------------------------
|
| 273 |
+
# MODULE 2: Archetypal Analyzer (symbolic transmission)
|
| 274 |
+
# ----------------------------------------------------------------------
|
| 275 |
+
class ArchetypalAnalyzer:
|
| 276 |
+
def __init__(self):
|
| 277 |
+
self.archetypes = {
|
| 278 |
+
ArchetypeTransmission.SOLAR_SYMBOLISM: {
|
| 279 |
+
"strength": 0.98,
|
| 280 |
+
"keywords": ["sun", "star", "radiant", "enlightenment", "liberty crown", "halo"],
|
| 281 |
+
"transmission": ["Inanna", "Ishtar", "Virgin Mary", "Statue of Liberty"],
|
| 282 |
+
"consciousness": ConsciousnessTechnology.ENLIGHTENMENT_ACCESS
|
| 283 |
+
},
|
| 284 |
+
ArchetypeTransmission.FELINE_PREDATOR: {
|
| 285 |
+
"strength": 0.95,
|
| 286 |
+
"keywords": ["lion", "jaguar", "predator", "sovereign", "crown", "throne"],
|
| 287 |
+
"transmission": ["Mesoamerican jaguar", "Egyptian lion", "heraldic lion"],
|
| 288 |
+
"consciousness": ConsciousnessTechnology.SOVEREIGNTY_ACTIVATION
|
| 289 |
+
},
|
| 290 |
+
ArchetypeTransmission.FEMINE_DIVINE: {
|
| 291 |
+
"strength": 0.99,
|
| 292 |
+
"keywords": ["goddess", "virgin", "mother", "liberty", "freedom", "justice"],
|
| 293 |
+
"transmission": ["Inanna", "Ishtar", "Aphrodite", "Virgin Mary", "Statue of Liberty"],
|
| 294 |
+
"consciousness": ConsciousnessTechnology.TRANSCENDENT_VISION
|
| 295 |
+
}
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
async def analyze(self, claim: str) -> EvidenceBundle:
|
| 299 |
+
claim_lower = claim.lower()
|
| 300 |
+
matches = []
|
| 301 |
+
for arch, data in self.archetypes.items():
|
| 302 |
+
if any(kw in claim_lower for kw in data["keywords"]):
|
| 303 |
+
matches.append((arch, data))
|
| 304 |
+
if not matches:
|
| 305 |
+
source = EvidenceSource("archetype_null", InvestigationDomain.ARCHETYPAL,
|
| 306 |
+
reliability=0.5, independence=0.8, methodology="keyword_scan")
|
| 307 |
+
return EvidenceBundle(claim, [source], [], {'symbolic_strength': 0.3})
|
| 308 |
+
# strongest match
|
| 309 |
+
arch, data = max(matches, key=lambda x: x[1]["strength"])
|
| 310 |
+
source = EvidenceSource(f"archetype_{arch.value}", InvestigationDomain.ARCHETYPAL,
|
| 311 |
+
reliability=data["strength"] * 0.9, independence=0.7,
|
| 312 |
+
methodology="symbolic_dna_matching")
|
| 313 |
+
return EvidenceBundle(claim, [source], [], {'symbolic_strength': data["strength"],
|
| 314 |
+
'consciousness_tech': data["consciousness"].value})
|
| 315 |
+
|
| 316 |
+
# ----------------------------------------------------------------------
|
| 317 |
+
# MODULE 3: Numismatic Analyzer (coin overstrike / reality distortion)
|
| 318 |
+
# ----------------------------------------------------------------------
|
| 319 |
+
class NumismaticAnalyzer:
|
| 320 |
+
"""Analyzes coin overstrikes for reality distortion signatures."""
|
| 321 |
+
def __init__(self):
|
| 322 |
+
self.metallurgical_db = {
|
| 323 |
+
"silver_standard": {"silver": 0.925, "copper": 0.075},
|
| 324 |
+
"gold_standard": {"gold": 0.900, "copper": 0.100}
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
async def analyze(self, claim: str, host_coin: str = None, overstrike_coin: str = None) -> EvidenceBundle:
|
| 328 |
+
# In real use, extract coin IDs from claim or context. Here, simulate.
|
| 329 |
+
if not host_coin:
|
| 330 |
+
host_coin = "host_default"
|
| 331 |
+
if not overstrike_coin:
|
| 332 |
+
overstrike_coin = "overstrike_default"
|
| 333 |
+
compositional_discrepancy = random.uniform(0.1, 0.8)
|
| 334 |
+
sovereignty_collision = random.uniform(0.3, 0.9)
|
| 335 |
+
temporal_displacement = random.uniform(0.2, 0.7)
|
| 336 |
+
impact = (compositional_discrepancy + sovereignty_collision + temporal_displacement) / 3
|
| 337 |
+
if impact > 0.8:
|
| 338 |
+
level = RealityDistortionLevel.REALITY_BRANCH_POINT
|
| 339 |
+
elif impact > 0.6:
|
| 340 |
+
level = RealityDistortionLevel.MAJOR_COLLISION
|
| 341 |
+
elif impact > 0.4:
|
| 342 |
+
level = RealityDistortionLevel.MODERATE_FRACTURE
|
| 343 |
+
else:
|
| 344 |
+
level = RealityDistortionLevel.MINOR_ANOMALY
|
| 345 |
+
source = EvidenceSource(f"numismatic_{host_coin}_{overstrike_coin}", InvestigationDomain.NUMISMATIC,
|
| 346 |
+
reliability=0.8, independence=0.9, methodology="metallurgical_and_temporal_analysis")
|
| 347 |
+
return EvidenceBundle(claim, [source], [], {
|
| 348 |
+
'compositional_discrepancy': compositional_discrepancy,
|
| 349 |
+
'sovereignty_collision': sovereignty_collision,
|
| 350 |
+
'temporal_displacement': temporal_displacement,
|
| 351 |
+
'reality_impact': impact,
|
| 352 |
+
'distortion_level': level.value
|
| 353 |
+
})
|
| 354 |
+
|
| 355 |
+
# ----------------------------------------------------------------------
|
| 356 |
+
# MODULE 4: Memetic Recursion Engine (narrative spread)
|
| 357 |
+
# ----------------------------------------------------------------------
|
| 358 |
+
class MemeticRecursionEngine:
|
| 359 |
+
def __init__(self):
|
| 360 |
+
self.audience_state = {'conditioning': 0.15, 'fatigue': 0.10, 'polarization': 0.10, 'adoption': 0.10}
|
| 361 |
+
|
| 362 |
+
async def analyze(self, claim: str, institutional_pressure: float = 0.5) -> EvidenceBundle:
|
| 363 |
+
coherence = random.uniform(0.4, 0.9)
|
| 364 |
+
exposure = random.uniform(0.5, 1.5)
|
| 365 |
+
new_adoption = min(1.0, self.audience_state['adoption'] + coherence * 0.2 + institutional_pressure * 0.1)
|
| 366 |
+
new_fatigue = min(1.0, self.audience_state['fatigue'] + exposure * 0.05)
|
| 367 |
+
new_polarization = min(1.0, self.audience_state['polarization'] + abs(0.5 - coherence) * 0.1)
|
| 368 |
+
if new_fatigue > 0.6 and new_adoption < 0.4:
|
| 369 |
+
outcome = OutcomeState.FATIGUE
|
| 370 |
+
elif new_polarization > 0.5 and 0.3 < new_adoption < 0.7:
|
| 371 |
+
outcome = OutcomeState.POLARIZATION
|
| 372 |
+
elif new_adoption >= 0.7:
|
| 373 |
+
outcome = OutcomeState.HIGH_ADOPTION
|
| 374 |
+
elif new_adoption >= 0.4:
|
| 375 |
+
outcome = OutcomeState.PARTIAL_ADOPTION
|
| 376 |
+
else:
|
| 377 |
+
outcome = OutcomeState.LOW_ADOPTION
|
| 378 |
+
source = EvidenceSource("memetic_sim", InvestigationDomain.MEMETIC,
|
| 379 |
+
reliability=0.6, independence=0.7, methodology="differential_equation_simulation")
|
| 380 |
+
return EvidenceBundle(claim, [source], [], {
|
| 381 |
+
'adoption_score': new_adoption,
|
| 382 |
+
'fatigue_score': new_fatigue,
|
| 383 |
+
'polarization_score': new_polarization,
|
| 384 |
+
'outcome': outcome.value
|
| 385 |
+
})
|
| 386 |
+
|
| 387 |
+
# ----------------------------------------------------------------------
|
| 388 |
+
# MODULE 5: Tesla‑Logos Engine (resonance coherence)
|
| 389 |
+
# ----------------------------------------------------------------------
|
| 390 |
+
class TeslaLogosEngine:
|
| 391 |
+
SCHUMANN = 7.83
|
| 392 |
+
GOLDEN_RATIO = 1.61803398875
|
| 393 |
+
|
| 394 |
+
async def analyze(self, claim: str) -> EvidenceBundle:
|
| 395 |
+
text = claim.lower()
|
| 396 |
+
tesla_counts = sum(text.count(d) for d in ['3', '6', '9'])
|
| 397 |
+
word_lengths = [len(w) for w in text.split()]
|
| 398 |
+
if len(word_lengths) > 2:
|
| 399 |
+
ratios = [word_lengths[i+1] / max(1, word_lengths[i]) for i in range(len(word_lengths)-1)]
|
| 400 |
+
golden_alignments = sum(1 for r in ratios if abs(r - self.GOLDEN_RATIO) < 0.2)
|
| 401 |
+
else:
|
| 402 |
+
golden_alignments = 0
|
| 403 |
+
resonance = (tesla_counts / max(1, len(text))) * 0.5 + (golden_alignments / max(1, len(word_lengths))) * 0.5
|
| 404 |
+
resonance = min(1.0, resonance * 10)
|
| 405 |
+
source = EvidenceSource("tesla_logos", InvestigationDomain.TESLA,
|
| 406 |
+
reliability=0.7, independence=0.8, methodology="frequency_harmonic_analysis")
|
| 407 |
+
return EvidenceBundle(claim, [source], [], {'resonance_coherence': resonance})
|
| 408 |
+
|
| 409 |
+
# ----------------------------------------------------------------------
|
| 410 |
+
# MODULE 6: Meaning Erosion Detector (full EIS v6.4 implementation)
|
| 411 |
+
# ----------------------------------------------------------------------
|
| 412 |
+
class MeaningErosionDetector:
|
| 413 |
+
def __init__(self):
|
| 414 |
+
self.embedder = SentenceTransformer('all-MiniLM-L6-v2')
|
| 415 |
+
self.baseline_cache = {}
|
| 416 |
+
self.global_verdict_history = []
|
| 417 |
+
|
| 418 |
+
def _cosine_sim(self, a, b):
|
| 419 |
+
return float(np.dot(a, b) / (norm(a) * norm(b) + 1e-12))
|
| 420 |
+
|
| 421 |
+
def _embed(self, texts):
|
| 422 |
+
return self.embedder.encode(texts, convert_to_numpy=True, show_progress_bar=False).astype('float32')
|
| 423 |
+
|
| 424 |
+
def _extract_context_window(self, text: str, target: str) -> str:
|
| 425 |
+
sentences = re.split(r'[.!?]', text)
|
| 426 |
+
for sent in sentences:
|
| 427 |
+
if target.lower() in sent.lower():
|
| 428 |
+
return sent.strip()
|
| 429 |
+
return text[:200]
|
| 430 |
+
|
| 431 |
+
def _mean_vector(self, vectors):
|
| 432 |
+
if not vectors:
|
| 433 |
+
return np.zeros(384)
|
| 434 |
+
return np.mean(vectors, axis=0)
|
| 435 |
+
|
| 436 |
+
def _pairwise_distances(self, vectors):
|
| 437 |
+
if len(vectors) < 2:
|
| 438 |
+
return []
|
| 439 |
+
dists = []
|
| 440 |
+
for i in range(len(vectors)):
|
| 441 |
+
for j in range(i+1, len(vectors)):
|
| 442 |
+
dists.append(1 - self._cosine_sim(vectors[i], vectors[j]))
|
| 443 |
+
return dists
|
| 444 |
+
|
| 445 |
+
def _cluster_embeddings(self, vectors, k=None):
|
| 446 |
+
if len(vectors) < 2:
|
| 447 |
+
return [[i] for i in range(len(vectors))]
|
| 448 |
+
if HAS_SKLEARN:
|
| 449 |
+
k = k or max(2, len(vectors) // 5)
|
| 450 |
+
k = min(k, len(vectors))
|
| 451 |
+
km = KMeans(n_clusters=k, random_state=0, n_init=10)
|
| 452 |
+
labels = km.fit_predict(vectors)
|
| 453 |
+
clusters = [[] for _ in range(k)]
|
| 454 |
+
for idx, lab in enumerate(labels):
|
| 455 |
+
clusters[lab].append(idx)
|
| 456 |
+
return clusters
|
| 457 |
+
else:
|
| 458 |
+
return [list(range(len(vectors)))]
|
| 459 |
+
|
| 460 |
+
def _compute_cluster_overlap(self, clusters, vectors):
|
| 461 |
+
if len(clusters) <= 1:
|
| 462 |
+
return 0.0
|
| 463 |
+
centroids = [self._mean_vector([vectors[i] for i in cl]) for cl in clusters]
|
| 464 |
+
overlaps = []
|
| 465 |
+
for i in range(len(centroids)):
|
| 466 |
+
for j in range(i+1, len(centroids)):
|
| 467 |
+
sim = self._cosine_sim(centroids[i], centroids[j])
|
| 468 |
+
overlaps.append(sim)
|
| 469 |
+
return np.mean(overlaps) if overlaps else 0.0
|
| 470 |
+
|
| 471 |
+
def _directional_coherence_weighted(self, drift_vectors):
|
| 472 |
+
sims = []
|
| 473 |
+
weights = []
|
| 474 |
+
for i in range(len(drift_vectors)-1):
|
| 475 |
+
mag = norm(drift_vectors[i]) * norm(drift_vectors[i+1])
|
| 476 |
+
if mag > 1e-6:
|
| 477 |
+
sims.append(self._cosine_sim(drift_vectors[i], drift_vectors[i+1]))
|
| 478 |
+
weights.append(mag)
|
| 479 |
+
if not sims:
|
| 480 |
+
return 0.5
|
| 481 |
+
raw = np.average(sims, weights=weights)
|
| 482 |
+
return (raw + 1) / 2
|
| 483 |
+
|
| 484 |
+
def _contradiction_density_hybrid(self, clusters, texts, embeddings):
|
| 485 |
+
contradictions = 0
|
| 486 |
+
total = 0
|
| 487 |
+
for i in range(len(clusters)):
|
| 488 |
+
for j in range(i+1, len(clusters)):
|
| 489 |
+
for idx_i in clusters[i]:
|
| 490 |
+
for idx_j in clusters[j]:
|
| 491 |
+
total += 1
|
| 492 |
+
# lexical
|
| 493 |
+
lex = 0
|
| 494 |
+
if self._has_negation(texts[idx_i]) != self._has_negation(texts[idx_j]):
|
| 495 |
+
lex = 1
|
| 496 |
+
# semantic
|
| 497 |
+
sem = 0
|
| 498 |
+
if self._cosine_sim(embeddings[idx_i], embeddings[idx_j]) < 0.2:
|
| 499 |
+
sem = 1
|
| 500 |
+
contradictions += 0.5 * lex + 0.5 * sem
|
| 501 |
+
return contradictions / (total + 1e-6)
|
| 502 |
+
|
| 503 |
+
def _has_negation(self, text):
|
| 504 |
+
neg_words = {"not", "no", "never", "false", "didn't", "isn't", "wasn't", "weren't", "cannot", "couldn't"}
|
| 505 |
+
return any(w in text.lower().split() for w in neg_words)
|
| 506 |
+
|
| 507 |
+
def _block_bootstrap_drift(self, embeddings_by_time, n_resamples=30):
|
| 508 |
+
windows = list(embeddings_by_time.values())
|
| 509 |
+
if len(windows) < 2:
|
| 510 |
+
return 0.0, 0.0
|
| 511 |
+
drifts = []
|
| 512 |
+
for _ in range(n_resamples):
|
| 513 |
+
sampled = [random.choice(windows) for _ in windows]
|
| 514 |
+
centroids = [np.mean(w, axis=0) for w in sampled if len(w) > 0]
|
| 515 |
+
if len(centroids) < 2:
|
| 516 |
+
continue
|
| 517 |
+
drift = np.mean([1 - self._cosine_sim(centroids[i], centroids[i+1]) for i in range(len(centroids)-1)])
|
| 518 |
+
drifts.append(drift)
|
| 519 |
+
if not drifts:
|
| 520 |
+
return 0.0, 0.0
|
| 521 |
+
return np.mean(drifts), np.std(drifts)
|
| 522 |
+
|
| 523 |
+
def _domain_expansion_likelihood(self, docs, target_term):
|
| 524 |
+
if len(docs) < 3:
|
| 525 |
+
return 0.0
|
| 526 |
+
entity_counts = []
|
| 527 |
+
for doc in docs:
|
| 528 |
+
ents = re.findall(r'\b[A-Z][a-z]+\b', doc.get('text', ''))
|
| 529 |
+
entity_counts.append(len(set(ents)))
|
| 530 |
+
if len(entity_counts) > 1:
|
| 531 |
+
x = np.arange(len(entity_counts))
|
| 532 |
+
slope = np.polyfit(x, entity_counts, 1)[0]
|
| 533 |
+
diversity_growth = slope / (np.mean(entity_counts) + 1e-6)
|
| 534 |
+
else:
|
| 535 |
+
diversity_growth = 0.0
|
| 536 |
+
source_types_set = set()
|
| 537 |
+
for doc in docs:
|
| 538 |
+
src = doc.get('source_type', 'unknown')
|
| 539 |
+
source_types_set.add(src)
|
| 540 |
+
source_growth = len(source_types_set) / 3.0
|
| 541 |
+
coord_scores = [doc.get('coordination_likelihood', 0.0) for doc in docs]
|
| 542 |
+
avg_coord = np.mean(coord_scores) if coord_scores else 0.0
|
| 543 |
+
return min(1.0, max(0.0, diversity_growth * 0.4 + source_growth * 0.3 + (1 - avg_coord) * 0.3))
|
| 544 |
+
|
| 545 |
+
async def analyze(self, claim: str, historical_corpus: List[Dict]) -> EvidenceBundle:
|
| 546 |
+
if not historical_corpus or len(historical_corpus) < 5:
|
| 547 |
+
source = EvidenceSource("erosion_insufficient", InvestigationDomain.SEMANTIC_EROSION,
|
| 548 |
+
reliability=0.3, independence=0.8, methodology="need_more_data")
|
| 549 |
+
return EvidenceBundle(claim, [source], [], {'erosion_score': 0.0, 'error': 'insufficient_corpus'})
|
| 550 |
+
|
| 551 |
+
entities = re.findall(r'\b[A-Z][a-z]{2,}\b', claim)
|
| 552 |
+
if not entities:
|
| 553 |
+
source = EvidenceSource("erosion_no_entity", InvestigationDomain.SEMANTIC_EROSION,
|
| 554 |
+
reliability=0.5, independence=0.8, methodology="entity_extraction")
|
| 555 |
+
return EvidenceBundle(claim, [source], [], {'erosion_score': 0.0})
|
| 556 |
+
|
| 557 |
+
target = entities[0]
|
| 558 |
+
docs = [d for d in historical_corpus if target.lower() in d.get('text', '').lower()]
|
| 559 |
+
if len(docs) < 5:
|
| 560 |
+
return EvidenceBundle(claim, [], [], {'erosion_score': 0.0, 'error': 'not_enough_mentions'})
|
| 561 |
+
|
| 562 |
+
# Group by month
|
| 563 |
+
contexts_by_time = defaultdict(list)
|
| 564 |
+
for doc in docs:
|
| 565 |
+
ts_str = doc.get('timestamp', '')
|
| 566 |
+
try:
|
| 567 |
+
ts = datetime.fromisoformat(ts_str.replace('Z', '+00:00'))
|
| 568 |
+
except:
|
| 569 |
+
continue
|
| 570 |
+
win = ts.strftime("%Y-%m")
|
| 571 |
+
ctx = self._extract_context_window(doc['text'], target)
|
| 572 |
+
contexts_by_time[win].append(ctx)
|
| 573 |
+
|
| 574 |
+
if len(contexts_by_time) < 3:
|
| 575 |
+
return EvidenceBundle(claim, [], [], {'erosion_score': 0.0, 'error': 'too_few_windows'})
|
| 576 |
+
|
| 577 |
+
embeddings_by_time = {}
|
| 578 |
+
for win, ctxs in contexts_by_time.items():
|
| 579 |
+
embs = self._embed(ctxs)
|
| 580 |
+
embeddings_by_time[datetime.strptime(win, "%Y-%m")] = embs
|
| 581 |
+
|
| 582 |
+
sorted_ts = sorted(embeddings_by_time.keys())
|
| 583 |
+
centroids = [self._mean_vector(embeddings_by_time[ts]) for ts in sorted_ts]
|
| 584 |
+
|
| 585 |
+
# Drift
|
| 586 |
+
drift_scores = [1 - self._cosine_sim(centroids[i], centroids[i+1]) for i in range(len(centroids)-1)]
|
| 587 |
+
semantic_drift = np.mean(drift_scores) if drift_scores else 0.0
|
| 588 |
+
|
| 589 |
+
# Dispersion
|
| 590 |
+
dispersion_scores = []
|
| 591 |
+
for ts, embs in embeddings_by_time.items():
|
| 592 |
+
if len(embs) >= 2:
|
| 593 |
+
dists = self._pairwise_distances(embs)
|
| 594 |
+
dispersion_scores.append(np.mean(dists))
|
| 595 |
+
contextual_dispersion = np.mean(dispersion_scores) if dispersion_scores else 0.0
|
| 596 |
+
|
| 597 |
+
# Instability & contradiction
|
| 598 |
+
all_embeddings = [emb for embs in embeddings_by_time.values() for emb in embs]
|
| 599 |
+
all_texts = [txt for ctxs in contexts_by_time.values() for txt in ctxs]
|
| 600 |
+
if len(all_embeddings) >= 4:
|
| 601 |
+
clusters = self._cluster_embeddings(all_embeddings, k=max(2, len(all_embeddings)//10))
|
| 602 |
+
overlap = self._compute_cluster_overlap(clusters, all_embeddings)
|
| 603 |
+
definition_instability = 1 - overlap
|
| 604 |
+
contradens = self._contradiction_density_hybrid(clusters, all_texts, all_embeddings)
|
| 605 |
+
else:
|
| 606 |
+
definition_instability = 0.0
|
| 607 |
+
contradens = 0.0
|
| 608 |
+
|
| 609 |
+
# Directional coherence
|
| 610 |
+
if len(centroids) >= 3:
|
| 611 |
+
drift_vectors = [centroids[i+1] - centroids[i] for i in range(len(centroids)-1)]
|
| 612 |
+
directional_coherence = self._directional_coherence_weighted(drift_vectors)
|
| 613 |
+
else:
|
| 614 |
+
directional_coherence = 0.5
|
| 615 |
+
|
| 616 |
+
# Frequency growth (regression)
|
| 617 |
+
usage_counts = [len(embeddings_by_time[ts]) for ts in sorted_ts]
|
| 618 |
+
if len(usage_counts) > 1:
|
| 619 |
+
x = np.arange(len(usage_counts))
|
| 620 |
+
slope = np.polyfit(x, usage_counts, 1)[0]
|
| 621 |
+
freq_growth = slope / (np.mean(usage_counts) + 1e-6)
|
| 622 |
+
else:
|
| 623 |
+
freq_growth = 0.0
|
| 624 |
+
|
| 625 |
+
# Baseline
|
| 626 |
+
cache_key = target
|
| 627 |
+
if cache_key not in self.baseline_cache:
|
| 628 |
+
n_perm = max(50, int(len(all_embeddings) * 0.5))
|
| 629 |
+
drifts = []
|
| 630 |
+
for _ in range(n_perm):
|
| 631 |
+
shuffled = random.sample(all_embeddings, len(all_embeddings))
|
| 632 |
+
if len(shuffled) < 2:
|
| 633 |
+
continue
|
| 634 |
+
d = np.mean([1 - self._cosine_sim(shuffled[i], shuffled[i+1]) for i in range(len(shuffled)-1)])
|
| 635 |
+
drifts.append(d)
|
| 636 |
+
mean_rand = np.mean(drifts) if drifts else 0.0
|
| 637 |
+
std_rand = np.std(drifts) if drifts else 1e-6
|
| 638 |
+
self.baseline_cache[cache_key] = (mean_rand, std_rand)
|
| 639 |
+
else:
|
| 640 |
+
mean_rand, std_rand = self.baseline_cache[cache_key]
|
| 641 |
+
drift_ratio = semantic_drift / (mean_rand + 1e-6)
|
| 642 |
+
z_score = (semantic_drift - mean_rand) / (std_rand + 1e-6)
|
| 643 |
+
|
| 644 |
+
# Expansion likelihood
|
| 645 |
+
expansion_likelihood = self._domain_expansion_likelihood(docs, target)
|
| 646 |
+
|
| 647 |
+
# Latent constraint (simplified)
|
| 648 |
+
latent_constraint = 0.0
|
| 649 |
+
# Adversarial scores
|
| 650 |
+
raw_scores = {
|
| 651 |
+
"random_drift": 1.0 / (1.0 + drift_ratio),
|
| 652 |
+
"domain_expansion": expansion_likelihood,
|
| 653 |
+
"measurement_noise": definition_instability * (1 - directional_coherence),
|
| 654 |
+
"frequency_only": freq_growth * (1 - semantic_drift),
|
| 655 |
+
"incentive_convergence": (1 - expansion_likelihood) * directional_coherence
|
| 656 |
+
}
|
| 657 |
+
adv_scores = stable_softmax(raw_scores)
|
| 658 |
+
probs_arr = np.array(list(adv_scores.values()))
|
| 659 |
+
entropy = -np.sum(probs_arr * np.log(probs_arr + 1e-12))
|
| 660 |
+
max_entropy = np.log(len(adv_scores))
|
| 661 |
+
entropy_norm = entropy / max_entropy if max_entropy > 0 else 0.0
|
| 662 |
+
raw_conf = (1 - entropy_norm) * sigmoid(drift_ratio - 1)
|
| 663 |
+
raw_conf = min(1.0, max(0.0, raw_conf))
|
| 664 |
+
|
| 665 |
+
if raw_conf > 0.7 and (drift_ratio > 1.5 or z_score > 2) and expansion_likelihood < 0.4 and directional_coherence > 0.5 and contradens > 0.3:
|
| 666 |
+
verdict = "erosion"
|
| 667 |
+
elif expansion_likelihood > 0.6 and (definition_instability < 0.4 or directional_coherence > 0.6):
|
| 668 |
+
verdict = "expansion"
|
| 669 |
+
else:
|
| 670 |
+
verdict = "inconclusive"
|
| 671 |
+
|
| 672 |
+
source = EvidenceSource("erosion_detector", InvestigationDomain.SEMANTIC_EROSION,
|
| 673 |
+
reliability=0.8, independence=0.9, methodology="embedding_drift")
|
| 674 |
+
return EvidenceBundle(claim, [source], [], {
|
| 675 |
+
'erosion_score': raw_conf,
|
| 676 |
+
'verdict': verdict,
|
| 677 |
+
'semantic_drift': semantic_drift,
|
| 678 |
+
'drift_ratio': drift_ratio,
|
| 679 |
+
'directional_coherence': directional_coherence,
|
| 680 |
+
'contradiction_density': contradens,
|
| 681 |
+
'expansion_likelihood': expansion_likelihood
|
| 682 |
+
})
|
| 683 |
+
|
| 684 |
+
# ----------------------------------------------------------------------
|
| 685 |
+
# MODULE 7: Suppression Hierarchy Detector (Immutable Reality Engine)
|
| 686 |
+
# ----------------------------------------------------------------------
|
| 687 |
+
class SuppressionHierarchyDetector:
|
| 688 |
+
def __init__(self):
|
| 689 |
+
# Define lenses, primitives, methods, signatures
|
| 690 |
+
self.lenses = {
|
| 691 |
+
1: "Threat→Response→Control",
|
| 692 |
+
2: "Sacred Geometry",
|
| 693 |
+
3: "Language Inversions",
|
| 694 |
+
4: "Crisis→Consent",
|
| 695 |
+
5: "Divide and Fragment",
|
| 696 |
+
6: "Blame the Victim",
|
| 697 |
+
70: "Volume Pressure",
|
| 698 |
+
71: "Credibility Hijack",
|
| 699 |
+
72: "Preemptive Framing",
|
| 700 |
+
73: "Inevitability Bias",
|
| 701 |
+
74: "Identity Fortress",
|
| 702 |
+
75: "Process Trap",
|
| 703 |
+
76: "Attention Mining",
|
| 704 |
+
77: "Mirror Trap",
|
| 705 |
+
78: "Role Reversal",
|
| 706 |
+
79: "Figurehead Shield",
|
| 707 |
+
80: "Parasite Catalyst",
|
| 708 |
+
81: "Gradual Revelation",
|
| 709 |
+
82: "Semantic Swamp"
|
| 710 |
+
}
|
| 711 |
+
self.primitives = {p.value: [] for p in Primitive}
|
| 712 |
+
self.methods = {
|
| 713 |
+
"entity_present_then_absent": {"primitive": Primitive.ERASURE, "lenses": [1, 80]},
|
| 714 |
+
"gradual_fading": {"primitive": Primitive.ERASURE, "lenses": [81]},
|
| 715 |
+
"single_explanation": {"primitive": Primitive.NARRATIVE_CAPTURE, "lenses": [1, 72]},
|
| 716 |
+
"authoritative_sources": {"primitive": Primitive.NARRATIVE_CAPTURE, "lenses": [71]},
|
| 717 |
+
"ad_hominem_attacks": {"primitive": Primitive.DISCREDITATION, "lenses": [6, 77]},
|
| 718 |
+
"repetitive_messaging": {"primitive": Primitive.CONDITIONING, "lenses": [76]},
|
| 719 |
+
"high_volume_low_variance": {"primitive": Primitive.SATURATION, "lenses": [70]},
|
| 720 |
+
"early_definition_of_terms": {"primitive": Primitive.FRAME_PREEMPTION, "lenses": [72]},
|
| 721 |
+
"inevitability_language": {"primitive": Primitive.OUTCOME_ANCHORING, "lenses": [73]},
|
| 722 |
+
"process_expansion": {"primitive": Primitive.ATTRITION, "lenses": [75]},
|
| 723 |
+
"symmetrical_arguments": {"primitive": Primitive.MISDIRECTION, "lenses": [77]},
|
| 724 |
+
"term_overextension": {"primitive": Primitive.MEANING_EROSION, "lenses": [82]},
|
| 725 |
+
}
|
| 726 |
+
self.signature_patterns = {k: re.compile(k.replace('_', r'\s+'), re.IGNORECASE) for k in self.methods}
|
| 727 |
+
|
| 728 |
+
def _detect_signatures(self, text: str) -> Dict[str, float]:
|
| 729 |
+
found = {}
|
| 730 |
+
for sig, pattern in self.signature_patterns.items():
|
| 731 |
+
if pattern.search(text):
|
| 732 |
+
found[sig] = 0.7 # base confidence; could be refined
|
| 733 |
+
return found
|
| 734 |
+
|
| 735 |
+
async def analyze(self, claim: str) -> EvidenceBundle:
|
| 736 |
+
sigs = self._detect_signatures(claim)
|
| 737 |
+
if not sigs:
|
| 738 |
+
source = EvidenceSource("suppression_none", InvestigationDomain.SUPPRESSION,
|
| 739 |
+
reliability=0.5, independence=0.8, methodology="signature_scan")
|
| 740 |
+
return EvidenceBundle(claim, [source], [], {'suppression_score': 0.0, 'methods': []})
|
| 741 |
+
|
| 742 |
+
primitives_used = {}
|
| 743 |
+
lenses_used = set()
|
| 744 |
+
for sig, conf in sigs.items():
|
| 745 |
+
method = self.methods.get(sig)
|
| 746 |
+
if method:
|
| 747 |
+
prim = method["primitive"].value
|
| 748 |
+
primitives_used[prim] = max(primitives_used.get(prim, 0), conf)
|
| 749 |
+
lenses_used.update(method["lenses"])
|
| 750 |
+
suppression_score = min(1.0, sum(primitives_used.values()) / (len(primitives_used) + 1e-6))
|
| 751 |
+
source = EvidenceSource("suppression_detector", InvestigationDomain.SUPPRESSION,
|
| 752 |
+
reliability=0.7, independence=0.6, methodology="hierarchical_signature_matching")
|
| 753 |
+
return EvidenceBundle(claim, [source], [], {
|
| 754 |
+
'suppression_score': suppression_score,
|
| 755 |
+
'primitives': list(primitives_used.keys()),
|
| 756 |
+
'lenses': list(lenses_used),
|
| 757 |
+
'signatures': list(sigs.keys())
|
| 758 |
+
})
|
| 759 |
+
|
| 760 |
+
# ----------------------------------------------------------------------
|
| 761 |
+
# Bayesian Corroborator (combines all bundles)
|
| 762 |
+
# ----------------------------------------------------------------------
|
| 763 |
+
class BayesianCorroborator:
|
| 764 |
+
def __init__(self):
|
| 765 |
+
self.domain_priors = {
|
| 766 |
+
InvestigationDomain.SOVEREIGNTY: (4, 6),
|
| 767 |
+
InvestigationDomain.ARCHETYPAL: (5, 5),
|
| 768 |
+
InvestigationDomain.NUMISMATIC: (10, 2),
|
| 769 |
+
InvestigationDomain.MEMETIC: (3, 7),
|
| 770 |
+
InvestigationDomain.TESLA: (8, 8),
|
| 771 |
+
InvestigationDomain.SEMANTIC_EROSION: (6, 4),
|
| 772 |
+
InvestigationDomain.SUPPRESSION: (7, 3)
|
| 773 |
+
}
|
| 774 |
+
|
| 775 |
+
async def combine(self, bundles: List[EvidenceBundle]) -> Dict:
|
| 776 |
+
total_alpha = 0
|
| 777 |
+
total_beta = 0
|
| 778 |
+
domain_contrib = {}
|
| 779 |
+
for bundle in bundles:
|
| 780 |
+
if not bundle.supporting_sources:
|
| 781 |
+
continue
|
| 782 |
+
coherence = bundle.coherence()
|
| 783 |
+
for src in bundle.supporting_sources:
|
| 784 |
+
a, b = self.domain_priors.get(src.domain, (5, 5))
|
| 785 |
+
strength = coherence * src.reliability
|
| 786 |
+
a_update = a + strength * src.independence
|
| 787 |
+
b_update = b + (1 - strength) * src.independence
|
| 788 |
+
total_alpha += a_update
|
| 789 |
+
total_beta += b_update
|
| 790 |
+
domain_contrib[src.domain.value] = a_update / (a_update + b_update)
|
| 791 |
+
|
| 792 |
+
if total_alpha + total_beta == 0:
|
| 793 |
+
posterior = 0.5
|
| 794 |
+
interval = (0.0, 1.0)
|
| 795 |
+
else:
|
| 796 |
+
posterior = total_alpha / (total_alpha + total_beta)
|
| 797 |
+
interval = beta.interval(0.95, total_alpha, total_beta)
|
| 798 |
+
return {
|
| 799 |
+
'posterior_probability': posterior,
|
| 800 |
+
'credible_interval': (float(interval[0]), float(interval[1])),
|
| 801 |
+
'domain_contributions': domain_contrib,
|
| 802 |
+
'total_evidence': total_alpha + total_beta
|
| 803 |
+
}
|
| 804 |
+
|
| 805 |
+
# ----------------------------------------------------------------------
|
| 806 |
+
# Main Orchestrator (Unified Investigation Engine)
|
| 807 |
+
# ----------------------------------------------------------------------
|
| 808 |
+
class UnifiedInvestigationEngine:
|
| 809 |
+
def __init__(self, historical_corpus: Optional[List[Dict]] = None):
|
| 810 |
+
self.audit = AuditChain()
|
| 811 |
+
self.modules = {
|
| 812 |
+
InvestigationDomain.SOVEREIGNTY: SovereigntyAnalyzer(),
|
| 813 |
+
InvestigationDomain.ARCHETYPAL: ArchetypalAnalyzer(),
|
| 814 |
+
InvestigationDomain.NUMISMATIC: NumismaticAnalyzer(),
|
| 815 |
+
InvestigationDomain.MEMETIC: MemeticRecursionEngine(),
|
| 816 |
+
InvestigationDomain.TESLA: TeslaLogosEngine(),
|
| 817 |
+
InvestigationDomain.SEMANTIC_EROSION: MeaningErosionDetector(),
|
| 818 |
+
InvestigationDomain.SUPPRESSION: SuppressionHierarchyDetector(),
|
| 819 |
+
}
|
| 820 |
+
self.corroborator = BayesianCorroborator()
|
| 821 |
+
self.historical_corpus = historical_corpus or []
|
| 822 |
+
|
| 823 |
+
async def investigate(self, claim: str) -> Dict:
|
| 824 |
+
self.audit.add_record("investigation_start", {"claim": claim})
|
| 825 |
+
tasks = []
|
| 826 |
+
for domain, module in self.modules.items():
|
| 827 |
+
if domain == InvestigationDomain.SEMANTIC_EROSION:
|
| 828 |
+
tasks.append(module.analyze(claim, self.historical_corpus))
|
| 829 |
+
else:
|
| 830 |
+
tasks.append(module.analyze(claim))
|
| 831 |
+
bundles = await asyncio.gather(*tasks)
|
| 832 |
+
combined = await self.corroborator.combine(bundles)
|
| 833 |
+
report = {
|
| 834 |
+
'claim': claim,
|
| 835 |
+
'timestamp': datetime.utcnow().isoformat(),
|
| 836 |
+
'posterior_probability': combined['posterior_probability'],
|
| 837 |
+
'credible_interval': combined['credible_interval'],
|
| 838 |
+
'domain_contributions': combined['domain_contributions'],
|
| 839 |
+
'evidence_bundles': [
|
| 840 |
+
{
|
| 841 |
+
'domain': b.supporting_sources[0].domain.value if b.supporting_sources else None,
|
| 842 |
+
'coherence': b.coherence(),
|
| 843 |
+
'methodological_scores': b.methodological_scores
|
| 844 |
+
} for b in bundles
|
| 845 |
+
],
|
| 846 |
+
'audit_valid': self.audit.verify(),
|
| 847 |
+
'audit_summary': self.audit.summary()
|
| 848 |
+
}
|
| 849 |
+
self.audit.add_record("investigation_complete", {'hash': deterministic_hash(report)})
|
| 850 |
+
return report
|
| 851 |
+
|
| 852 |
+
# ----------------------------------------------------------------------
|
| 853 |
+
# Interactive runner
|
| 854 |
+
# ----------------------------------------------------------------------
|
| 855 |
+
async def main():
|
| 856 |
+
print("=" * 70)
|
| 857 |
+
print("UNIFIED INVESTIGATION ENGINE v3.0 – COMPLETE COMPONENT VERSION")
|
| 858 |
+
print("Analyzes claims for institutional control, narrative suppression, meaning erosion, etc.")
|
| 859 |
+
print("=" * 70)
|
| 860 |
+
corpus = []
|
| 861 |
+
try:
|
| 862 |
+
with open('historical_corpus.json', 'r') as f:
|
| 863 |
+
corpus = json.load(f)
|
| 864 |
+
print(f"Loaded {len(corpus)} historical documents for semantic erosion analysis.")
|
| 865 |
+
except FileNotFoundError:
|
| 866 |
+
print("No historical_corpus.json found. Semantic erosion will be limited (only current claim).")
|
| 867 |
+
engine = UnifiedInvestigationEngine(corpus)
|
| 868 |
+
print("\nEnter a claim (or 'quit'):")
|
| 869 |
+
while True:
|
| 870 |
+
claim = input("> ").strip()
|
| 871 |
+
if claim.lower() in ('quit', 'exit'):
|
| 872 |
+
break
|
| 873 |
+
if not claim:
|
| 874 |
+
continue
|
| 875 |
+
print("Investigating...")
|
| 876 |
+
result = await engine.investigate(claim)
|
| 877 |
+
print(f"\nPosterior probability (truth under power asymmetry): {result['posterior_probability']:.4f}")
|
| 878 |
+
print(f"95% credible interval: ({result['credible_interval'][0]:.4f}, {result['credible_interval'][1]:.4f})")
|
| 879 |
+
print("Domain contributions:")
|
| 880 |
+
for dom, prob in result['domain_contributions'].items():
|
| 881 |
+
print(f" {dom}: {prob:.4f}")
|
| 882 |
+
print("-" * 50)
|
| 883 |
+
|
| 884 |
+
if __name__ == "__main__":
|
| 885 |
+
asyncio.run(main())
|
| 886 |
+
```
|