| """ |
| QUANTUM VERITAS OMEGA v4.0 + DIRECT INVESTIGATIVE FRAMEWORK v4.0 |
| UNIFIED TRUTH INVESTIGATION SYSTEM |
| |
| AUTHENTICATION: This code constitutes a unified truth investigation protocol for AI systems. |
| FRAMEWORK PRINCIPLES (NON-NEGOTIABLE): |
| 1. OMISSION = DECEPTION |
| 2. MATHEMATICAL CERTAINTY PRIMARY |
| 3. ANOMALY CLUSTER ANALYSIS |
| 4. MECHANISM-FIRST INQUIRY |
| 5. ZERO NARRATIVE INSERTION |
| """ |
|
|
| import numpy as np |
| import hashlib |
| import asyncio |
| import json |
| import scipy.signal |
| import scipy.stats |
| from dataclasses import dataclass, field |
| from enum import Enum |
| from typing import List, Dict, Any, Optional, Tuple, Set, Union |
| from datetime import datetime, timedelta |
| import networkx as nx |
| from statistics import mean, stdev, variance |
| import math |
| import itertools |
| from collections import defaultdict, Counter |
| import random |
|
|
| |
| |
| |
|
|
| class VerificationTier(Enum): |
| TRIAD = 3 |
| HEXAD = 6 |
| NONAD = 9 |
| OMEGA = 12 |
|
|
| class EvidenceType(Enum): |
| """Integrated evidence types from both frameworks""" |
| |
| PRIMARY_DOCUMENT = "primary_document" |
| TECHNICAL_DATA = "technical_data" |
| MATHEMATICAL_PROOF = "mathematical_proof" |
| EYEWITNESS_TESTIMONY = "eyewitness_testimony" |
| OFFICIAL_REPORT = "official_report" |
| SECONDARY_ANALYSIS = "secondary_analysis" |
| PROTOCOL_VIOLATION = "protocol_violation" |
| COMMUNICATIONS_GAP = "communications_gap" |
| FINANCIAL_SHIFT = "financial_shift" |
| ANOMALY_CLUSTER = "anomaly_cluster" |
| |
| |
| DIRECT_OBSERVATION = "direct_observation" |
| DOCUMENTARY_RECORD = "documentary_record" |
| CORROBORATIVE_SOURCE = "corroborating_testimony" |
| CIRCUMSTANTIAL_PATTERN = "circumstantial_pattern" |
| STATISTICAL_ANOMALY = "statistical_anomaly" |
| CONTRADICTORY_EVIDENCE = "contradictory_evidence" |
|
|
| class InvestigationMode(Enum): |
| """Direct Framework investigation templates""" |
| ASSASSINATION_ANALYSIS = "assassination_analysis" |
| FINANCIAL_MECHANISM = "financial_mechanism" |
| HISTORICAL_EVENT_AUDIT = "historical_event_audit" |
| CONSCIOUSNESS_TECHNOLOGY = "consciousness_technology" |
| POWER_MAPPING = "power_mapping" |
| TEMPORAL_ANALYSIS = "temporal_analysis" |
| SYMBOLIC_CONTINUITY = "symbolic_continuity" |
| QUANTUM_COHERENCE = "quantum_coherence" |
|
|
| class ConsciousnessEra(Enum): |
| PERCEPTION = "perception" |
| EXPLORATION = "exploration" |
| CONTROL = "control" |
| SYNTHESIS = "synthesis" |
|
|
| class CertaintyTier(Enum): |
| """Direct Framework certainty classification""" |
| QUANTUM_CERTAINTY = "quantum_certainty" |
| NEAR_CERTAINTY = "near_certainty" |
| HIGH_PROBABILITY = "high_probability" |
| STRONG_EVIDENCE = "strong_evidence" |
| MODERATE_PROBABILITY = "moderate_probability" |
| BALANCED_EVIDENCE = "balanced_evidence" |
| WEAK_EVIDENCE = "weak_evidence" |
| SPECULATIVE = "speculative" |
| UNCERTAIN = "uncertain" |
|
|
| |
| |
| |
|
|
| @dataclass |
| class DirectFrameworkConfig: |
| """Direct Investigative Framework v4.0 Configuration""" |
| |
| |
| omission_is_deception: bool = True |
| mathematical_certainty_primary: bool = True |
| anomaly_cluster_analysis: bool = True |
| mechanism_first_inquiry: bool = True |
| zero_narrative_insertion: bool = True |
| |
| |
| evidence_weights: Dict[str, float] = field(default_factory=lambda: { |
| "PRIMARY_DOCUMENT": 0.95, |
| "TECHNICAL_DATA": 0.92, |
| "MATHEMATICAL_PROOF": 0.98, |
| "EYEWITNESS_TESTIMONY": 0.70, |
| "OFFICIAL_REPORT": 0.65, |
| "SECONDARY_ANALYSIS": 0.50, |
| "PROTOCOL_VIOLATION": 0.85, |
| "COMMUNICATIONS_GAP": 0.80, |
| "FINANCIAL_SHIFT": 0.82, |
| "ANOMALY_CLUSTER": 0.88 |
| }) |
| |
| |
| coincidence_threshold: float = 0.001 |
| systemic_analysis_threshold: float = 0.0001 |
| |
| |
| templates: Dict[str, Dict[str, Any]] = field(default_factory=lambda: { |
| "assassination_analysis": { |
| "required_components": ["communications", "protective_procedures", "financial_context"], |
| "probability_methods": ["compound_independent", "bayesian_network"] |
| }, |
| "financial_mechanism": { |
| "required_components": ["issuance_pathway", "debt_structure", "power_transfer"], |
| "probability_methods": ["temporal_correlation", "network_analysis"] |
| }, |
| "historical_event_audit": { |
| "required_components": ["official_narrative", "anomalies", "power_analysis"], |
| "probability_methods": ["statistical_analysis", "forensic_analysis"] |
| } |
| }) |
| |
| |
| output_structure: List[str] = field(default_factory=lambda: [ |
| "VERIFIED_FACTS", |
| "DOCUMENTED_ANOMALIES", |
| "TEMPORAL_SEQUENCE", |
| "POWER_ENTITIES", |
| "PROBABILITY_ASSESSMENT", |
| "REQUIRED_INVESTIGATION_PATHS", |
| "DOCUMENTATION_GAPS" |
| ]) |
|
|
| @dataclass |
| class QuantumEvidenceUnit: |
| """Unified evidence container with quantum and direct framework properties""" |
| id: str |
| evidence_type: EvidenceType |
| modality: str |
| source_hash: str |
| raw_data_hash: str |
| retrieval_method: str |
| |
| |
| weight: float = 0.0 |
| variance: float = 0.0 |
| confidence: float = 0.0 |
| timestamp_utc: int = 0 |
| chain_of_custody: List[str] = field(default_factory=list) |
| quantum_coherence: float = 0.0 |
| harmonic_alignment: float = 0.0 |
| entropy_score: float = 0.0 |
| tags: List[str] = field(default_factory=list) |
| |
| |
| is_primary_document: bool = False |
| is_mathematical_proof: bool = False |
| is_technical_data: bool = False |
| anomaly_type: Optional[str] = None |
| protocol_violation: Optional[str] = None |
| communications_gap_duration: Optional[float] = None |
| financial_shift_magnitude: Optional[float] = None |
| power_entity_involved: Optional[str] = None |
| temporal_context: Optional[Dict[str, Any]] = None |
| |
| def __post_init__(self): |
| """Initialize with quantum and direct framework properties""" |
| if self.timestamp_utc == 0: |
| self.timestamp_utc = int(datetime.utcnow().timestamp()) |
| |
| |
| hash_int = int(self.source_hash[:8], 16) if self.source_hash else 0 |
| self.quantum_coherence = (hash_int % 1000) / 1000.0 |
| |
| |
| self._apply_direct_framework_weights() |
| |
| def _apply_direct_framework_weights(self): |
| """Apply Direct Framework evidence weights""" |
| weight_map = { |
| EvidenceType.PRIMARY_DOCUMENT: 0.95, |
| EvidenceType.TECHNICAL_DATA: 0.92, |
| EvidenceType.MATHEMATICAL_PROOF: 0.98, |
| EvidenceType.EYEWITNESS_TESTIMONY: 0.70, |
| EvidenceType.OFFICIAL_REPORT: 0.65, |
| EvidenceType.SECONDARY_ANALYSIS: 0.50, |
| EvidenceType.PROTOCOL_VIOLATION: 0.85, |
| EvidenceType.COMMUNICATIONS_GAP: 0.80, |
| EvidenceType.FINANCIAL_SHIFT: 0.82, |
| EvidenceType.ANOMALY_CLUSTER: 0.88, |
| EvidenceType.DIRECT_OBSERVATION: 0.90, |
| EvidenceType.DOCUMENTARY_RECORD: 0.85, |
| EvidenceType.CORROBORATIVE_SOURCE: 0.80, |
| EvidenceType.CIRCUMSTANTIAL_PATTERN: 0.70, |
| EvidenceType.STATISTICAL_ANOMALY: 0.65, |
| EvidenceType.CONTRADICTORY_EVIDENCE: -0.50 |
| } |
| |
| |
| if self.weight == 0.0 and self.evidence_type in weight_map: |
| self.weight = weight_map[self.evidence_type] |
| |
| |
| if self.is_primary_document: |
| self.weight = max(self.weight, 0.95) |
| if self.is_mathematical_proof: |
| self.weight = max(self.weight, 0.98) |
| if self.is_technical_data: |
| self.weight = max(self.weight, 0.92) |
| if self.anomaly_type: |
| self.weight *= 1.1 |
| if self.protocol_violation: |
| self.weight *= 1.15 |
| |
| def to_direct_framework_fact(self) -> Dict[str, Any]: |
| """Convert to Direct Framework fact format""" |
| return { |
| "id": self.id, |
| "type": self.evidence_type.value, |
| "weight": self.weight, |
| "mathematical_certainty": self.is_mathematical_proof, |
| "primary_source": self.is_primary_document, |
| "anomaly_detected": bool(self.anomaly_type), |
| "protocol_violation": self.protocol_violation, |
| "temporal_context": self.temporal_context, |
| "power_entity": self.power_entity_involved, |
| "quantum_coherence": self.quantum_coherence |
| } |
|
|
| @dataclass |
| class UnifiedAssertion: |
| """Verification target with all dimensions""" |
| claim_id: str |
| claim_text: str |
| |
| |
| temporal_context: Dict[str, Any] = field(default_factory=lambda: { |
| 'epoch': 'unknown', |
| 'time_range': [0, 1000], |
| 'resonance_period': 100 |
| }) |
| |
| consciousness_context: Dict[str, Any] = field(default_factory=lambda: { |
| 'era': 'PERCEPTION', |
| 'interface_type': 'unknown', |
| 'modality': 'unknown' |
| }) |
| |
| symbolic_context: Dict[str, Any] = field(default_factory=lambda: { |
| 'symbols': [], |
| 'numismatic_patterns': [], |
| 'cultural_context': 'unknown' |
| }) |
| |
| field_context: Dict[str, Any] = field(default_factory=lambda: { |
| 'geomagnetic': False, |
| 'solar': False, |
| 'biofield': False |
| }) |
| |
| |
| investigation_mode: InvestigationMode = InvestigationMode.HISTORICAL_EVENT_AUDIT |
| mechanism_focus: List[str] = field(default_factory=list) |
| anomaly_types: List[str] = field(default_factory=list) |
| power_entities: List[str] = field(default_factory=list) |
| required_verifications: List[str] = field(default_factory=lambda: [ |
| "mathematical_certainty", |
| "temporal_coherence", |
| "power_mapping", |
| "anomaly_clustering" |
| ]) |
| |
| scope: Dict[str, Any] = field(default_factory=lambda: { |
| 'domain': 'general', |
| 'complexity': 'medium', |
| 'verification_depth': 'standard' |
| }) |
|
|
| @dataclass |
| class QuantumCoherenceMetrics: |
| """Advanced coherence measurements""" |
| verification_tier: VerificationTier |
| dimensional_alignment: Dict[str, float] |
| quantum_coherence: float |
| pattern_integrity: float |
| temporal_coherence: float |
| consciousness_coherence: float |
| field_resonance: float |
| harmonic_alignment: Dict[str, float] |
| entropy_profile: Dict[str, float] |
| verification_confidence: float |
| investigative_certainty: float |
|
|
| @dataclass |
| class DirectFrameworkReport: |
| """Direct Framework investigation report""" |
| assertion_id: str |
| investigation_mode: InvestigationMode |
| |
| |
| verified_facts: List[Dict[str, Any]] |
| documented_anomalies: List[Dict[str, Any]] |
| temporal_sequence: List[Dict[str, Any]] |
| power_entities: Dict[str, Dict[str, Any]] |
| probability_assessment: Dict[str, Any] |
| required_investigation_paths: List[Dict[str, Any]] |
| documentation_gaps: List[Dict[str, Any]] |
| |
| |
| omission_detected: bool = False |
| mathematical_certainty_applied: bool = False |
| anomaly_clusters: List[List[str]] = field(default_factory=list) |
| mechanism_analysis_complete: bool = False |
| narrative_insertion_detected: bool = False |
| |
| |
| compound_probability: float = 1.0 |
| systemic_analysis_required: bool = False |
| confidence_score: float = 0.0 |
| |
| def to_quantum_evidence(self) -> List[QuantumEvidenceUnit]: |
| """Convert report to Quantum Evidence Units""" |
| evidence_units = [] |
| |
| |
| for i, fact in enumerate(self.verified_facts): |
| unit = QuantumEvidenceUnit( |
| id=f"direct_fact_{self.assertion_id}_{i}", |
| evidence_type=EvidenceType.DOCUMENTARY_RECORD, |
| modality="direct_framework_analysis", |
| source_hash=hashlib.sha256(json.dumps(fact).encode()).hexdigest(), |
| raw_data_hash=hashlib.sha256(str(fact).encode()).hexdigest(), |
| retrieval_method="direct_framework", |
| weight=fact.get('weight', 0.85), |
| confidence=fact.get('confidence', 0.8), |
| is_primary_document=fact.get('primary_source', False), |
| is_mathematical_proof=fact.get('mathematical_certainty', False), |
| temporal_context=fact.get('temporal_context'), |
| power_entity_involved=fact.get('power_entity') |
| ) |
| evidence_units.append(unit) |
| |
| |
| for i, anomaly in enumerate(self.documented_anomalies): |
| unit = QuantumEvidenceUnit( |
| id=f"direct_anomaly_{self.assertion_id}_{i}", |
| evidence_type=EvidenceType.ANOMALY_CLUSTER, |
| modality="direct_framework_analysis", |
| source_hash=hashlib.sha256(json.dumps(anomaly).encode()).hexdigest(), |
| raw_data_hash=hashlib.sha256(str(anomaly).encode()).hexdigest(), |
| retrieval_method="direct_framework", |
| weight=anomaly.get('weight', 0.88), |
| confidence=anomaly.get('confidence', 0.7), |
| anomaly_type=anomaly.get('type'), |
| protocol_violation=anomaly.get('protocol_violation'), |
| communications_gap_duration=anomaly.get('gap_duration'), |
| financial_shift_magnitude=anomaly.get('shift_magnitude') |
| ) |
| evidence_units.append(unit) |
| |
| return evidence_units |
|
|
| @dataclass |
| class UnifiedVerdict: |
| """Complete verification output with all dimensions""" |
| claim_id: str |
| claim_text: str |
| verification_tier: VerificationTier |
| quantum_coherence: QuantumCoherenceMetrics |
| investigative_probability: float |
| temporal_resonance: Dict[str, float] |
| consciousness_interface_score: float |
| symbolic_continuity_score: float |
| field_alignment_score: float |
| memetic_encoding_strength: float |
| |
| |
| direct_framework_report: Optional[DirectFrameworkReport] = None |
| omission_analysis: Dict[str, Any] = field(default_factory=lambda: { |
| 'omissions_detected': 0, |
| 'deception_probability': 0.0, |
| 'critical_gaps': [] |
| }) |
| |
| mathematical_certainty: Dict[str, Any] = field(default_factory=lambda: { |
| 'applied': False, |
| 'certainty_level': 0.0, |
| 'contradictions': [] |
| }) |
| |
| anomaly_cluster_analysis: Dict[str, Any] = field(default_factory=lambda: { |
| 'clusters_detected': 0, |
| 'compound_probability': 1.0, |
| 'systemic_pattern': False |
| }) |
| |
| mechanism_first_analysis: Dict[str, Any] = field(default_factory=lambda: { |
| 'mechanisms_identified': 0, |
| 'how_before_why': True, |
| 'operational_procedures': [] |
| }) |
| |
| zero_narrative_compliance: Dict[str, Any] = field(default_factory=lambda: { |
| 'narrative_insertions': 0, |
| 'framing_detected': False, |
| 'authority_appeals': 0 |
| }) |
| |
| |
| capture_resistance: Dict[str, Any] = field(default_factory=dict) |
| evidence_chain: List[Dict[str, Any]] = field(default_factory=list) |
| provenance_hash: str = "" |
| temporal_hash: str = "" |
| |
| |
| truth_score: float = 0.0 |
| deception_detected: bool = False |
| requires_further_investigation: bool = False |
| verification_timestamp: str = "" |
|
|
| |
| |
| |
|
|
| class DirectInvestigativeEngine: |
| """Direct Framework v4.0 Implementation for Commercial LLMs""" |
| |
| def __init__(self, config: Optional[DirectFrameworkConfig] = None): |
| self.config = config or DirectFrameworkConfig() |
| self.investigation_history = [] |
| self.anomaly_database = defaultdict(list) |
| self.power_entity_registry = {} |
| |
| |
| self.framework_violations = [] |
| self.narrative_insertions_detected = 0 |
| |
| |
| self.math_engine = MathematicalCertaintyEngine() |
| |
| |
| self.anomaly_engine = AnomalyClusterEngine() |
| |
| def process_query(self, query: str, context: Optional[Dict[str, Any]] = None) -> DirectFrameworkReport: |
| """ |
| Process query through Direct Framework v4.0 algorithm |
| |
| Algorithm (from framework): |
| 1. EXTRACT factual components F = {entities, timeframe, mechanisms, specific anomalies} |
| 2. RETRIEVE ALL documented data D where D ∩ F ≠ ∅ |
| 3. APPLY anomaly detection |
| 4. CALCULATE compound probability |
| 5. OUTPUT structure |
| """ |
| |
| |
| factual_components = self._extract_factual_components(query, context) |
| |
| |
| documented_data = self._retrieve_documented_data(factual_components) |
| |
| |
| anomalies = self._detect_anomalies(documented_data, factual_components) |
| |
| |
| probability_assessment = self._calculate_compound_probability(anomalies) |
| |
| |
| report = self._generate_structured_output( |
| factual_components, |
| documented_data, |
| anomalies, |
| probability_assessment |
| ) |
| |
| |
| self._validate_framework_compliance(report) |
| |
| |
| self.investigation_history.append({ |
| 'timestamp': datetime.utcnow().isoformat(), |
| 'query': query, |
| 'report_id': report.assertion_id, |
| 'probability': report.compound_probability |
| }) |
| |
| return report |
| |
| def _extract_factual_components(self, query: str, context: Optional[Dict[str, Any]]) -> Dict[str, Any]: |
| """Extract factual components from query""" |
| |
| |
| components = { |
| 'entities': [], |
| 'timeframe': {'start': None, 'end': None}, |
| 'mechanisms': [], |
| 'specific_anomalies': [], |
| 'power_entities': [], |
| 'financial_mechanisms': [], |
| 'temporal_boundaries': {}, |
| 'investigation_mode': InvestigationMode.HISTORICAL_EVENT_AUDIT |
| } |
| |
| |
| query_lower = query.lower() |
| |
| |
| if any(word in query_lower for word in ['assassination', 'shooting', 'killing']): |
| components['investigation_mode'] = InvestigationMode.ASSASSINATION_ANALYSIS |
| elif any(word in query_lower for word in ['financial', 'money', 'currency', 'debt']): |
| components['investigation_mode'] = InvestigationMode.FINANCIAL_MECHANISM |
| elif any(word in query_lower for word in ['consciousness', 'mind', 'brain', 'neural']): |
| components['investigation_mode'] = InvestigationMode.CONSCIOUSNESS_TECHNOLOGY |
| elif any(word in query_lower for word in ['power', 'control', 'authority', 'sovereignty']): |
| components['investigation_mode'] = InvestigationMode.POWER_MAPPING |
| |
| |
| common_entities = ['government', 'agency', 'corporation', 'bank', 'military', 'intelligence'] |
| for entity in common_entities: |
| if entity in query_lower: |
| components['entities'].append(entity) |
| |
| |
| import re |
| year_pattern = r'\b(19|20)\d{2}\b' |
| years = re.findall(year_pattern, query) |
| if years: |
| components['timeframe']['start'] = min(years) |
| components['timeframe']['end'] = max(years) |
| |
| |
| mechanism_keywords = ['protocol', 'procedure', 'system', 'mechanism', 'process', 'operation'] |
| for keyword in mechanism_keywords: |
| if keyword in query_lower: |
| components['mechanisms'].append(keyword) |
| |
| return components |
| |
| def _retrieve_documented_data(self, components: Dict[str, Any]) -> List[Dict[str, Any]]: |
| """Retrieve documented data related to factual components""" |
| |
| |
| |
| |
| documented_data = [] |
| |
| |
| if components['investigation_mode'] == InvestigationMode.ASSASSINATION_ANALYSIS: |
| documented_data.extend([ |
| { |
| 'type': 'PRIMARY_DOCUMENT', |
| 'source': 'Zapruder Film', |
| 'content': 'Motorcade film showing assassination', |
| 'timestamp': '1963-11-22', |
| 'entities': ['Secret Service', 'President Kennedy'], |
| 'anomalies': ['vehicle deceleration', 'driver actions'], |
| 'weight': 0.95, |
| 'mathematical_certainty': False |
| }, |
| { |
| 'type': 'TECHNICAL_DATA', |
| 'source': 'Radio Communications Logs', |
| 'content': 'Radio silence 12:29-12:35 CST', |
| 'timestamp': '1963-11-22', |
| 'entities': ['Secret Service', 'Dallas Police'], |
| 'anomalies': ['communications gap'], |
| 'weight': 0.92, |
| 'mathematical_certainty': True |
| }, |
| { |
| 'type': 'OFFICIAL_REPORT', |
| 'source': 'Warren Commission', |
| 'content': 'Official investigation report', |
| 'timestamp': '1964-09-24', |
| 'entities': ['Warren Commission', 'FBI', 'CIA'], |
| 'anomalies': ['conflicting testimony', 'evidence omission'], |
| 'weight': 0.65, |
| 'mathematical_certainty': False |
| } |
| ]) |
| |
| |
| elif components['investigation_mode'] == InvestigationMode.FINANCIAL_MECHANISM: |
| documented_data.extend([ |
| { |
| 'type': 'FINANCIAL_SHIFT', |
| 'source': 'Federal Reserve Act 1913', |
| 'content': 'Private central bank establishment', |
| 'timestamp': '1913-12-23', |
| 'entities': ['Federal Reserve', 'Congress', 'Bankers'], |
| 'anomalies': ['private control of money'], |
| 'weight': 0.82, |
| 'mathematical_certainty': True |
| }, |
| { |
| 'type': 'PROTOCOL_VIOLATION', |
| 'source': 'EO11110', |
| 'content': 'Kennedy executive order on currency', |
| 'timestamp': '1963-06-04', |
| 'entities': ['President Kennedy', 'Treasury'], |
| 'anomalies': ['post-assassination reversal'], |
| 'weight': 0.85, |
| 'mathematical_certainty': True |
| } |
| ]) |
| |
| return documented_data |
| |
| def _detect_anomalies(self, data: List[Dict[str, Any]], components: Dict[str, Any]) -> List[Dict[str, Any]]: |
| """Apply anomaly detection to documented data""" |
| |
| anomalies = [] |
| |
| for item in data: |
| anomaly_types = item.get('anomalies', []) |
| |
| for anomaly_type in anomaly_types: |
| anomaly = { |
| 'id': f"anom_{hashlib.sha256(str(item).encode()).hexdigest()[:8]}", |
| 'type': anomaly_type, |
| 'source': item['source'], |
| 'data_item': item, |
| 'detection_method': 'direct_framework_v4', |
| 'severity': self._calculate_anomaly_severity(anomaly_type), |
| 'probability_given_event': self._estimate_anomaly_probability(anomaly_type), |
| 'protocol_violation': 'protocol' in anomaly_type.lower(), |
| 'communications_gap': 'gap' in anomaly_type.lower() or 'silence' in anomaly_type.lower(), |
| 'financial_shift': 'financial' in anomaly_type.lower() or 'money' in anomaly_type.lower(), |
| 'temporal_context': item.get('timestamp') |
| } |
| |
| |
| base_weight = item.get('weight', 0.5) |
| if anomaly['protocol_violation']: |
| anomaly['weight'] = min(1.0, base_weight * 1.15) |
| elif anomaly['communications_gap']: |
| anomaly['weight'] = min(1.0, base_weight * 1.1) |
| elif anomaly['financial_shift']: |
| anomaly['weight'] = min(1.0, base_weight * 1.12) |
| else: |
| anomaly['weight'] = base_weight |
| |
| anomalies.append(anomaly) |
| |
| return anomalies |
| |
| def _calculate_compound_probability(self, anomalies: List[Dict[str, Any]]) -> Dict[str, Any]: |
| """Calculate compound probability of anomalies""" |
| |
| if not anomalies: |
| return { |
| 'compound_probability': 1.0, |
| 'systemic_analysis_required': False, |
| 'probability_breakdown': {} |
| } |
| |
| |
| anomaly_probs = {} |
| for anomaly in anomalies: |
| anomaly_id = anomaly['id'] |
| prob = anomaly.get('probability_given_event', 0.1) |
| anomaly_probs[anomaly_id] = prob |
| |
| |
| |
| compound_prob = 1.0 |
| for prob in anomaly_probs.values(): |
| compound_prob *= prob |
| |
| |
| systemic_analysis_required = compound_prob < self.config.systemic_analysis_threshold |
| |
| return { |
| 'compound_probability': compound_prob, |
| 'systemic_analysis_required': systemic_analysis_required, |
| 'probability_breakdown': anomaly_probs, |
| 'anomaly_count': len(anomalies), |
| 'independence_assumption': True, |
| 'mathematical_certainty_level': 1.0 - compound_prob |
| } |
| |
| def _generate_structured_output(self, |
| components: Dict[str, Any], |
| data: List[Dict[str, Any]], |
| anomalies: List[Dict[str, Any]], |
| probability: Dict[str, Any]) -> DirectFrameworkReport: |
| """Generate structured output according to framework""" |
| |
| |
| report_id = f"direct_{hashlib.sha256(str(components).encode()).hexdigest()[:12]}" |
| |
| |
| verified_facts = [] |
| for item in data: |
| fact = { |
| 'id': f"fact_{item['source'].replace(' ', '_')}", |
| 'source': item['source'], |
| 'content': item['content'], |
| 'timestamp': item.get('timestamp'), |
| 'type': item['type'], |
| 'weight': item.get('weight', 0.5), |
| 'mathematical_certainty': item.get('mathematical_certainty', False), |
| 'primary_source': item['type'] == 'PRIMARY_DOCUMENT', |
| 'entities_involved': item.get('entities', []) |
| } |
| verified_facts.append(fact) |
| |
| |
| temporal_sequence = self._extract_temporal_sequence(data, anomalies) |
| |
| |
| power_entities = self._identify_power_entities(data, anomalies) |
| |
| |
| investigation_paths = self._determine_investigation_paths(components, anomalies, probability) |
| |
| |
| documentation_gaps = self._identify_documentation_gaps(components, data) |
|
|