Skip to content

Commit

Permalink
fix: avg_comp_isolation = 0 if only one component
Browse files Browse the repository at this point in the history
  • Loading branch information
herbiebradley committed Mar 11, 2021
1 parent 051ac83 commit f5b80c0
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/models/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,24 @@ def _avg_component_isolation(geo_graph: geograph.GeoGraph) -> Metric:
raise ValueError(
"This metric is not valid for ComponentGeoGraphs without distance edges."
)

dist_set = set()
for comp in comp_geograph.graph.nodes:
for nbr in comp_geograph.graph.adj[comp]:
dist_set.update(
[
dist
for u, v, dist in comp_geograph.graph.edges(nbr, data="distance")
if v != comp
]
)
mean_patch_isolation = np.mean(np.fromiter(dist_set, np.float32, len(dist_set)))
if len(comp_geograph.components_list) == 1:
val: Any = 0
else:
dist_set = set()
for comp in comp_geograph.graph.nodes:
for nbr in comp_geograph.graph.adj[comp]:
dist_set.update(
[
dist
for u, v, dist in comp_geograph.graph.edges(
nbr, data="distance"
)
if v != comp
]
)
val = np.mean(np.fromiter(dist_set, np.float32, len(dist_set)))
return Metric(
value=mean_patch_isolation,
value=val,
name="avg_component_isolation",
description="The average distance to the next-nearest component",
variant="component",
Expand Down

0 comments on commit f5b80c0

Please sign in to comment.