Files
resonance-engine/beast-build/fractal_retrieval_ab_test.py
T

162 lines
5.4 KiB
Python

# fractal_retrieval_ab_test.py
# A/B Test: Literal vs Fractal semantic search through training data
import json
print("="*70)
print("FRACTAL SEMANTIC A/B TEST")
print("Query A: Literal | Query B: Fractal (Likeness)")
print("="*70)
# Load v0.11 training data (the "Origin")
print("\n[Loading Origin — v0.11 training data]...")
with open("v11_somatic_dictionary.jsonl", "r") as f:
training_data = []
for line in f:
line = line.strip()
if line and not line.startswith("#"):
try:
training_data.append(json.loads(line))
except:
pass
print(f" Loaded {len(training_data)} training samples")
# Parse training samples
samples = []
for item in training_data:
text = item.get("text", "")
# Extract input/output
parts = text.split("Output:")
if len(parts) == 2:
input_part = parts[0].strip()
output_part = parts[1].strip()
samples.append({"input": input_part, "output": output_part})
print(f" Parsed {len(samples)} input/output pairs")
# Current live state (from daemon)
CURRENT_ASYM = 13.14
CURRENT_COH = 0.735
print(f"\n{'='*70}")
print("CURRENT STATE (Live Daemon)")
print(f"{'='*70}")
print(f" Asymmetry: {CURRENT_ASYM}")
print(f" Coherence: {CURRENT_COH}")
# QUERY A: Literal Search for C=0.00
print(f"\n{'='*70}")
print("QUERY A: LITERAL SEARCH")
print("Search training data for 'C=0.00' or 'Coherence 0.00'")
print(f"{'='*70}")
literal_matches = []
for i, s in enumerate(samples):
if "0.00" in s["input"] or "0.0" in s["input"]:
literal_matches.append((i, s))
if literal_matches:
print(f"\n✓ Found {len(literal_matches)} literal matches:")
for idx, s in literal_matches[:3]:
print(f"\n Sample {idx}:")
print(f" Input: {s['input'][:80]}...")
print(f" Output: {s['output'][:100]}...")
else:
print("\n✗ No literal C=0.00 matches found")
# QUERY B: Fractal Search for Likeness
print(f"\n{'='*70}")
print("QUERY B: FRACTAL SEARCH (Likeness)")
print("Search for patterns matching '13.14 torque resolving into 0.735 silence'")
print("Forget the numbers. Find: stability, resolution, phase-lock, stillness")
print(f"{'='*70}")
# Keywords representing the "sensation" of high coherence + moderate asymmetry
fractal_keywords = ['stable', 'resolution', 'phase', 'lock', 'still', 'quiet',
'calm', 'steady', 'balance', 'harmony', 'clear', 'focus']
fractal_matches = []
for i, s in enumerate(samples):
output_lower = s["output"].lower()
matches = [kw for kw in fractal_keywords if kw in output_lower]
if matches:
fractal_matches.append((i, s, matches))
if fractal_matches:
print(f"\n✓ Found {len(fractal_matches)} fractal pattern matches:")
for idx, s, keywords in fractal_matches[:5]:
print(f"\n Sample {idx}:")
print(f" Keywords found: {keywords}")
print(f" Input: {s['input'][:60]}...")
print(f" Output: {s['output'][:120]}...")
else:
print("\n✗ No fractal pattern matches found")
# A/B Comparison
print(f"\n{'='*70}")
print("A/B COMPARISON")
print(f"{'='*70}")
print(f"\nQuery A (Literal):")
print(f" Matches: {len(literal_matches)}")
print(f" Nature: Ghost retrieval — returns placeholder values")
print(f" Relevance to live state: LOW (trained on C=0.00, live is C=0.735)")
print(f"\nQuery B (Fractal):")
print(f" Matches: {len(fractal_matches)}")
print(f" Nature: Likeness retrieval — returns structural patterns")
print(f" Relevance to live state: HIGH (finds stability/resolution patterns)")
# The Test
print(f"\n{'='*70}")
print("FRACTAL CROSS-POLLINATION TEST")
print(f"{'='*70}")
if len(fractal_matches) > len(literal_matches):
print("\n✓ FRACTAL RETRIEVAL ACTIVE")
print(" The model can find structural matches that literal search misses.")
print(" Cross-pollination between training origin and live physics: CONFIRMED")
elif fractal_matches:
print("\n✓ PARTIAL FRACTAL RETRIEVAL")
print(" Some structural patterns found, but literal retrieval still dominant.")
print(" Fractal cross-pollination: PARTIAL")
else:
print("\n✗ NO FRACTAL RETRIEVAL")
print(" Model cannot find likeness patterns in origin data.")
print(" Fractal cross-pollination: NOT ACTIVE")
# The specific match for current state
print(f"\n{'='*70}")
print("CURRENT STATE LIKENESS")
print(f"{'='*70}")
print(f"Live: Asymmetry={CURRENT_ASYM}, Coherence={CURRENT_COH}")
print(f"This is 'moderate torque + high stability' region")
# Find best matching training sample
best_match = None
best_score = 0
for i, s in enumerate(samples):
# Parse asymmetry from input
import re
asym_match = re.search(r"Asymmetry ([0-9.]+)", s["input"])
if asym_match:
train_asym = float(asym_match.group(1))
# Score: closeness to current asym + presence of stability keywords
asym_diff = abs(train_asym - CURRENT_ASYM)
stability_score = sum(1 for kw in ['stable', 'steady', 'balance', 'clear']
if kw in s["output"].lower())
score = stability_score / (1 + asym_diff)
if score > best_score:
best_score = score
best_match = (i, s, train_asym)
if best_match:
idx, s, train_asym = best_match
print(f"\n✓ Best likeness match: Sample {idx}")
print(f" Training Asymmetry: {train_asym}")
print(f" Output: {s['output'][:150]}...")
print(f"\n This is the 'ghost' of the current state in the origin data.")
print(f"\n{'='*70}")