Skip to content

Commit

Permalink
nngraph: width = radius / 2
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeff committed Feb 24, 2019
1 parent 5c2e856 commit 011dc81
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions pygsp/graphs/nngraphs/nngraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ class NNGraph(Graph):
Control the width, also known as the bandwidth, :math:`\sigma` of the
kernel by scaling the distances as ``distances / kernel_width`` before
calling the kernel function.
By default, it is set to the average of all computed distances.
By default, it is set to the average of all computed distances for
``kind='knn'`` and to half the radius for ``kind='radius'``.
When building a radius graph, it's common to set it as a function of
the radius, such as ``radius / 2``.
backend : string, optional
Expand Down Expand Up @@ -362,7 +363,10 @@ def __init__(self, features, standardize=False,
W = utils.symmetrize(W, method='fill')

if kernel_width is None:
kernel_width = np.mean(W.data) if W.nnz > 0 else np.nan
if kind == 'knn':
kernel_width = np.mean(W.data) if W.nnz > 0 else np.nan
elif kind == 'radius':
kernel_width = radius / 2

if not callable(kernel):
try:
Expand Down
2 changes: 1 addition & 1 deletion pygsp/tests/test_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def test_nngraph(self, n_vertices=24):
else:
params['backend'] = backend
if backend == 'flann':
graph = Graph(random_seed=0, **params)
graph = Graph(random_seed=40, **params)
else:
graph = Graph(**params)
np.testing.assert_allclose(graph.W.toarray(),
Expand Down

0 comments on commit 011dc81

Please sign in to comment.