MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / _normalize_weight_map

Function _normalize_weight_map

scripts/drift_engine.py:133–151  ·  view source on GitHub ↗
(weights: Dict[str, Any])

Source from the content-addressed store, hash-verified

131
132def _normalize_weight_map(weights: Dict[str, Any]) -> Dict[str, float]:
133 normalized: Dict[str, float] = {}
134 for key, value in (weights or {}).items():
135 topic = str(key or "").strip()
136 if not topic:
137 continue
138 try:
139 numeric = float(value)
140 except (TypeError, ValueError):
141 continue
142 if numeric <= 0:
143 continue
144 normalized[topic] = round(min(1.0, numeric), 4)
145
146 max_score = max(normalized.values(), default=0.0)
147 if max_score > 1.0:
148 normalized = {key: round(value / max_score, 4) for key, value in normalized.items()}
149
150 return normalized
151
152
153def _ensure_anchor_state(profile: Dict[str, Any]) -> Dict[str, Any]:
154 drift_state = copy.deepcopy(profile.get("drift_state", {}) or {})

Callers 2

_advance_anchor_profileFunction · 0.85
advance_anchor_recoveryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected