From 011dc8159e1e7ee816d02a008b494e935d4b65fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Defferrard?= Date: Sun, 24 Feb 2019 23:54:27 +0100 Subject: [PATCH] nngraph: width = radius / 2 --- pygsp/graphs/nngraphs/nngraph.py | 8 ++++++-- pygsp/tests/test_graphs.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pygsp/graphs/nngraphs/nngraph.py b/pygsp/graphs/nngraphs/nngraph.py index 21d0ccd3..506866e7 100644 --- a/pygsp/graphs/nngraphs/nngraph.py +++ b/pygsp/graphs/nngraphs/nngraph.py @@ -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 @@ -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: diff --git a/pygsp/tests/test_graphs.py b/pygsp/tests/test_graphs.py index 2450fe90..94ebe2fa 100644 --- a/pygsp/tests/test_graphs.py +++ b/pygsp/tests/test_graphs.py @@ -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(),