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 is not None and len(segments_gdf):
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:
nodes, edges = builder()
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:
return name, f”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’:<14}{‘#edges’:>10}{‘avg_degree’:>12}”)
built = {}
for nm, b in builders.items():
name, ne, avgdeg, payload = graph_stats(nm, b)
print(f”{name:<14}{str(ne):>10}{str(avgdeg):>12}”)
if payload: built[nm] = payload
fig, axes = plt.subplots(1, 3, figsize=(16, 5))
for ax, key in zip(axes, [“KNN (k=8)”, “Delaunay”, “EMST”]):
if key in built:
n_, e_ = built[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
- Parse PDFs for RAG Locally with Docling: Rich Tables, No Cloud Upload
- A Coding Implementation on Spatial Graph Neural Networks for Urban Function Inference Using city2graph, OSMnx, and PyTorch Geometric
- Anthropic Disables Claude Fable 5 and Mythos 5 After US Government Order
- Is Language Visual? An Experiment with Chinese Characters
- Moonshot AI Releases Kimi K2.7-Code: a Coding Model Reporting +21.8% on Kimi Code Bench v2 Over K2.6
- Can you do the 'Asian squat'?
- A Harness for Every Task: Putting a Team of Claudes on One Job
- Exeter College opens lifelike hospital training ward
Related Posts
Add A Comment
Subscribe to Updates
Get the latest creative news from FooBar about art, design and business.
© 2026 insureai360. Designed by Pro.
