mirror of
https://github.com/allaunthefox/Research-Stack.git
synced 2026-07-31 03:05:21 +00:00
101 lines
3.6 KiB
Python
101 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
|
# ==============================================================================
|
|
# COPYRIGHT NO ONE EVERYWHERE LLC (WYOMING HOLDING COMPANY)
|
|
# PROJECT: SOVEREIGN STACK
|
|
# This artifact is entirely proprietary and cryptographically proven.
|
|
# Open-Source usage requires explicit permission from Brandon Scott Schneider.
|
|
# ==============================================================================
|
|
"""
|
|
engram_generator.py — Discrete Codon Search for enwik9
|
|
Identifies the 32-byte structural seed (S_H) by maximizing MirrorLUT symmetry.
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
|
from math_harness_compat import xp, AnyArray
|
|
from collections import defaultdict
|
|
import os
|
|
|
|
def load_target(size=10240):
|
|
"""Loads a segment of enwik data."""
|
|
path = os.path.join(os.path.dirname(__file__), '../docs/field_solver/test_input_wiki_10kb.bin')
|
|
if os.path.exists(path):
|
|
with open(path, 'rb') as f:
|
|
return f.read(size)
|
|
else:
|
|
# Fallback target pattern
|
|
return b"The quick brown fox jumps over the lazy dog. " * (size // 45 + 1)
|
|
|
|
def sym_idx(p, q):
|
|
"""Triangular pairing logic (v3 oracle alignment)."""
|
|
lo, hi = (p, q) if p < q else (q, p)
|
|
return int(hi * (hi + 1) / 2 + lo)
|
|
|
|
def build_mirror_lut(data):
|
|
"""Builds a transition frequency matrix for enwik codons."""
|
|
counts = defaultdict(lambda: defaultdict(int))
|
|
for i in range(2, len(data)):
|
|
prev = data[i-2]
|
|
curr = data[i-1]
|
|
nxt = data[i]
|
|
addr = sym_idx(prev, curr)
|
|
counts[addr][nxt] += 1
|
|
return counts
|
|
|
|
def extract_seed(counts, seed_size=32):
|
|
"""
|
|
Extracts the 'Codon Shunt' (32-byte seed S_H).
|
|
Picks the top N most frequent transition addresses to store in the seed.
|
|
"""
|
|
sorted_addrs = sorted(counts.keys(), key=lambda k: sum(counts[k].values()), reverse=True)
|
|
# Each addr is ~16-bit. We can store ~16 major codons in 32 bytes.
|
|
# For now, we take the top 16 addresses as the 'Structural Seed'.
|
|
seed_addrs = sorted_addrs[:seed_size // 2]
|
|
seed = []
|
|
for addr in seed_addrs:
|
|
seed.append(addr >> 8) # High byte
|
|
seed.append(addr & 0xFF) # Low byte
|
|
return bytes(seed), seed_addrs
|
|
|
|
def calculate_hit_rate(data, seed_addrs, counts):
|
|
"""Calculates if the seed can successfully predict the data flow."""
|
|
hits = 0
|
|
total = len(data) - 2
|
|
seed_set = set(seed_addrs)
|
|
|
|
for i in range(2, len(data)):
|
|
addr = sym_idx(data[i-2], data[i-1])
|
|
if addr in seed_set:
|
|
# Prediction: pick the most likely next byte for this addr
|
|
predicted = max(counts[addr].items(), key=lambda x: x[1])[0]
|
|
if predicted == data[i]:
|
|
hits += 1
|
|
|
|
return hits / total
|
|
|
|
def main():
|
|
print("=" * 60)
|
|
print("ENGRAM GENERATOR (Phase 1) — Discrete Codon Search")
|
|
print("=" * 60)
|
|
|
|
data = load_target()
|
|
print(f"Target Loaded: {len(data)} bytes")
|
|
|
|
counts = build_mirror_lut(data)
|
|
print(f"Unique Transitions identified: {len(counts)}")
|
|
|
|
seed, seed_addrs = extract_seed(counts)
|
|
print(f"Seed S_H extracted: {seed.hex()}")
|
|
|
|
# Accuracy check
|
|
hit_rate = calculate_hit_rate(data, seed_addrs, counts)
|
|
print(f"Mirror Hit Rate (v3 Oracle Accuracy): {hit_rate * 100:.2f}%")
|
|
|
|
if hit_rate > 0.05: # High bar for discrete 32-byte search
|
|
print("\nVerdict: PASS - Structural seed identifies salient codons.")
|
|
else:
|
|
print("\nVerdict: FAIL - Hit rate too low to stabilize manifold.")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|