Skip to content

Commit 061942b

Browse files
authored
BUG: incorrect gaussian kernel on Graph (#789)
1 parent dd862be commit 061942b

File tree

4 files changed

+40
-40
lines changed

4 files changed

+40
-40
lines changed

libpysal/graph/_kernel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def _parabolic(distances, bandwidth):
3434

3535
def _gaussian(distances, bandwidth):
3636
u = distances / bandwidth
37-
return numpy.exp(-((u / 2) ** 2)) / (numpy.sqrt(2) * numpy.pi)
37+
return numpy.exp(-((u / 2) ** 2)) / (numpy.sqrt(2 * numpy.pi))
3838

3939

4040
def _bisquare(distances, bandwidth):

libpysal/graph/tests/test_builders.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -237,26 +237,26 @@ def test_kernel_precompute(self):
237237
g = graph.Graph.build_kernel(distmat, metric="precomputed")
238238
expected = np.array(
239239
[
240-
0.07131664,
241-
0.14998932,
242-
0.09804811,
243-
0.0402638,
244-
0.07131664,
245-
0.18556845,
246-
0.17529176,
247-
0.16394507,
248-
0.14998932,
249-
0.18556845,
250-
0.17495794,
251-
0.11561449,
252-
0.09804811,
253-
0.17529176,
254-
0.17495794,
255-
0.19116432,
256-
0.0402638,
257-
0.16394507,
258-
0.11561449,
259-
0.19116432,
240+
0.126,
241+
0.266,
242+
0.174,
243+
0.071,
244+
0.126,
245+
0.329,
246+
0.311,
247+
0.291,
248+
0.266,
249+
0.329,
250+
0.31,
251+
0.205,
252+
0.174,
253+
0.311,
254+
0.31,
255+
0.339,
256+
0.071,
257+
0.291,
258+
0.205,
259+
0.339,
260260
]
261261
)
262262

libpysal/graph/tests/test_kernel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ def test_kernels(kernel, grocs):
210210
assert weight.mean() == pytest.approx(0.10312196315841769)
211211
assert weight.max() == pytest.approx(0.749881829575671)
212212
elif kernel == "gaussian":
213-
assert weight.mean() == pytest.approx(0.1124559308071747)
214-
assert weight.max() == pytest.approx(0.22507021331712948)
213+
assert weight.mean() == pytest.approx(0.19932294761630429)
214+
assert weight.max() == pytest.approx(0.3989265663183409)
215215
elif kernel == "bisquare":
216216
assert weight.mean() == pytest.approx(0.09084085210598618)
217217
assert weight.max() == pytest.approx(0.9372045972129259)

libpysal/graph/tests/test_triangulation.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -259,26 +259,26 @@ def test_kernel():
259259
_, _, weight = _delaunay(cau_coords, kernel="gaussian")
260260
expected = np.array(
261261
[
262-
0.1305618,
263-
0.17359059,
264-
0.22312817,
265-
0.1305618,
266-
0.1339654,
267-
0.03259559,
268-
0.17359059,
269-
0.1339654,
270-
0.06948067,
271-
0.180294,
272-
0.03259559,
273-
0.06948067,
274-
0.02004257,
275-
0.22312817,
276-
0.180294,
277-
0.02004257,
262+
0.231415,
263+
0.307681,
264+
0.395484,
265+
0.231415,
266+
0.237447,
267+
0.057774,
268+
0.307681,
269+
0.237447,
270+
0.123151,
271+
0.319563,
272+
0.057774,
273+
0.123151,
274+
0.035525,
275+
0.395484,
276+
0.319563,
277+
0.035525,
278278
]
279279
)
280280

281-
np.testing.assert_array_almost_equal(expected, weight)
281+
np.testing.assert_array_almost_equal(weight, expected)
282282

283283

284284
@pytest.mark.network

0 commit comments

Comments
 (0)