poi_gdf["cx"] = poi_gdf.geometry.x
poi_gdf["cy"] = poi_gdf.geometry.y
Coords = Poi_gdf[["cx", "cy"]].to_numpy()
nn = NearestNeighbors(radius=150.0).fit(coords)
poi_gdf["local_density"] = [len(idx) - 1 for idx in nn.radius_neighbors(coords, return_distance=False)]
If segments_gdf does not equal None, and len (segments_gdf), then:
try:
joined = gpd.sjoin_nearest(poi_gdf[["geometry"]], segments_gdf[["geometry"]],
distance_col="dist_street")
poi_gdf["dist_street"] = joined.groupby(level=0)["dist_street"].min().reindex(poi_gdf.index).fillna(0.0)
Except Exception
poi_gdf["dist_street"] = 0.0
else:
poi_gdf["dist_street"] = 0.0
poi_gdf["category"] = poi_gdf["category"].astype("category")
poi_gdf["label"] = poi_gdf["category"].cat.codes.astype(int)
CLASS_NAMES = list(poi_gdf["category"].cat.categories)
print("Classes:", CLASS_NAMES)
def graph_stats (name, builder:
try:
Builder = nodes + edges()
deg = pd.Series(np.r_[edges.index.get_level_values(0),
edges.index.get_level_values(1)]).value_counts()
return name, len(edges), round(deg.mean(), 2), (nodes, edges)
Except Exception As e.
The return number is fBuilders ="ERR: {e}", None, None
builders = {
"KNN (k=8)": lambda: c2g.knn_graph(poi_gdf, distance_metric="euclidean", k=8, as_nx=False),
"Delaunay": lambda: c2g.delaunay_graph(poi_gdf, as_nx=False),
"Gabriel": lambda: c2g.gabriel_graph(poi_gdf, as_nx=False),
"RNG": lambda: c2g.relative_neighborhood_graph(poi_gdf, as_nx=False),
"EMST": lambda: c2g.euclidean_minimum_spanning_tree(poi_gdf, as_nx=False),
"Waxman": lambda: c2g.waxman_graph(poi_gdf, distance_metric="euclidean", r0=150, beta=0.6),
}
print("n--- Proximity graph comparison ---")
print(f"{'graph':10}{'avg_degree':>12}")
built = {}
Builders.items for nm and b():
name, ne, avgdeg, payload = graph_stats(nm, b)
print(f"{name:10}{str(avgdeg):>12}")
If payload is built[nm] The payload
Axes = plt.subplots (1, 3, figsize=(16, 5 )
for ax, key in zip(axes, ["KNN (k=8)", "Delaunay", "EMST"]):
If key is built in:
Built = n_, E_[key]
e_.plot(ax=ax, linewidth=0.4, color="#3b7dd8", alpha=0.6)
poi_gdf.plot(ax=ax, markersize=4, color="#d83b5c")
ax.set_title(key); ax.set_axis_off()
plt.suptitle("Spatial graph topologies on the same POI set", y=1.02)
plt.tight_layout(); plt.show()
Trending
- Perplexity Trains Its Pc Agent on Actual Errors With Trace-Guided Self-Distillation
- Appeals Court docket Lets the Pentagon Designate Anthropic a Provide-Chain Threat
- Aikido Safety Releases Altar-1: An Open-Weight Safety Mannequin Pruned From GLM-5.3 to 328 GB
- Black Forest Labs Releases FLUX 3 Motion: A 7B Open-Weights World Motion Mannequin That Tops RoboLab-120
- Fastino Releases GLiNER2.5-Resolve: A 340M Open-Weight Determination Mannequin That Runs on CPU
- BottleCap AI Releases ThinkingCap-Qwen3.8-27B: 37.2% Fewer Considering Tokens at a 0.86pp Accuracy Price
- What if I find an AI agent that is worth the risk?
- Google’s Gemini Can Now Make Requires You on Pixel Telephones

