upgraedd commited on
Commit
1137f41
·
verified ·
1 Parent(s): f20c604

Upload EIS_ESL_PNC_CEC_INFMOD.txt

Browse files
Files changed (1) hide show
  1. EIS_ESL_PNC_CEC_INFMOD.txt +209 -0
EIS_ESL_PNC_CEC_INFMOD.txt ADDED
@@ -0,0 +1,209 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Intent Inference Module (INFMOD) for EIS/ESL/PNC/CEC v6
4
+ ========================================================
5
+ This module performs *hypothesis-level* intent inference
6
+ based on structural signals from the ESLedger.
7
+
8
+ It does NOT:
9
+ - assert intent
10
+ - assert agency
11
+ - assert truth
12
+
13
+ It DOES:
14
+ - generate competing hypotheses
15
+ - attach explicit evidence
16
+ - propagate uncertainty
17
+ - maintain epistemic separation
18
+ """
19
+
20
+ from dataclasses import dataclass
21
+ from typing import List, Dict, Optional
22
+ from datetime import datetime
23
+
24
+ # ------------------------------------------------------------
25
+ # INTENT HYPOTHESIS DATA MODEL
26
+ # ------------------------------------------------------------
27
+
28
+ @dataclass
29
+ class IntentHypothesis:
30
+ agent: str # e.g., "institutional", "network", "emergent", "unknown"
31
+ incentive: str # e.g., "reputation_protection", "narrative_control"
32
+ causal_graph: Dict # minimal DAG of event relationships
33
+ probability: float # 0–1 weight, not a verdict
34
+ uncertainty_factors: List[str] # explicit epistemic humility
35
+ evidence: List[str] # concrete observations supporting the hypothesis
36
+
37
+
38
+ # ------------------------------------------------------------
39
+ # INTENT INFERENCE ENGINE
40
+ # ------------------------------------------------------------
41
+
42
+ class IntentInferenceEngine:
43
+ def __init__(self, structural_layer):
44
+ """
45
+ structural_layer: an ESLedger instance or compatible interface
46
+ """
47
+ self.structural = structural_layer
48
+
49
+ # --------------------------------------------------------
50
+ # MAIN ENTRY POINT
51
+ # --------------------------------------------------------
52
+ def infer(self, target: str) -> List[IntentHypothesis]:
53
+ """
54
+ Generate competing intent hypotheses for a given entity or term.
55
+ Returns a list of IntentHypothesis objects.
56
+ """
57
+
58
+ metrics = self._gather_structural_metrics(target)
59
+ incentive_models = self._build_incentive_models(metrics)
60
+ hypotheses = self._generate_hypotheses(metrics, incentive_models)
61
+
62
+ return hypotheses
63
+
64
+ # --------------------------------------------------------
65
+ # STEP 1 — STRUCTURAL METRIC EXTRACTION
66
+ # --------------------------------------------------------
67
+ def _gather_structural_metrics(self, target: str) -> Dict:
68
+ """
69
+ Pulls structural signals from the ESLedger.
70
+ These are *signals*, not interpretations.
71
+ """
72
+
73
+ metrics = {
74
+ "suppression_score": self.structural.get_entity_suppression(target),
75
+ "coordination_likelihood": self._avg_claim_field(target, "coordination_likelihood"),
76
+ "negation_density": self._negation_density(target),
77
+ "temporal_pattern": self._temporal_pattern(target),
78
+ "entity_presence": self._entity_presence(target),
79
+ }
80
+
81
+ return metrics
82
+
83
+ def _avg_claim_field(self, target: str, field: str) -> float:
84
+ vals = []
85
+ for cid, claim in self.structural.claims.items():
86
+ if target.lower() in claim["text"].lower():
87
+ vals.append(claim.get(field, 0.0))
88
+ return sum(vals) / len(vals) if vals else 0.0
89
+
90
+ def _negation_density(self, target: str) -> float:
91
+ neg = 0
92
+ total = 0
93
+ for cid, claim in self.structural.claims.items():
94
+ if target.lower() in claim["text"].lower():
95
+ total += 1
96
+ if any(n in claim["text"].lower() for n in ["not", "never", "no "]):
97
+ neg += 1
98
+ return neg / total if total else 0.0
99
+
100
+ def _temporal_pattern(self, target: str) -> Dict:
101
+ timestamps = []
102
+ for cid, claim in self.structural.claims.items():
103
+ if target.lower() in claim["text"].lower():
104
+ try:
105
+ timestamps.append(datetime.fromisoformat(claim["timestamp"].replace("Z", "+00:00")))
106
+ except:
107
+ pass
108
+ timestamps.sort()
109
+ return {"count": len(timestamps), "first": timestamps[0] if timestamps else None}
110
+
111
+ def _entity_presence(self, target: str) -> int:
112
+ return sum(1 for cid, claim in self.structural.claims.items() if target.lower() in claim["text"].lower())
113
+
114
+ # --------------------------------------------------------
115
+ # STEP 2 — INCENTIVE MODELING
116
+ # --------------------------------------------------------
117
+ def _build_incentive_models(self, metrics: Dict) -> List[Dict]:
118
+ """
119
+ Creates abstract incentive models based on structural signals.
120
+ These are NOT intent claims — they are interpretive scaffolds.
121
+ """
122
+
123
+ models = []
124
+
125
+ # Institutional incentive model
126
+ if metrics["suppression_score"] > 0.4 or metrics["coordination_likelihood"] > 0.5:
127
+ models.append({
128
+ "agent": "institutional",
129
+ "incentive": "narrative_control",
130
+ "weight": 0.4 + metrics["coordination_likelihood"] * 0.3,
131
+ "uncertainties": ["no direct evidence of agency"],
132
+ })
133
+
134
+ # Network incentive model
135
+ if metrics["coordination_likelihood"] > 0.3:
136
+ models.append({
137
+ "agent": "network",
138
+ "incentive": "signal_amplification",
139
+ "weight": 0.3 + metrics["coordination_likelihood"] * 0.2,
140
+ "uncertainties": ["coordination may be emergent"],
141
+ })
142
+
143
+ # Emergent systemic model
144
+ models.append({
145
+ "agent": "emergent",
146
+ "incentive": "incentive_alignment",
147
+ "weight": 0.2 + metrics["negation_density"] * 0.2,
148
+ "uncertainties": ["emergent patterns mimic intent"],
149
+ })
150
+
151
+ # Unknown agent model
152
+ models.append({
153
+ "agent": "unknown",
154
+ "incentive": "unclear",
155
+ "weight": 0.1,
156
+ "uncertainties": ["insufficient structural signal"],
157
+ })
158
+
159
+ return models
160
+
161
+ # --------------------------------------------------------
162
+ # STEP 3 — HYPOTHESIS GENERATION
163
+ # --------------------------------------------------------
164
+ def _generate_hypotheses(self, metrics: Dict, models: List[Dict]) -> List[IntentHypothesis]:
165
+ hypotheses = []
166
+
167
+ for model in models:
168
+ evidence = self._collect_evidence(metrics, model)
169
+
170
+ hypotheses.append(
171
+ IntentHypothesis(
172
+ agent=model["agent"],
173
+ incentive=model["incentive"],
174
+ causal_graph=self._build_causal_graph(metrics),
175
+ probability=min(1.0, model["weight"]),
176
+ uncertainty_factors=model["uncertainties"],
177
+ evidence=evidence
178
+ )
179
+ )
180
+
181
+ return hypotheses
182
+
183
+ def _collect_evidence(self, metrics: Dict, model: Dict) -> List[str]:
184
+ evidence = []
185
+
186
+ if metrics["suppression_score"] > 0.4:
187
+ evidence.append(f"High suppression_score: {metrics['suppression_score']:.2f}")
188
+
189
+ if metrics["coordination_likelihood"] > 0.3:
190
+ evidence.append(f"Elevated coordination_likelihood: {metrics['coordination_likelihood']:.2f}")
191
+
192
+ if metrics["negation_density"] > 0.2:
193
+ evidence.append(f"Negation density suggests contested narrative: {metrics['negation_density']:.2f}")
194
+
195
+ if metrics["entity_presence"] > 10:
196
+ evidence.append(f"High entity presence: {metrics['entity_presence']} mentions")
197
+
198
+ return evidence or ["No strong evidence — hypothesis weak"]
199
+
200
+ def _build_causal_graph(self, metrics: Dict) -> Dict:
201
+ """
202
+ Minimal DAG: structural signals → incentive model
203
+ """
204
+ return {
205
+ "suppression_score": metrics["suppression_score"],
206
+ "coordination_likelihood": metrics["coordination_likelihood"],
207
+ "negation_density": metrics["negation_density"],
208
+ "leads_to": "incentive_hypothesis"
209
+ }