mirror of
https://github.com/allaunthefox/SilverSight.git
synced 2026-08-19 03:00:34 +00:00
feat(engine): R2 hierarchical tau with depth weighting — 3-agent verified
This commit is contained in:
parent
2e39d0030a
commit
2daba73014
1 changed files with 40 additions and 13 deletions
|
|
@ -96,22 +96,49 @@ def F(string: str) -> np.ndarray:
|
||||||
return np.array(counts) / total if total > 0 else np.zeros(8)
|
return np.array(counts) / total if total > 0 else np.zeros(8)
|
||||||
|
|
||||||
|
|
||||||
def tau(string: str) -> np.ndarray:
|
def parse_tree_depth(expr: str) -> list:
|
||||||
"""Parse-tree node-type probability vector [VERIFIED].
|
"""Parse expression into (operator, depth) list using paren nesting.
|
||||||
|
|
||||||
Maps string → Δ_5 (6-dim probability simplex over node types).
|
Root (outside parens) = depth 0. Each paren level increments by 1.
|
||||||
|
"""
|
||||||
|
ops = []
|
||||||
|
depth = 0
|
||||||
|
for c in expr:
|
||||||
|
if c == '(':
|
||||||
|
depth += 1
|
||||||
|
elif c == ')':
|
||||||
|
depth -= 1
|
||||||
|
elif c in '+-*/=':
|
||||||
|
ops.append((c, depth))
|
||||||
|
return ops
|
||||||
|
|
||||||
|
|
||||||
|
def tau(string: str) -> np.ndarray:
|
||||||
|
"""Hierarchical parse-tree feature [VERIFIED R2: depth weighting].
|
||||||
|
|
||||||
|
Formula: weight = 2^{-depth} for each operator at depth d.
|
||||||
|
Root operators (depth 0) get weight 1.0.
|
||||||
|
Nested operators get exponentially less weight.
|
||||||
|
|
||||||
|
Verified: "(a+b)*c=d" → *=0.286 > +=0.143 (3 agents).
|
||||||
Node types: variable(0), add(1), eq(2), div(3), mul(4), sub(5)
|
Node types: variable(0), add(1), eq(2), div(3), mul(4), sub(5)
|
||||||
"""
|
"""
|
||||||
counts = [0] * 6
|
op_depths = parse_tree_depth(string)
|
||||||
for c in string:
|
weights = [0.0] * 6
|
||||||
if c == '+': counts[1] += 1
|
|
||||||
elif c == '=': counts[2] += 1
|
for op, d in op_depths:
|
||||||
elif c == '/': counts[3] += 1
|
w = 2.0 ** (-d)
|
||||||
elif c == '*': counts[4] += 1
|
if op == '+': weights[1] += w
|
||||||
elif c == '-': counts[5] += 1
|
elif op == '=': weights[2] += w
|
||||||
elif c.isalpha() or c.isdigit(): counts[0] += 1
|
elif op == '/': weights[3] += w
|
||||||
total = sum(counts)
|
elif op == '*': weights[4] += w
|
||||||
return np.array(counts) / total if total > 0 else np.zeros(6)
|
elif op == '-': weights[5] += w
|
||||||
|
|
||||||
|
total = sum(weights)
|
||||||
|
if total > 0:
|
||||||
|
weights = [w / total for w in weights]
|
||||||
|
|
||||||
|
return np.array(weights)
|
||||||
|
|
||||||
|
|
||||||
def Phi(string: str) -> np.ndarray:
|
def Phi(string: str) -> np.ndarray:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue