INNER CODE UNIT · Python
simplify_graph
astroautomata/SymbolicRegression.jl · benchmark/family_tree.py:119
def simplify_graph(G):
"""Create a simplified version with only essential attributes"""
simple_G = nx.DiGraph()
for node, data in G.nodes(data=True):
# Keep full tree and add a truncated version for display
tree = data.get("tree", "No equation")
display_tree = str(tree)
if len(display_tree) > 30: # Truncate long equations
display_tree = display_tree[:27] + "..."
simple_G.add_node(
node,
cost=data.get("cost"),
loss=data.get("loss"),
tree=tree,
display_tree=display_tree,
)