@@ -1080,7 +1080,14 @@ def silence_metrics(
10801080def expansion_metrics (
10811081 G : TNFRGraph , node : NodeId , vf_before : float , epi_before : float
10821082) -> dict [str , Any ]:
1083- """VAL - Expansion metrics: νf increase, volume exploration.
1083+ """VAL - Enhanced expansion metrics with structural fidelity indicators.
1084+
1085+ Collects comprehensive metrics that reflect canonical VAL effects:
1086+ - **Structural dilation**: EPI and νf increases
1087+ - **Bifurcation risk**: ∂²EPI/∂t² threshold monitoring
1088+ - **Coherence gradient**: Impact on local/global coherence
1089+ - **Network impact**: Affected neighbors and coupling changes
1090+ - **Fractality preservation**: Structural complexity indicators
10841091
10851092 Parameters
10861093 ----------
@@ -1096,19 +1103,136 @@ def expansion_metrics(
10961103 Returns
10971104 -------
10981105 dict
1099- Expansion-specific metrics including structural dilation
1106+ Comprehensive expansion metrics including:
1107+
1108+ **Core Metrics**:
1109+ - operator, glyph: Identification
1110+ - vf_increase, vf_final: Frequency changes
1111+ - delta_epi, epi_final: EPI changes
1112+ - expansion_factor: Relative νf increase
1113+
1114+ **Structural Metrics** (NEW):
1115+ - dnfr_final: Final reorganization gradient
1116+ - d2epi: EPI acceleration (∂²EPI/∂t²)
1117+ - bifurcation_risk: Boolean flag if d²EPI/dt² > τ
1118+ - coherence_local: Local coherence after expansion
1119+ - phase_final: Final phase alignment
1120+
1121+ **Network Metrics** (NEW):
1122+ - neighbor_count: Number of connected neighbors
1123+ - network_impact_radius: Boolean if has neighbors
1124+ - degree_change: Change in node degree (if applicable)
1125+
1126+ **Fractality Indicators** (NEW):
1127+ - structural_complexity_increase: Relative EPI growth
1128+ - frequency_complexity_ratio: νf/EPI growth ratio
1129+ - expansion_quality: "coherent" if metrics healthy, else "unstable"
1130+
1131+ Examples
1132+ --------
1133+ >>> from tnfr.structural import create_nfr, run_sequence
1134+ >>> from tnfr.operators.definitions import Expansion
1135+ >>>
1136+ >>> G, node = create_nfr("test", epi=0.5, vf=2.0)
1137+ >>> G.graph["COLLECT_OPERATOR_METRICS"] = True
1138+ >>> G.nodes[node]['delta_nfr'] = 0.1
1139+ >>>
1140+ >>> # Apply expansion
1141+ >>> Expansion()(G, node, collect_metrics=True)
1142+ >>>
1143+ >>> # Metrics include bifurcation_risk, coherence_local, etc.
1144+
1145+ Notes
1146+ -----
1147+ These metrics enable monitoring of:
1148+ 1. **Bifurcation readiness**: d²EPI/dt² > τ signals reorganization threshold
1149+ 2. **Coherence preservation**: Expansion should maintain or increase coherence
1150+ 3. **Fractality**: Self-similar growth patterns indicated by complexity ratios
1151+ 4. **Network coupling**: Impact on surrounding nodes
1152+
1153+ See Also
1154+ --------
1155+ Expansion : VAL operator that produces these metrics
1156+ validate_expansion : Preconditions ensuring valid expansion
11001157 """
1158+ # Existing metrics
11011159 vf_after = _get_node_attr (G , node , ALIAS_VF )
11021160 epi_after = _get_node_attr (G , node , ALIAS_EPI )
1103-
1161+
1162+ # NEW: Additional structural parameters
1163+ dnfr = _get_node_attr (G , node , ALIAS_DNFR )
1164+ d2epi = _get_node_attr (G , node , ALIAS_D2EPI )
1165+ theta = _get_node_attr (G , node , ALIAS_THETA )
1166+
1167+ # NEW: Bifurcation risk assessment
1168+ tau = float (G .graph .get ("BIFURCATION_THRESHOLD_TAU" , 0.5 ))
1169+ bifurcation_risk = abs (d2epi ) > tau
1170+
1171+ # NEW: Network impact metrics
1172+ neighbors = list (G .neighbors (node ))
1173+ neighbor_count = len (neighbors )
1174+ network_impact_radius = neighbor_count > 0
1175+
1176+ # NEW: Coherence metrics (if available)
1177+ try :
1178+ from ..telemetry import compute_local_coherence
1179+ coherence_local = compute_local_coherence (G , node )
1180+ except (ImportError , AttributeError ):
1181+ # Fallback if telemetry not available
1182+ coherence_local = None
1183+
1184+ # NEW: Fractality and complexity indicators
1185+ delta_epi = epi_after - epi_before
1186+ delta_vf = vf_after - vf_before
1187+
1188+ structural_complexity_increase = (
1189+ (delta_epi / epi_before ) if epi_before > 0 else 0.0
1190+ )
1191+
1192+ frequency_complexity_ratio = (
1193+ (delta_vf / delta_epi ) if delta_epi > 0 else 0.0
1194+ )
1195+
1196+ # NEW: Expansion quality assessment
1197+ expansion_quality = "coherent"
1198+ if bifurcation_risk :
1199+ expansion_quality = "threshold" # At bifurcation point
1200+ if dnfr < 0 :
1201+ expansion_quality = "unstable" # Negative ΔNFR (shouldn't happen)
1202+ if delta_epi <= 0 or delta_vf <= 0 :
1203+ expansion_quality = "ineffective" # No actual expansion occurred
1204+
11041205 return {
1206+ # Core identification
11051207 "operator" : "Expansion" ,
11061208 "glyph" : "VAL" ,
1107- "vf_increase" : vf_after - vf_before ,
1209+
1210+ # Existing metrics
1211+ "vf_increase" : delta_vf ,
11081212 "vf_final" : vf_after ,
1109- "delta_epi" : epi_after - epi_before ,
1213+ "delta_epi" : delta_epi ,
11101214 "epi_final" : epi_after ,
11111215 "expansion_factor" : vf_after / vf_before if vf_before > 0 else 1.0 ,
1216+
1217+ # NEW: Structural metrics
1218+ "dnfr_final" : dnfr ,
1219+ "d2epi" : d2epi ,
1220+ "bifurcation_risk" : bifurcation_risk ,
1221+ "bifurcation_threshold" : tau ,
1222+ "coherence_local" : coherence_local ,
1223+ "phase_final" : theta ,
1224+
1225+ # NEW: Network impact
1226+ "neighbor_count" : neighbor_count ,
1227+ "network_impact_radius" : network_impact_radius ,
1228+
1229+ # NEW: Fractality indicators
1230+ "structural_complexity_increase" : structural_complexity_increase ,
1231+ "frequency_complexity_ratio" : frequency_complexity_ratio ,
1232+ "expansion_quality" : expansion_quality ,
1233+
1234+ # Metadata
1235+ "metrics_version" : "2.0_canonical" ,
11121236 }
11131237
11141238
0 commit comments