Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions libpysal/weights/gabriel.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ def _filter_relativehood(edges, coordinates, return_dkmax=False):
2. for each edge of the delaunay (i,j), compute
dkmax = max(d(k,i), d(k,j)) for k in 1..n, k != i, j
3. for each edge of the delaunay (i,j), prune
if any dkmax is greater than d(i,j)
if any dkmax is smaller than d(i,j)
"""
n = edges.max()
n = len(coordinates)
out = []
r = []
for edge in edges:
Expand All @@ -345,11 +345,12 @@ def _filter_relativehood(edges, coordinates, return_dkmax=False):
dij = ((pi - pj) ** 2).sum() ** 0.5
prune = False
for k in range(n):
if k in (i, j):
continue
pk = coordinates[k]
dik = ((pi - pk) ** 2).sum() ** 0.5
djk = ((pj - pk) ** 2).sum() ** 0.5
distances = numpy.array([dik, djk, dkmax])
dkmax = distances.max()
dkmax = max(dik, djk)
prune = dkmax < dij
if (not return_dkmax) & prune:
break
Expand Down
6 changes: 5 additions & 1 deletion libpysal/weights/tests/test_gabriel.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ def test_rng():

assert e.neighbors == f.neighbors

# RNG should be a subgraph of Delaunay
for k, neighbors in e.neighbors.items():
assert set(neighbors) <= set(dty[k])

assert e[1] != dty[1]
assert list(e[1].keys()) == [0, 3, 6, 30, 38]
assert list(e[1].keys()) == [0, 3]
for focal, neighbors in e.neighbors.items():
dneighbors = dty[focal]
assert set(neighbors) <= set(dneighbors)
Loading