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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
ACTUAL_REALITY_MODULE_v2.py
|
| 4 |
+
|
| 5 |
+
A modeled/simulated analytical engine for studying layered governance,
|
| 6 |
+
control mechanisms, and how surface events may map to shifts in
|
| 7 |
+
decision authority and resource control.
|
| 8 |
+
|
| 9 |
+
IMPORTANT: This is a model and simulation tool. Outputs are model-derived
|
| 10 |
+
inferences based on encoded patterns and configurable heuristics, NOT
|
| 11 |
+
definitive factual claims about historical events. Use responsibly.
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
from __future__ import annotations
|
| 15 |
+
import json
|
| 16 |
+
import logging
|
| 17 |
+
from dataclasses import dataclass, field
|
| 18 |
+
from typing import Dict, Any, List, Optional, Tuple
|
| 19 |
+
import math
|
| 20 |
+
import copy
|
| 21 |
+
|
| 22 |
+
# Optional: used for DataFrame output if pandas is available
|
| 23 |
+
try:
|
| 24 |
+
import pandas as pd
|
| 25 |
+
except Exception:
|
| 26 |
+
pd = None
|
| 27 |
+
|
| 28 |
+
logger = logging.getLogger("ActualReality")
|
| 29 |
+
handler = logging.StreamHandler()
|
| 30 |
+
formatter = logging.Formatter("%(asctime)s [%(levelname)s] %(message)s")
|
| 31 |
+
handler.setFormatter(formatter)
|
| 32 |
+
logger.addHandler(handler)
|
| 33 |
+
logger.setLevel(logging.INFO)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
@dataclass
|
| 37 |
+
class ActualReality:
|
| 38 |
+
"""
|
| 39 |
+
Encodes the layered control architecture and baseline power metrics.
|
| 40 |
+
|
| 41 |
+
NOTE: All numeric values are model parameters. They can and should be
|
| 42 |
+
recalibrated against data if used for research.
|
| 43 |
+
"""
|
| 44 |
+
|
| 45 |
+
control_architecture: Dict[str, Dict[str, str]] = field(default_factory=dict)
|
| 46 |
+
power_metrics: Dict[str, Dict[str, float]] = field(default_factory=dict)
|
| 47 |
+
reality_gap: Dict[str, float] = field(default_factory=dict)
|
| 48 |
+
|
| 49 |
+
def __post_init__(self):
|
| 50 |
+
if not self.control_architecture:
|
| 51 |
+
self.control_architecture = {
|
| 52 |
+
"surface_government": {
|
| 53 |
+
"presidents": "replaceable_figureheads",
|
| 54 |
+
"congress": "theater_for_public_drama",
|
| 55 |
+
"courts": "legitimization_apparatus",
|
| 56 |
+
"elections": "controlled_opposition_cycles",
|
| 57 |
+
},
|
| 58 |
+
"permanent_government": {
|
| 59 |
+
"intelligence_community": "continuous_operations",
|
| 60 |
+
"military_industrial": "permanent_funding",
|
| 61 |
+
"central_banking": "economic_control",
|
| 62 |
+
"corporate_monopolies": "policy_enforcement",
|
| 63 |
+
},
|
| 64 |
+
"control_mechanisms": {
|
| 65 |
+
"information_warfare": "narrative_control",
|
| 66 |
+
"economic_leverage": "dependency_creation",
|
| 67 |
+
"psychological_operations": "perception_management",
|
| 68 |
+
"violence_monopoly": "ultimate_enforcement",
|
| 69 |
+
},
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
if not self.power_metrics:
|
| 73 |
+
self.power_metrics = {
|
| 74 |
+
"decision_power_distribution": {
|
| 75 |
+
"public_elections": 0.05,
|
| 76 |
+
"intelligence_directives": 0.35,
|
| 77 |
+
"corporate_policy": 0.25,
|
| 78 |
+
"financial_system": 0.20,
|
| 79 |
+
"military_industrial": 0.15,
|
| 80 |
+
},
|
| 81 |
+
"policy_origination": {
|
| 82 |
+
"public_demand": 0.08,
|
| 83 |
+
"intelligence_assessments": 0.42,
|
| 84 |
+
"corporate_lobbying": 0.32,
|
| 85 |
+
"financial_imperatives": 0.18,
|
| 86 |
+
},
|
| 87 |
+
"consequence_immunity": {
|
| 88 |
+
"elected_officials": 0.15,
|
| 89 |
+
"intelligence_operatives": 0.85,
|
| 90 |
+
"corporate_executives": 0.70,
|
| 91 |
+
"central_bankers": 0.90,
|
| 92 |
+
},
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
if not self.reality_gap:
|
| 96 |
+
self.reality_gap = {
|
| 97 |
+
"democracy_perception_gap": 0.87,
|
| 98 |
+
"freedom_illusion_index": 0.76,
|
| 99 |
+
"control_opacity_factor": 0.92,
|
| 100 |
+
"historical_amnesia_rate": 0.81,
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
def analyze_power_transfer(self, event_type: str, actor: str, target: str) -> Dict[str, Any]:
|
| 104 |
+
"""
|
| 105 |
+
High-level mapping for well-known event-types to model components.
|
| 106 |
+
|
| 107 |
+
Returns a dictionary of narrative/actual mappings as a baseline.
|
| 108 |
+
"""
|
| 109 |
+
power_analysis = {
|
| 110 |
+
"kennedy_assassination": {
|
| 111 |
+
"surface_narrative": "lone_gunman",
|
| 112 |
+
"actual_dynamics": "institutional_enforcement_of_boundaries",
|
| 113 |
+
"power_transfer": "presidential_authority -> intelligence_autonomy",
|
| 114 |
+
"precedent_set": "challenge_permanent_government -> elimination",
|
| 115 |
+
"propagation_method": "public_spectacle_with_hidden_mechanisms",
|
| 116 |
+
"verification_control": "media_narrative + official_investigation",
|
| 117 |
+
"resilience_demonstrated": "system_survived_public_scrutiny",
|
| 118 |
+
},
|
| 119 |
+
"economic_crises": {
|
| 120 |
+
"surface_narrative": "market_cycles",
|
| 121 |
+
"actual_dynamics": "controlled_resets",
|
| 122 |
+
"power_transfer": "public_wealth -> institutional_consolidation",
|
| 123 |
+
"precedent_set": "privatize_gains_socialize_losses",
|
| 124 |
+
"propagation_method": "complexity_obfuscation",
|
| 125 |
+
"verification_control": "economic_theories + expert_consensus",
|
| 126 |
+
"resilience_demonstrated": "too_big_to_fail_doctrine",
|
| 127 |
+
},
|
| 128 |
+
"pandemic_response": {
|
| 129 |
+
"surface_narrative": "public_health",
|
| 130 |
+
"actual_dynamics": "control_infrastructure_test",
|
| 131 |
+
"power_transfer": "individual_autonomy -> institutional_control",
|
| 132 |
+
"precedent_set": "emergency_powers_normalization",
|
| 133 |
+
"propagation_method": "fear_amplification + censorship",
|
| 134 |
+
"verification_control": "scientific_consensus_enforcement",
|
| 135 |
+
"resilience_demonstrated": "global_coordination_capability",
|
| 136 |
+
},
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
# Use baseline if present, else return an interpretive placeholder.
|
| 140 |
+
return power_analysis.get(event_type, {
|
| 141 |
+
"surface_narrative": "unknown",
|
| 142 |
+
"actual_dynamics": "unknown",
|
| 143 |
+
"power_transfer": "unknown",
|
| 144 |
+
"precedent_set": None,
|
| 145 |
+
"propagation_method": None,
|
| 146 |
+
"verification_control": None,
|
| 147 |
+
"resilience_demonstrated": None,
|
| 148 |
+
})
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
@dataclass
|
| 152 |
+
class ControlSystemDynamics:
|
| 153 |
+
"""
|
| 154 |
+
Encoded operational patterns of how control has been maintained historically.
|
| 155 |
+
"""
|
| 156 |
+
|
| 157 |
+
historical_patterns: Dict[str, Dict[str, Any]] = field(default_factory=dict)
|
| 158 |
+
operational_doctrine: Dict[str, Any] = field(default_factory=dict)
|
| 159 |
+
|
| 160 |
+
def __post_init__(self):
|
| 161 |
+
if not self.historical_patterns:
|
| 162 |
+
self.historical_patterns = {
|
| 163 |
+
"reformer_elimination": {
|
| 164 |
+
"success_rate": 0.94,
|
| 165 |
+
"methods": ["assassination", "character_assassination", "legal_entrapment"],
|
| 166 |
+
"detection_avoidance": "plausible_deniability + controlled_narrative",
|
| 167 |
+
"historical_examples": ["JFK", "RFK", "MLK", "Malcolm_X"],
|
| 168 |
+
},
|
| 169 |
+
"system_preservation": {
|
| 170 |
+
"success_rate": 0.98,
|
| 171 |
+
"methods": ["economic_crises", "wars", "pandemics", "terror_events"],
|
| 172 |
+
"function": "reset_public_expectations + consolidate_power",
|
| 173 |
+
"recurrence_cycle": "7-15_years",
|
| 174 |
+
},
|
| 175 |
+
"truth_suppression": {
|
| 176 |
+
"success_rate": 0.89,
|
| 177 |
+
"methods": ["classification", "media_control", "academic_gatekeeping", "social_ostracism"],
|
| 178 |
+
"vulnerability": "persistent_whistleblowers + technological_disruption",
|
| 179 |
+
"modern_challenge": "decentralized_information_propagation",
|
| 180 |
+
},
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
if not self.operational_doctrine:
|
| 184 |
+
self.operational_doctrine = {
|
| 185 |
+
"response_scale": {
|
| 186 |
+
"low": ["ignore", "discredit_source", "create_counter_narrative"],
|
| 187 |
+
"medium": ["legal_harassment", "financial_pressure", "character_assassination"],
|
| 188 |
+
"high": ["elimination", "institutional_destruction", "event_creation"],
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
def predict_system_response(self, threat_type: str, threat_level: str) -> List[str]:
|
| 193 |
+
"""
|
| 194 |
+
Predict how the control system model would respond to a given threat.
|
| 195 |
+
"""
|
| 196 |
+
matrix = {
|
| 197 |
+
"truth_revelation": {
|
| 198 |
+
"low_level": ["ignore", "discredit_source", "create_counter_narrative"],
|
| 199 |
+
"medium_level": ["legal_harassment", "financial_pressure", "character_assassination"],
|
| 200 |
+
"high_level": ["elimination", "institutional_destruction", "event_creation"],
|
| 201 |
+
},
|
| 202 |
+
"sovereign_technology": {
|
| 203 |
+
"low_level": ["patent_control", "regulatory_barriers", "acquisition"],
|
| 204 |
+
"medium_level": ["infiltration", "sabotage", "economic_warfare"],
|
| 205 |
+
"high_level": ["classification", "national_security_claim", "elimination"],
|
| 206 |
+
},
|
| 207 |
+
"mass_awakening": {
|
| 208 |
+
"low_level": ["media_distraction", "social_division", "entertainment_saturation"],
|
| 209 |
+
"medium_level": ["economic_crisis", "terror_event", "pandemic_response"],
|
| 210 |
+
"high_level": ["internet_control", "financial_reset", "martial_law_test"],
|
| 211 |
+
},
|
| 212 |
+
}
|
| 213 |
+
return matrix.get(threat_type, {}).get(threat_level, [])
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
class RealityInterface:
|
| 217 |
+
"""
|
| 218 |
+
Bridge that transforms surface events into model-derived analyses of actual dynamics.
|
| 219 |
+
"""
|
| 220 |
+
|
| 221 |
+
def __init__(self, reality: Optional[ActualReality] = None, control_dynamics: Optional[ControlSystemDynamics] = None):
|
| 222 |
+
self.actual_reality = reality if reality is not None else ActualReality()
|
| 223 |
+
self.control_dynamics = control_dynamics if control_dynamics is not None else ControlSystemDynamics()
|
| 224 |
+
|
| 225 |
+
# Tunable parameters for heuristic inference
|
| 226 |
+
self.keyword_similarity_weight = 0.6
|
| 227 |
+
self.metrics_shift_sensitivity = 0.25 # how strongly events perturb baseline metrics
|
| 228 |
+
|
| 229 |
+
# Minimal dictionary of event-to-pattern keywords for similarity scoring
|
| 230 |
+
self._event_keymap = {
|
| 231 |
+
"kennedy_assassination": ["assassination", "president", "punctuated_event", "public_spectacle"],
|
| 232 |
+
"economic_crises": ["banking", "financial", "bailout", "crash", "reset"],
|
| 233 |
+
"pandemic_response": ["disease", "lockdown", "emergency", "public_health", "vaccination"],
|
| 234 |
+
# user may supply more; it's expandable
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
# ----------------------------
|
| 238 |
+
# Core analysis implementations
|
| 239 |
+
# ----------------------------
|
| 240 |
+
def _tokenize(self, text: str) -> List[str]:
|
| 241 |
+
return [t.strip().lower() for t in text.replace("_", " ").split() if t.strip()]
|
| 242 |
+
|
| 243 |
+
def _similarity_score(self, tokens: List[str], pattern_tokens: List[str]) -> float:
|
| 244 |
+
"""
|
| 245 |
+
Simple Jaccard-like similarity for token overlap; returns score in [0,1].
|
| 246 |
+
"""
|
| 247 |
+
s = set(tokens)
|
| 248 |
+
p = set(pattern_tokens)
|
| 249 |
+
if not s and not p:
|
| 250 |
+
return 0.0
|
| 251 |
+
inter = s.intersection(p)
|
| 252 |
+
union = s.union(p)
|
| 253 |
+
return float(len(inter)) / max(1.0, len(union))
|
| 254 |
+
|
| 255 |
+
def _decode_actual_dynamics(self, event: str) -> Dict[str, Any]:
|
| 256 |
+
"""
|
| 257 |
+
Heuristic extraction of what's happening beneath a surface event.
|
| 258 |
+
|
| 259 |
+
Approach:
|
| 260 |
+
- If event is a known key (exact), return the baseline mapping from ActualReality
|
| 261 |
+
- Otherwise, try fuzzy keyword matching against internal patterns and return
|
| 262 |
+
the best-match mapping with a confidence score.
|
| 263 |
+
"""
|
| 264 |
+
event_lower = event.strip().lower()
|
| 265 |
+
baseline = self.actual_reality.analyze_power_transfer(event_lower, actor="unknown", target="unknown")
|
| 266 |
+
if baseline and baseline.get("surface_narrative") != "unknown":
|
| 267 |
+
# attach a confidence for exact-match baseline
|
| 268 |
+
baseline["inference_confidence"] = 0.85
|
| 269 |
+
baseline["matched_pattern"] = event_lower
|
| 270 |
+
return baseline
|
| 271 |
+
|
| 272 |
+
# Fallback: fuzzy match against event_keymap
|
| 273 |
+
tokens = self._tokenize(event_lower)
|
| 274 |
+
best_score = 0.0
|
| 275 |
+
best_key = None
|
| 276 |
+
for key, kws in self._event_keymap.items():
|
| 277 |
+
score = self._similarity_score(tokens, kws)
|
| 278 |
+
if score > best_score:
|
| 279 |
+
best_score = score
|
| 280 |
+
best_key = key
|
| 281 |
+
|
| 282 |
+
if best_key:
|
| 283 |
+
mapping = self.actual_reality.analyze_power_transfer(best_key, actor="unknown", target="unknown")
|
| 284 |
+
mapping["inference_confidence"] = round(self.keyword_similarity_weight * best_score + 0.15, 3)
|
| 285 |
+
mapping["matched_pattern"] = best_key
|
| 286 |
+
mapping["match_score"] = round(best_score, 3)
|
| 287 |
+
return mapping
|
| 288 |
+
|
| 289 |
+
# If nothing matches, return a reasoned default
|
| 290 |
+
return {
|
| 291 |
+
"surface_narrative": "unmapped_event",
|
| 292 |
+
"actual_dynamics": "ambiguous",
|
| 293 |
+
"power_transfer": None,
|
| 294 |
+
"precedent_set": None,
|
| 295 |
+
"propagation_method": None,
|
| 296 |
+
"verification_control": None,
|
| 297 |
+
"resilience_demonstrated": None,
|
| 298 |
+
"inference_confidence": 0.05,
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
def _calculate_power_transfer(self, event: str) -> Dict[str, float]:
|
| 302 |
+
"""
|
| 303 |
+
Quantifies how power might be redistributed as a result of 'event'
|
| 304 |
+
relative to baseline `self.actual_reality.power_metrics`.
|
| 305 |
+
|
| 306 |
+
Strategy:
|
| 307 |
+
- Identify the dominant domains implicated by the event (heuristic)
|
| 308 |
+
- Apply small perturbations to baseline distributions proportional to
|
| 309 |
+
event significance and the `metrics_shift_sensitivity`.
|
| 310 |
+
- Keep distributions normalized where appropriate.
|
| 311 |
+
"""
|
| 312 |
+
# Simple heuristic: map keywords to domains
|
| 313 |
+
domain_map = {
|
| 314 |
+
"intelligence": ["assassin", "intel", "cia", "intellegence", "intelligence"],
|
| 315 |
+
"financial": ["bank", "banking", "financial", "bailout", "economy", "crash"],
|
| 316 |
+
"public_elections": ["election", "vote", "voter", "campaign"],
|
| 317 |
+
"military": ["war", "military", "soldier", "force"],
|
| 318 |
+
"public_health": ["pandemic", "disease", "lockdown", "vaccine", "virus"],
|
| 319 |
+
"corporate_policy": ["corporate", "lobby", "merger", "acquisition"],
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
tokens = self._tokenize(event)
|
| 323 |
+
domain_scores = {k: 0.0 for k in domain_map.keys()}
|
| 324 |
+
for dom, kws in domain_map.items():
|
| 325 |
+
for kw in kws:
|
| 326 |
+
if kw in tokens:
|
| 327 |
+
domain_scores[dom] += 1.0
|
| 328 |
+
# Normalize domain scores
|
| 329 |
+
total = sum(domain_scores.values()) or 1.0
|
| 330 |
+
for k in domain_scores:
|
| 331 |
+
domain_scores[k] = domain_scores[k] / total
|
| 332 |
+
|
| 333 |
+
# Start with a copy of baseline decision distribution
|
| 334 |
+
baseline = copy.deepcopy(self.actual_reality.power_metrics.get("decision_power_distribution", {}))
|
| 335 |
+
# If baseline empty, create a uniform fallback
|
| 336 |
+
if not baseline:
|
| 337 |
+
baseline = {"public_elections": 0.2, "intelligence_directives": 0.2, "corporate_policy": 0.2, "financial_system": 0.2, "military_industrial": 0.2}
|
| 338 |
+
|
| 339 |
+
# Perturb baseline towards domains implicated
|
| 340 |
+
perturbed = {}
|
| 341 |
+
for k, v in baseline.items():
|
| 342 |
+
# Map baseline key to one of our domain buckets heuristically
|
| 343 |
+
if "intelligence" in k:
|
| 344 |
+
dom_key = "intelligence"
|
| 345 |
+
elif "financial" in k or "financial_system" in k:
|
| 346 |
+
dom_key = "financial"
|
| 347 |
+
elif "corporate" in k:
|
| 348 |
+
dom_key = "corporate_policy"
|
| 349 |
+
elif "military" in k or "military_industrial" in k:
|
| 350 |
+
dom_key = "military"
|
| 351 |
+
else:
|
| 352 |
+
dom_key = "public_elections"
|
| 353 |
+
|
| 354 |
+
# shift amount proportional to domain_scores[dom_key] and sensitivity
|
| 355 |
+
shift = (domain_scores.get(dom_key, 0.0) - 0.1) * self.metrics_shift_sensitivity
|
| 356 |
+
perturbed[k] = max(0.0, v + shift)
|
| 357 |
+
|
| 358 |
+
# Normalize perturbed so they sum to 1.0 (if baseline represented a simplex)
|
| 359 |
+
s = sum(perturbed.values())
|
| 360 |
+
if s <= 0:
|
| 361 |
+
# fall back to baseline
|
| 362 |
+
perturbed = baseline
|
| 363 |
+
s = sum(perturbed.values())
|
| 364 |
+
|
| 365 |
+
for k in perturbed:
|
| 366 |
+
perturbed[k] = round(perturbed[k] / s, 3)
|
| 367 |
+
|
| 368 |
+
return perturbed
|
| 369 |
+
|
| 370 |
+
# ----------------------------
|
| 371 |
+
# Public API
|
| 372 |
+
# ----------------------------
|
| 373 |
+
def analyze_event(self, surface_event: str) -> Dict[str, Any]:
|
| 374 |
+
"""
|
| 375 |
+
Main entry point to decode and quantify an event.
|
| 376 |
+
|
| 377 |
+
Returns:
|
| 378 |
+
{
|
| 379 |
+
"surface_event": <str>,
|
| 380 |
+
"decoded": <dict from _decode_actual_dynamics>,
|
| 381 |
+
"power_transfer": <dict of perturbed metrics>,
|
| 382 |
+
"system_response_prediction": <list of responses from ControlSystemDynamics>,
|
| 383 |
+
"vulnerabilities": <list heuristically inferred>,
|
| 384 |
+
}
|
| 385 |
+
"""
|
| 386 |
+
logger.info("Analyzing event: %s", surface_event)
|
| 387 |
+
decoded = self._decode_actual_dynamics(surface_event)
|
| 388 |
+
power_transfer = self._calculate_power_transfer(surface_event)
|
| 389 |
+
|
| 390 |
+
# Heuristic: map decoded['actual_dynamics'] to a response scenario
|
| 391 |
+
# We'll approximate threat_type by scanning decoded text
|
| 392 |
+
ad = (decoded.get("actual_dynamics") or "").lower()
|
| 393 |
+
if "control" in ad or "enforcement" in ad or "elimination" in ad:
|
| 394 |
+
threat_type = "truth_revelation"
|
| 395 |
+
level = "high_level"
|
| 396 |
+
elif "test" in ad or "infrastructure" in ad:
|
| 397 |
+
threat_type = "mass_awakening"
|
| 398 |
+
level = "medium_level"
|
| 399 |
+
else:
|
| 400 |
+
threat_type = "truth_revelation"
|
| 401 |
+
level = "low_level"
|
| 402 |
+
|
| 403 |
+
system_response = self.control_dynamics.predict_system_response(threat_type, level)
|
| 404 |
+
|
| 405 |
+
# Vulnerabilities (simple heuristic)
|
| 406 |
+
vulnerabilities = []
|
| 407 |
+
if decoded.get("inference_confidence", 0) < 0.25:
|
| 408 |
+
vulnerabilities.append("low_model_confidence_on_mapping")
|
| 409 |
+
if power_transfer.get("public_elections", 0) > 0.15:
|
| 410 |
+
vulnerabilities.append("visible_public_influence")
|
| 411 |
+
if power_transfer.get("intelligence_directives", 0) > 0.4:
|
| 412 |
+
vulnerabilities.append("intelligence_autonomy_dominant")
|
| 413 |
+
|
| 414 |
+
result = {
|
| 415 |
+
"surface_event": surface_event,
|
| 416 |
+
"decoded": decoded,
|
| 417 |
+
"power_transfer": power_transfer,
|
| 418 |
+
"system_response_prediction": system_response,
|
| 419 |
+
"vulnerabilities": vulnerabilities,
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
return result
|
| 423 |
+
|
| 424 |
+
# ----------------------------
|
| 425 |
+
# Utilities: export / display
|
| 426 |
+
# ----------------------------
|
| 427 |
+
def to_json(self, analysis: Dict[str, Any]) -> str:
|
| 428 |
+
return json.dumps(analysis, indent=2, sort_keys=False)
|
| 429 |
+
|
| 430 |
+
def to_dataframe(self, analysis: Dict[str, Any]) -> Optional["pd.DataFrame"]:
|
| 431 |
+
"""
|
| 432 |
+
Convert the most important numeric parts of analysis to a DataFrame
|
| 433 |
+
for downstream consumption. Returns None if pandas not installed.
|
| 434 |
+
"""
|
| 435 |
+
if pd is None:
|
| 436 |
+
logger.warning("pandas not available; to_dataframe will return None")
|
| 437 |
+
return None
|
| 438 |
+
|
| 439 |
+
# Flatten power_transfer and key decoded fields into a single-row DataFrame
|
| 440 |
+
row = {"surface_event": analysis.get("surface_event", "")}
|
| 441 |
+
pt = analysis.get("power_transfer", {})
|
| 442 |
+
for k, v in pt.items():
|
| 443 |
+
row[f"pt_{k}"] = v
|
| 444 |
+
decoded = analysis.get("decoded", {})
|
| 445 |
+
row["decoded_inference_confidence"] = decoded.get("inference_confidence", None)
|
| 446 |
+
row["decoded_matched_pattern"] = decoded.get("matched_pattern", None)
|
| 447 |
+
df = pd.DataFrame([row])
|
| 448 |
+
return df
|
| 449 |
+
|
| 450 |
+
# ----------------------------
|
| 451 |
+
# Simulation helpers
|
| 452 |
+
# ----------------------------
|
| 453 |
+
def simulate_event_impact(self, surface_event: str, steps: int = 3) -> Dict[str, Any]:
|
| 454 |
+
"""
|
| 455 |
+
Simulate iterative propagation of an event's impact over `steps` cycles.
|
| 456 |
+
Each step perturbs the internal reality.power_metrics (decision distribution)
|
| 457 |
+
slightly towards the event-implied distribution. Returns the trajectory.
|
| 458 |
+
"""
|
| 459 |
+
trajectory = []
|
| 460 |
+
local_metrics = copy.deepcopy(self.actual_reality.power_metrics.get("decision_power_distribution", {}))
|
| 461 |
+
if not local_metrics:
|
| 462 |
+
local_metrics = {"public_elections": 0.2, "intelligence_directives": 0.2, "corporate_policy": 0.2, "financial_system": 0.2, "military_industrial": 0.2}
|
| 463 |
+
|
| 464 |
+
target = self._calculate_power_transfer(surface_event)
|
| 465 |
+
|
| 466 |
+
for i in range(steps):
|
| 467 |
+
# simple linear interpolation towards target
|
| 468 |
+
for k in local_metrics:
|
| 469 |
+
local_metrics[k] = round(local_metrics[k] + (target.get(k, 0) - local_metrics[k]) * 0.3, 4)
|
| 470 |
+
# renormalize
|
| 471 |
+
s = sum(local_metrics.values()) or 1.0
|
| 472 |
+
for k in local_metrics:
|
| 473 |
+
local_metrics[k] = round(local_metrics[k] / s, 4)
|
| 474 |
+
trajectory.append({"step": i + 1, "metrics": copy.deepcopy(local_metrics)})
|
| 475 |
+
|
| 476 |
+
return {"event": surface_event, "trajectory": trajectory, "final_metrics": local_metrics}
|
| 477 |
+
|
| 478 |
+
|
| 479 |
+
# ----------------------------
|
| 480 |
+
# Demonstration / CLI-style run
|
| 481 |
+
# ----------------------------
|
| 482 |
+
def demonstrate_actual_reality_demo():
|
| 483 |
+
ri = RealityInterface()
|
| 484 |
+
print("ACTUAL REALITY MODULE v2 - DEMONSTRATION")
|
| 485 |
+
print("=" * 60)
|
| 486 |
+
example_events = [
|
| 487 |
+
"kennedy_assassination",
|
| 488 |
+
"global_banking_crash bailout",
|
| 489 |
+
"novel_virus_lockdown vaccination campaign",
|
| 490 |
+
"small_local_election upset",
|
| 491 |
+
]
|
| 492 |
+
|
| 493 |
+
for ev in example_events:
|
| 494 |
+
analysis = ri.analyze_event(ev)
|
| 495 |
+
print("\n>> Surface event:", ev)
|
| 496 |
+
print("Decoded (short):", analysis["decoded"].get("actual_dynamics"))
|
| 497 |
+
print("Inference confidence:", analysis["decoded"].get("inference_confidence"))
|
| 498 |
+
print("Power transfer snapshot:")
|
| 499 |
+
for k, v in analysis["power_transfer"].items():
|
| 500 |
+
print(f" {k}: {v:.0%}")
|
| 501 |
+
print("Predicted system response:", ", ".join(analysis["system_response_prediction"]) or "none")
|
| 502 |
+
# Show simulation trajectory for the event
|
| 503 |
+
sim = ri.simulate_event_impact(ev, steps=3)
|
| 504 |
+
print("Simulated metric trajectory (final):")
|
| 505 |
+
for k, v in sim["final_metrics"].items():
|
| 506 |
+
print(f" {k}: {v:.0%}")
|
| 507 |
+
|
| 508 |
+
# Example: export one as JSON & DataFrame (if pandas available)
|
| 509 |
+
ev = "novel_virus_lockdown vaccination campaign"
|
| 510 |
+
analysis = ri.analyze_event(ev)
|
| 511 |
+
print("\nJSON export (excerpt):")
|
| 512 |
+
print(ri.to_json({k: analysis[k] for k in ["surface_event", "decoded", "power_transfer"]}))
|
| 513 |
+
|
| 514 |
+
df = ri.to_dataframe(analysis)
|
| 515 |
+
if df is not None:
|
| 516 |
+
print("\nPandas DataFrame preview:")
|
| 517 |
+
print(df.to_string(index=False))
|
| 518 |
+
|
| 519 |
+
|
| 520 |
+
if __name__ == "__main__":
|
| 521 |
+
demonstrate_actual_reality_demo()
|