symbolic_mutations / codex /formulas.py
RFTSystems's picture
Update codex/formulas.py
e41cd5c verified
Raw
History Blame
1.94 kB
# Author: Liam Grinstead
# RFT-native scoring wrapped in Formula class
from math import exp
class Formula:
def __init__(self, expression: str):
self.expression = expression
def evaluate(self, agent: dict) -> float:
overlay = agent.get("collapse_overlay", {}) or {}
tau_eff = overlay.get("tau_eff", 1.0)
beta = overlay.get("beta_band", 0.5)
weights = overlay.get("operator_weights", {}) or {}
tier = agent.get("tier", "Tier_1")
tier_level = int(tier.split("_")[1]) if "_" in tier else 1
resonance = 1.2 if agent.get("emotional_resonance") else 1.0
coupling_sum = sum(v for v in weights.values() if isinstance(v, (int, float)))
weight_count = max(1, len(weights))
coupling = coupling_sum / (1.0 + 0.25 * weight_count)
drift_penalty = 0.18 * tier_level
drift_resilience = 1.0 + 0.05 * (tier_level - 1)
collapse_energy = tau_eff * (0.6 + 0.4 * beta) * (1.0 + 0.35 * coupling)
coherence = exp(- (0.22 * tau_eff + 0.08 * tier_level)) * (0.9 + 0.1 * beta)
gvu = (collapse_energy * resonance * drift_resilience) * (0.7 + 0.6 * coherence) - drift_penalty
score = max(0.0, gvu)
return round(score, 4)
GVU_FORMULAS = {
"Formula_20": Formula("−τ_eff / (τ_c + 19/20) ⋅ P_standard ⋅ τ_eff ⋅ ℯ ⋅ |grad_R_O − grad_T_P| / GVU")
}
def rft_invariants(agent: dict) -> dict:
"""
Always returns a dict; never None. Uses safe defaults if data is missing.
"""
overlay = agent.get("collapse_overlay", {}) or {}
tier = agent.get("tier", "Tier_1")
tier_level = int(tier.split("_")[1]) if "_" in tier else 1
operators = agent.get("symbolic_operators", []) or []
return {
"tau_eff": overlay.get("tau_eff", 1.0),
"beta_band": overlay.get("beta_band", 0.5),
"operator_count": len(operators),
"tier_level": tier_level,
}