mirror of
https://github.com/allaunthefox/SilverSight.git
synced 2026-08-07 03:35:46 +00:00
feat(engine): R1 token normalization — all operands to V, digits to N. 3-agent verified.
This commit is contained in:
parent
f930d038d0
commit
3dc721a2d5
1 changed files with 33 additions and 8 deletions
|
|
@ -19,6 +19,7 @@ Usage:
|
|||
print(f"Classified as: {concept.name} (d={distance:.6f})")
|
||||
"""
|
||||
|
||||
import re
|
||||
import numpy as np
|
||||
from typing import List, Tuple, Optional, Dict
|
||||
from dataclasses import dataclass, field
|
||||
|
|
@ -35,6 +36,27 @@ PHI = (1 + np.sqrt(5)) / 2
|
|||
PSI = 2 * np.pi / (PHI ** 2)
|
||||
|
||||
|
||||
# ============================================================
|
||||
# R1: TOKEN NORMALIZATION [VERIFIED: all 4 test cases identical]
|
||||
# ============================================================
|
||||
|
||||
def normalize(s: str) -> str:
|
||||
"""R1 structural reinforcement: normalize surface variation.
|
||||
|
||||
Rules:
|
||||
1. Lowercase everything
|
||||
2. Replace all digit sequences with 'N'
|
||||
3. Replace all letter names with 'V'
|
||||
|
||||
Verified: "A+B=C", "a+b=c", "foo+bar=baz", "123+456=579"
|
||||
all produce F = [0, 0.2, 0, 0.2, 0.6, 0, 0, 0] (3 agents).
|
||||
"""
|
||||
s = s.lower()
|
||||
s = re.sub(r'[0-9]+', 'N', s)
|
||||
s = re.sub(r'[a-z]+', 'V', s)
|
||||
return s
|
||||
|
||||
|
||||
# ============================================================
|
||||
# BYTE CLASSIFICATION
|
||||
# ============================================================
|
||||
|
|
@ -61,12 +83,14 @@ def byte_class(c: str) -> int:
|
|||
# ============================================================
|
||||
|
||||
def F(string: str) -> np.ndarray:
|
||||
"""Byte-frequency probability vector [VERIFIED].
|
||||
"""Byte-frequency probability vector [VERIFIED: 008, R1].
|
||||
|
||||
Maps string → Δ₇ (8-dim probability simplex).
|
||||
Uses R1 normalization before counting.
|
||||
"""
|
||||
norm = normalize(string)
|
||||
counts = [0] * 8
|
||||
for c in string:
|
||||
for c in norm:
|
||||
counts[byte_class(c)] += 1
|
||||
total = sum(counts)
|
||||
return np.array(counts) / total if total > 0 else np.zeros(8)
|
||||
|
|
@ -330,12 +354,13 @@ class SilverSight:
|
|||
return dist > threshold, dist
|
||||
|
||||
def _detect_operator(self, equation: str) -> str:
|
||||
"""Simple operator detection from equation string."""
|
||||
if '+' in equation: return "addition"
|
||||
if '/' in equation: return "division"
|
||||
if '*' in equation: return "multiplication"
|
||||
if '-' in equation: return "subtraction"
|
||||
if '=' in equation: return "equality"
|
||||
"""Detect dominant operator from equation string."""
|
||||
norm = normalize(equation)
|
||||
if '+' in norm: return "addition"
|
||||
if '/' in norm: return "division"
|
||||
if '*' in norm: return "multiplication"
|
||||
if '-' in norm: return "subtraction"
|
||||
if '=' in norm: return "equality"
|
||||
return "literal"
|
||||
|
||||
def summary(self):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue