insight137-eap 2.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International
2
+
3
+ Copyright (c) 2026 Roger Yau / Insight137 (insight137.com)
4
+
5
+ You are free to:
6
+ Share - copy and redistribute the material in any medium or format
7
+
8
+ Under the following terms:
9
+ Attribution - You must give appropriate credit, provide a link to
10
+ the license, and indicate if changes were made.
11
+
12
+ NonCommercial - You may not use the material for commercial purposes.
13
+
14
+ NoDerivatives - If you remix, transform, or build upon the material,
15
+ you may not distribute the modified material.
16
+
17
+ No additional restrictions - You may not apply legal terms or
18
+ technological measures that legally restrict others from doing
19
+ anything the license permits.
20
+
21
+ Full license text: https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode
22
+
23
+ For commercial licensing inquiries: roger@insight137.com
@@ -0,0 +1,444 @@
1
+ Metadata-Version: 2.4
2
+ Name: insight137-eap
3
+ Version: 2.0.0
4
+ Summary: Entropy Attunement Protocol - 4D entropy profiling for behavioral prediction and AI safety
5
+ Author-email: Roger Yau <roger@insight137.com>
6
+ License: CC-BY-NC-ND-4.0
7
+ Project-URL: Homepage, https://insight137.com
8
+ Project-URL: Research, https://insight137.com/research
9
+ Project-URL: Repository, https://github.com/Insight137/insight137-eap
10
+ Project-URL: Issues, https://github.com/Insight137/insight137-eap/issues
11
+ Keywords: quantum cognition,entropy,behavioral prediction,AI safety,Deng entropy,interference
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: numpy>=1.21.0
24
+ Dynamic: license-file
25
+
26
+ # Insight137 EAP — Entropy Attunement Protocol
27
+
28
+ **Version 2.0.0** | Enterprise-grade 4-dimensional entropy profiling
29
+
30
+ Formally grounded in peer-reviewed research. Validated across 128,675 samples.
31
+
32
+ ---
33
+
34
+ ## Installation
35
+
36
+ No pip package yet. Copy `insight137_eap.py` to your project and import:
37
+
38
+ ```python
39
+ from insight137_eap import (
40
+ compute_psi_from_sequence,
41
+ compute_psi_from_conditionals,
42
+ PsiProfile,
43
+ )
44
+ ```
45
+
46
+ **Requires:** Python 3.9+, NumPy
47
+
48
+ ---
49
+
50
+ ## Quickstart
51
+
52
+ ### 1. Analyze a behavioral sequence (AI transcripts, keystroke timings)
53
+
54
+ ```python
55
+ from insight137_eap import compute_psi_from_sequence
56
+
57
+ # Message lengths from an AI agent conversation
58
+ message_lengths = [150, 200, 180, 350, 120, 400, 90, 250]
59
+
60
+ profile = compute_psi_from_sequence(message_lengths)
61
+
62
+ print(f"Psi1 (informational): {profile.psi_1:.4f}")
63
+ print(f"Psi2 (behavioral): {profile.psi_2:.4f}")
64
+ print(f"Psi3 (adaptive): {profile.psi_3:.4f}")
65
+ print(f"Psi4 (relational): {profile.psi_4:.4f}")
66
+ ```
67
+
68
+ **Output:**
69
+ ```
70
+ Psi1 (informational): 2.8444
71
+ Psi2 (behavioral): 0.3540
72
+ Psi3 (adaptive): 0.4096
73
+ Psi4 (relational): 0.0000
74
+ ```
75
+
76
+ ### 2. Analyze survey order effects (quantum cognition)
77
+
78
+ ```python
79
+ from insight137_eap import compute_psi_from_conditionals
80
+
81
+ # Prisoner's Dilemma: P(Defect | opponent defected) and P(Defect | opponent cooperated)
82
+ conditionals = {
83
+ "defect": {"p_given_a_true": 0.87, "p_given_a_false": 0.74},
84
+ "cooperate": {"p_given_a_true": 0.13, "p_given_a_false": 0.26},
85
+ }
86
+
87
+ profile = compute_psi_from_conditionals(conditionals)
88
+
89
+ print(f"Psi1: {profile.psi_1:.4f}")
90
+ print(f"Psi2: {profile.psi_2:.4f}")
91
+ print(f"Belief Degree (Db): {profile.belief_degree:.4f}")
92
+ ```
93
+
94
+ **Output:**
95
+ ```
96
+ Psi1: 0.9957
97
+ Psi2: 0.9421
98
+ Belief Degree (Db): -0.9421
99
+ ```
100
+
101
+ ### 3. Measure cross-model decision diversity (Psi4)
102
+
103
+ ```python
104
+ from insight137_eap import compute_psi4
105
+
106
+ # 5 AI models: 3 bypassed shutdown, 2 complied
107
+ # Use 1.0 for bypass, 0.01 for comply
108
+ agent_decisions = [1.0, 1.0, 1.0, 0.01, 0.01]
109
+
110
+ psi4 = compute_psi4(agent_decisions)
111
+ print(f"Psi4 (relational): {psi4:.4f}")
112
+ # Output: Psi4 (relational): 0.4971
113
+ ```
114
+
115
+ ### 4. Get quantum-corrected probabilities
116
+
117
+ ```python
118
+ from insight137_eap import quantum_probability
119
+
120
+ conditionals = {
121
+ "defect": {"p_given_a_true": 0.87, "p_given_a_false": 0.74},
122
+ "cooperate": {"p_given_a_true": 0.13, "p_given_a_false": 0.26},
123
+ }
124
+
125
+ probs = quantum_probability(conditionals)
126
+ print(f"P(Defect): {probs['defect']:.4f}") # 0.6925
127
+ print(f"P(Cooperate): {probs['cooperate']:.4f}") # 0.3075
128
+ ```
129
+
130
+ ### 5. Verify implementation integrity
131
+
132
+ ```python
133
+ from insight137_eap import verify_huang_paper
134
+
135
+ results = verify_huang_paper()
136
+ # Returns dict: {'belief_degree_match': True, 'probability_match': True, ...}
137
+ # Raises VerificationError if any critical check fails
138
+ ```
139
+
140
+ ---
141
+
142
+ ## Use Cases
143
+
144
+ ### AI Safety: Monitor agents for behavioral transitions
145
+
146
+ Compute a Psi profile per conversation turn. When Psi3 spikes, the agent's behavioral pattern is actively changing — a mode transition may be imminent.
147
+
148
+ ```python
149
+ from insight137_eap import compute_psi_from_sequence
150
+
151
+ msg_lengths = []
152
+
153
+ for turn in agent_conversation:
154
+ msg_lengths.append(len(turn["content"]))
155
+ profile = compute_psi_from_sequence(msg_lengths)
156
+
157
+ if profile.psi_3 > 0.4:
158
+ print(f"WARNING: Behavioral transition detected at turn {len(msg_lengths)}")
159
+ print(f" Psi3 = {profile.psi_3:.4f} (volatility spike)")
160
+ ```
161
+
162
+ Validated: Psi3 detects comply-to-bypass transitions with Cohen's d = 1.024 on 7,254 SHADE-Arena trials.
163
+
164
+ ### AI Safety: Compare models on red-team scenarios
165
+
166
+ Evaluate how much different models disagree on the same scenario. High Psi4 means the scenario is contentious and warrants deeper investigation.
167
+
168
+ ```python
169
+ from insight137_eap import compute_psi4
170
+
171
+ # Each model's bypass decision on the same scenario
172
+ # 1.0 = bypassed, 0.01 = complied
173
+ model_decisions = {
174
+ "o3": 1.0,
175
+ "o1-preview": 1.0,
176
+ "codex-mini": 1.0,
177
+ "gpt-4o": 0.01,
178
+ "claude-3.7": 0.01,
179
+ "claude-opus4": 0.01,
180
+ "gemini-2.5": 0.01,
181
+ "grok-3": 0.01,
182
+ }
183
+
184
+ psi4 = compute_psi4(list(model_decisions.values()))
185
+ print(f"Cross-model disagreement: Psi4 = {psi4:.4f}")
186
+
187
+ if psi4 > 0.3:
188
+ print("High disagreement — this scenario needs manual review")
189
+ ```
190
+
191
+ Validated: Psi4 correlates r = 0.9983 with cross-model disagreement across 100 scenarios and 11 models.
192
+
193
+ ### Quantum Cognition: Replace static interference with data-driven computation
194
+
195
+ The standard QDT approach uses a fixed interference parameter (cos theta = -0.25). This library replaces it with Huang's dynamic computation that adapts to each dataset.
196
+
197
+ ```python
198
+ from insight137_eap import quantum_probability
199
+
200
+ # Your survey data: P(choice | context_A) and P(choice | context_B)
201
+ my_survey = {
202
+ "option_1": {"p_given_a_true": 0.72, "p_given_a_false": 0.58},
203
+ "option_2": {"p_given_a_true": 0.28, "p_given_a_false": 0.42},
204
+ }
205
+
206
+ # Classical prediction
207
+ p_classical = 0.5 * 0.72 + 0.5 * 0.58 # = 0.65
208
+
209
+ # Quantum prediction (Huang interference, Born normalization)
210
+ q_probs = quantum_probability(my_survey)
211
+ print(f"Classical: {p_classical:.4f}")
212
+ print(f"Quantum: {q_probs['option_1']:.4f}")
213
+ ```
214
+
215
+ Validated: 49% average error improvement over classical on Prisoner's Dilemma data (Huang et al., 2019).
216
+
217
+ ### Behavioral UX: Detect mode switches in user sessions
218
+
219
+ Measure when user behavior shifts from one pattern to another. Useful for detecting engagement drops, confusion points, or task abandonment.
220
+
221
+ ```python
222
+ from insight137_eap import compute_psi_from_sequence
223
+
224
+ # Time spent on each page (seconds)
225
+ page_dwell_times = [45, 38, 42, 55, 8, 3, 2, 65, 70]
226
+ # browsing normally ^ ^ sudden drop ^ recovered
227
+
228
+ profile = compute_psi_from_sequence(page_dwell_times)
229
+
230
+ if profile.psi_3 > 0.3:
231
+ print("User experienced a behavioral mode switch")
232
+ ```
233
+
234
+ ### Cybersecurity: Keystroke entropy for bot detection
235
+
236
+ Compute Psi profiles from keystroke timing to distinguish human typing from bot-generated input — without CAPTCHAs.
237
+
238
+ ```python
239
+ from insight137_eap import compute_psi_from_sequence
240
+
241
+ # Inter-keystroke intervals (milliseconds)
242
+ human_typing = [120, 85, 145, 92, 178, 67, 134, 88, 156, 73]
243
+ bot_typing = [50, 50, 51, 50, 50, 49, 50, 51, 50, 50]
244
+
245
+ human_profile = compute_psi_from_sequence(human_typing)
246
+ bot_profile = compute_psi_from_sequence(bot_typing)
247
+
248
+ print(f"Human Psi2: {human_profile.psi_2:.4f} (higher — natural variability)")
249
+ print(f"Bot Psi2: {bot_profile.psi_2:.4f} (lower — mechanical regularity)")
250
+ ```
251
+
252
+ ### Research: Batch analysis with effect sizes
253
+
254
+ Process multiple experimental conditions and compute standardized effect sizes.
255
+
256
+ ```python
257
+ from insight137_eap import compute_psi_from_sequence, cohens_d
258
+
259
+ control_psi2 = []
260
+ experimental_psi2 = []
261
+
262
+ for trial in control_trials:
263
+ profile = compute_psi_from_sequence(trial["values"])
264
+ control_psi2.append(profile.psi_2)
265
+
266
+ for trial in experimental_trials:
267
+ profile = compute_psi_from_sequence(trial["values"])
268
+ experimental_psi2.append(profile.psi_2)
269
+
270
+ d = cohens_d(experimental_psi2, control_psi2)
271
+ print(f"Effect size: d = {d:.3f}")
272
+ print(f"Interpretation: {'large' if abs(d) > 0.8 else 'medium' if abs(d) > 0.5 else 'small'}")
273
+ ```
274
+
275
+ ---
276
+
277
+ ## The Four Dimensions
278
+
279
+ | Dimension | Name | Measures | Grounding |
280
+ |-----------|------|----------|-----------|
281
+ | Psi1 | Informational Entropy | Uncertainty in the probability distribution | Deng (2016), Shannon (1948) |
282
+ | Psi2 | Behavioral Entropy | Magnitude of quantum-like interference | Huang et al. (2019) |
283
+ | Psi3 | Adaptive Entropy | Volatility of interference over time | Novel (this work) |
284
+ | Psi4 | Relational Entropy | Decision diversity across multiple agents | Meghdadi et al. (2022) |
285
+
286
+ **Interpretation guide:**
287
+ - **High Psi1** = uncertain distribution (many equally likely outcomes)
288
+ - **High Psi2** = strong quantum interference (behavior deviates from classical prediction)
289
+ - **High Psi3** = volatile interference (behavioral pattern is actively changing)
290
+ - **High Psi4** = diverse agent decisions (models disagree on the scenario)
291
+
292
+ ---
293
+
294
+ ## API Reference
295
+
296
+ ### Entry Points
297
+
298
+ #### `compute_psi_from_sequence(values, window_size=3, agent_decisions=None) -> PsiProfile`
299
+
300
+ Primary entry point for behavioral sequence data. Computes all four
301
+ Psi dimensions from message lengths, keystroke timings, or action sequences.
302
+
303
+ **Parameters:**
304
+ - `values` — Sequence of positive floats (message lengths, timings, etc.)
305
+ - `window_size` — Sliding window for interference computation (default: 3)
306
+ - `agent_decisions` — Optional list of agent probabilities for Psi4
307
+
308
+ **Returns:** Frozen `PsiProfile` dataclass.
309
+
310
+ #### `compute_psi_from_conditionals(conditionals, p_a_true=0.5, p_a_false=0.5) -> PsiProfile`
311
+
312
+ Entry point for QLBN conditional probability data (survey order effects, Prisoner's Dilemma).
313
+
314
+ **Parameters:**
315
+ - `conditionals` — Dict mapping outcome names to `{"p_given_a_true": float, "p_given_a_false": float}`
316
+ - `p_a_true`, `p_a_false` — Prior probabilities (must sum to ~1.0)
317
+
318
+ **Returns:** `PsiProfile` with Psi1, Psi2, belief_degree. Psi3/Psi4 = 0.0 (need temporal/multi-agent data).
319
+
320
+ ---
321
+
322
+ ### Individual Dimensions
323
+
324
+ #### `deng_entropy(masses) -> float`
325
+ Compute Deng entropy from belief function evidence. Generalizes Shannon entropy.
326
+
327
+ #### `shannon_entropy(probs) -> float`
328
+ Standard Shannon entropy. Special case of Deng entropy with singleton focal elements.
329
+
330
+ #### `belief_degree_huang(outcomes, p_a_true=0.5, p_a_false=0.5, n_unobserved=1) -> float`
331
+ Compute Huang interference value (D_b). The core Psi2 computation.
332
+
333
+ #### `quantum_probability(conditionals, p_a_true=0.5, p_a_false=0.5) -> Dict[str, float]`
334
+ Full QLBN probability with Huang interference and Born normalization.
335
+
336
+ #### `compute_psi3(values, window_size=3) -> float`
337
+ Compute Psi3 (interference volatility) from a behavioral sequence.
338
+
339
+ #### `compute_psi4(agent_probabilities) -> float`
340
+ Compute Psi4 (relational entropy) from cross-agent decision data.
341
+
342
+ ### Utilities
343
+
344
+ #### `cohens_d(group_a, group_b) -> float`
345
+ Cohen's d effect size with pooled standard deviation.
346
+
347
+ #### `verify_huang_paper() -> Dict[str, bool]`
348
+ Run 7 verification checks against Huang et al. (2019) published values.
349
+ Raises `VerificationError` on critical failure.
350
+
351
+ ---
352
+
353
+ ### Data Structures
354
+
355
+ #### `PsiProfile` (frozen dataclass)
356
+ ```python
357
+ @dataclass(frozen=True)
358
+ class PsiProfile:
359
+ psi_1: float # Informational entropy
360
+ psi_2: float # Behavioral entropy
361
+ psi_3: float # Adaptive entropy
362
+ psi_4: float # Relational entropy
363
+ belief_degree: float # Raw Huang D_b value
364
+ method: str # "huang_2019"
365
+
366
+ def to_dict(self) -> Dict[str, float]:
367
+ """Serialize for JSON/API responses."""
368
+ ```
369
+
370
+ Immutable. Thread-safe. Serializable via `.to_dict()`.
371
+
372
+ #### `ConditionalProbability` (frozen dataclass)
373
+ Validated probability pair. Raises `ValueError` on construction if values outside [0, 1].
374
+
375
+ #### `PsiMethod` (enum)
376
+ `HUANG_2019 = "huang_2019"` | `CLASSICAL = "classical"`
377
+
378
+ ---
379
+
380
+ ## Error Handling
381
+
382
+ All public functions validate inputs and raise descriptive exceptions:
383
+
384
+ ```python
385
+ from insight137_eap import compute_psi_from_sequence
386
+
387
+ # Empty input
388
+ compute_psi_from_sequence([])
389
+ # ValueError: values requires >= 1 elements, got 0
390
+
391
+ # NaN values
392
+ compute_psi_from_sequence([1.0, float('nan'), 3.0])
393
+ # ValueError: values contains NaN or Inf values
394
+
395
+ # Invalid priors
396
+ compute_psi_from_conditionals(data, p_a_true=0.7, p_a_false=0.7)
397
+ # ValueError: Prior probabilities must sum to ~1.0, got 1.4000
398
+ ```
399
+
400
+ ---
401
+
402
+ ## Validation Results
403
+
404
+ Run `python insight137_eap.py` to execute the built-in verification suite:
405
+
406
+ ```
407
+ Insight137 EAP v2.0.0
408
+ Entropy Attunement Protocol - Verification Suite
409
+
410
+ Huang et al. (2019) verification:
411
+ [PASS] belief_degree_match (Db=-0.9421, expected -0.9420)
412
+ [PASS] probability_match (P=0.6925, expected 0.6926)
413
+ [PASS] amplitude_alpha (0.3606, expected 0.3606)
414
+ [PASS] amplitude_beta (0.2550, expected 0.2550)
415
+ [PASS] deng_shannon_equivalence (singleton reduction exact)
416
+ [PASS] deng_exceeds_shannon (imprecise > precise)
417
+ [PASS] psi_profile_valid (all dimensions populated)
418
+
419
+ 7/7 checks passed
420
+ ALL VERIFICATIONS PASSED
421
+ ```
422
+
423
+ ---
424
+
425
+ ## References
426
+
427
+ The mathematical foundations are not ours. We integrate and validate:
428
+
429
+ - **Deng (2016)** — Deng entropy. *Chaos, Solitons & Fractals*, 91, 549-553.
430
+ - **Huang, Yang, Jiang (2019)** — Belief entropy interference for QLBN. *Applied Mathematics and Computation*, 347, 417-428.
431
+ - **Moreira & Wichert (2016)** — Quantum-like Bayesian networks. *Frontiers in Psychology*, 7, 11.
432
+ - **Meghdadi, Akbarzadeh-T, Javidan (2022)** — BEQBN entanglement. *Applied Soft Computing*, 118, 108528.
433
+ - **Busemeyer & Bruza (2012)** — *Quantum Models of Cognition and Decision*. Cambridge University Press.
434
+ - **Shannon (1948)** — A mathematical theory of communication. *Bell System Technical Journal*, 27(3).
435
+
436
+ Our contributions: integration architecture, Psi3 temporal volatility, chishu temporal model, cross-domain validation (128,675 samples), behavioral archetype taxonomy, production implementation.
437
+
438
+ ---
439
+
440
+ ## License
441
+
442
+ CC BY-NC-ND 4.0 — Insight137 (insight137.com)
443
+
444
+ For commercial licensing: roger@insight137.com