@@ -103,7 +103,7 @@ def test_k_too_large():
103103 build_graph (data ,
104104 n_pca = 20 ,
105105 decay = 10 ,
106- knn = len (data ) + 1 ,
106+ knn = len (data ) - 1 ,
107107 thresh = 0 )
108108
109109
@@ -131,7 +131,7 @@ def test_exact_graph():
131131 np .fill_diagonal (W , 0 )
132132 G = pygsp .graphs .Graph (W )
133133 G2 = build_graph (data_small , thresh = 0 , n_pca = n_pca ,
134- decay = a , knn = k , random_state = 42 ,
134+ decay = a , knn = k - 1 , random_state = 42 ,
135135 bandwidth_scale = bandwidth_scale ,
136136 use_pygsp = True )
137137 assert (G .N == G2 .N )
@@ -141,7 +141,7 @@ def test_exact_graph():
141141 assert (isinstance (G2 , graphtools .graphs .TraditionalGraph ))
142142 G2 = build_graph (pdx , n_pca = None , precomputed = 'distance' ,
143143 bandwidth_scale = bandwidth_scale ,
144- decay = a , knn = k , random_state = 42 , use_pygsp = True )
144+ decay = a , knn = k - 1 , random_state = 42 , use_pygsp = True )
145145 assert (G .N == G2 .N )
146146 np .testing .assert_equal (G .dw , G2 .dw )
147147 assert ((G .W != G2 .W ).nnz == 0 )
@@ -195,7 +195,7 @@ def test_truncated_exact_graph():
195195 G2 = build_graph (data_small , thresh = thresh ,
196196 graphtype = 'exact' ,
197197 n_pca = n_pca ,
198- decay = a , knn = k , random_state = 42 ,
198+ decay = a , knn = k - 1 , random_state = 42 ,
199199 use_pygsp = True )
200200 assert (G .N == G2 .N )
201201 np .testing .assert_equal (G .dw , G2 .dw )
@@ -204,7 +204,7 @@ def test_truncated_exact_graph():
204204 assert (isinstance (G2 , graphtools .graphs .TraditionalGraph ))
205205 G2 = build_graph (pdx , n_pca = None , precomputed = 'distance' ,
206206 thresh = thresh ,
207- decay = a , knn = k , random_state = 42 , use_pygsp = True )
207+ decay = a , knn = k - 1 , random_state = 42 , use_pygsp = True )
208208 assert (G .N == G2 .N )
209209 np .testing .assert_equal (G .dw , G2 .dw )
210210 assert ((G .W != G2 .W ).nnz == 0 )
@@ -252,14 +252,14 @@ def test_truncated_exact_graph_sparse():
252252 G2 = build_graph (sp .coo_matrix (data_small ), thresh = thresh ,
253253 graphtype = 'exact' ,
254254 n_pca = n_pca ,
255- decay = a , knn = k , random_state = 42 ,
255+ decay = a , knn = k - 1 , random_state = 42 ,
256256 use_pygsp = True )
257257 assert (G .N == G2 .N )
258258 np .testing .assert_allclose (G2 .W .toarray (), G .W .toarray ())
259259 assert (isinstance (G2 , graphtools .graphs .TraditionalGraph ))
260260 G2 = build_graph (sp .bsr_matrix (pdx ), n_pca = None , precomputed = 'distance' ,
261261 thresh = thresh ,
262- decay = a , knn = k , random_state = 42 , use_pygsp = True )
262+ decay = a , knn = k - 1 , random_state = 42 , use_pygsp = True )
263263 assert (G .N == G2 .N )
264264 np .testing .assert_equal (G .dw , G2 .dw )
265265 assert ((G .W != G2 .W ).nnz == 0 )
@@ -304,7 +304,7 @@ def test_truncated_exact_graph_no_pca():
304304 G2 = build_graph (data_small , thresh = thresh ,
305305 graphtype = 'exact' ,
306306 n_pca = n_pca ,
307- decay = a , knn = k , random_state = 42 ,
307+ decay = a , knn = k - 1 , random_state = 42 ,
308308 use_pygsp = True )
309309 assert (G .N == G2 .N )
310310 np .testing .assert_equal (G .dw , G2 .dw )
@@ -314,7 +314,7 @@ def test_truncated_exact_graph_no_pca():
314314 G2 = build_graph (sp .csr_matrix (data_small ), thresh = thresh ,
315315 graphtype = 'exact' ,
316316 n_pca = n_pca ,
317- decay = a , knn = k , random_state = 42 ,
317+ decay = a , knn = k - 1 , random_state = 42 ,
318318 use_pygsp = True )
319319 assert (G .N == G2 .N )
320320 np .testing .assert_equal (G .dw , G2 .dw )
@@ -379,7 +379,7 @@ def test_exact_graph_callable_bandwidth():
379379 W = np .divide (K , 2 )
380380 np .fill_diagonal (W , 0 )
381381 G = pygsp .graphs .Graph (W )
382- G2 = build_graph (data , n_pca = n_pca , knn = knn ,
382+ G2 = build_graph (data , n_pca = n_pca , knn = knn - 1 ,
383383 decay = decay , bandwidth = bandwidth ,
384384 random_state = 42 ,
385385 thresh = thresh ,
@@ -396,7 +396,7 @@ def test_exact_graph_callable_bandwidth():
396396 W = np .divide (K , 2 )
397397 np .fill_diagonal (W , 0 )
398398 G = pygsp .graphs .Graph (W )
399- G2 = build_graph (data , n_pca = n_pca , knn = knn ,
399+ G2 = build_graph (data , n_pca = n_pca , knn = knn - 1 ,
400400 decay = decay , bandwidth = bandwidth ,
401401 random_state = 42 ,
402402 thresh = thresh ,
@@ -432,7 +432,7 @@ def test_exact_graph_anisotropy():
432432 np .fill_diagonal (W , 0 )
433433 G = pygsp .graphs .Graph (W )
434434 G2 = build_graph (data_small , thresh = 0 , n_pca = n_pca ,
435- decay = a , knn = k , random_state = 42 ,
435+ decay = a , knn = k - 1 , random_state = 42 ,
436436 use_pygsp = True , anisotropy = anisotropy )
437437 assert (isinstance (G2 , graphtools .graphs .TraditionalGraph ))
438438 assert (G .N == G2 .N )
@@ -441,15 +441,15 @@ def test_exact_graph_anisotropy():
441441 assert ((G .W != G2 .W ).nnz == 0 )
442442 assert_raises (ValueError , build_graph ,
443443 data_small , thresh = 0 , n_pca = n_pca ,
444- decay = a , knn = k , random_state = 42 ,
444+ decay = a , knn = k - 1 , random_state = 42 ,
445445 use_pygsp = True , anisotropy = - 1 )
446446 assert_raises (ValueError , build_graph ,
447447 data_small , thresh = 0 , n_pca = n_pca ,
448- decay = a , knn = k , random_state = 42 ,
448+ decay = a , knn = k - 1 , random_state = 42 ,
449449 use_pygsp = True , anisotropy = 2 )
450450 assert_raises (ValueError , build_graph ,
451451 data_small , thresh = 0 , n_pca = n_pca ,
452- decay = a , knn = k , random_state = 42 ,
452+ decay = a , knn = k - 1 , random_state = 42 ,
453453 use_pygsp = True , anisotropy = 'invalid' )
454454
455455#####################################################
@@ -462,32 +462,32 @@ def test_build_dense_exact_kernel_to_data(**kwargs):
462462 n = G .data .shape [0 ]
463463 K = G .build_kernel_to_data (data [:n // 2 , :])
464464 assert (K .shape == (n // 2 , n ))
465- K = G .build_kernel_to_data (G .data )
466- assert ( np .sum (G .kernel != (K + K .T ) / 2 ) == 0 )
467- K = G .build_kernel_to_data (G .data_nu )
468- assert ( np .sum (G .kernel != (K + K .T ) / 2 ) == 0 )
465+ K = G .build_kernel_to_data (G .data , knn = G . knn + 1 )
466+ np .testing . assert_equal (G .kernel - (K + K .T ) / 2 , 0 )
467+ K = G .build_kernel_to_data (G .data_nu , knn = G . knn + 1 )
468+ np .testing . assert_equal (G .kernel - (K + K .T ) / 2 , 0 )
469469
470470
471471def test_build_dense_exact_callable_bw_kernel_to_data (** kwargs ):
472472 G = build_graph (data , decay = 10 , thresh = 0 , bandwidth = lambda x : x .mean (1 ))
473473 n = G .data .shape [0 ]
474474 K = G .build_kernel_to_data (data [:n // 2 , :])
475475 assert (K .shape == (n // 2 , n ))
476- K = G .build_kernel_to_data (G .data )
477- assert ( np .sum (G .kernel != (K + K .T ) / 2 ) == 0 )
478- K = G .build_kernel_to_data (G .data_nu )
479- assert ( np .sum (G .kernel != (K + K .T ) / 2 ) == 0 )
476+ K = G .build_kernel_to_data (G .data , knn = G . knn + 1 )
477+ np .testing . assert_equal (G .kernel - (K + K .T ) / 2 , 0 )
478+ K = G .build_kernel_to_data (G .data_nu , knn = G . knn + 1 )
479+ np .testing . assert_equal (G .kernel - (K + K .T ) / 2 , 0 )
480480
481481
482482def test_build_sparse_exact_kernel_to_data (** kwargs ):
483483 G = build_graph (data , decay = 10 , thresh = 0 , sparse = True )
484484 n = G .data .shape [0 ]
485485 K = G .build_kernel_to_data (data [:n // 2 , :])
486486 assert (K .shape == (n // 2 , n ))
487- K = G .build_kernel_to_data (G .data )
488- assert ( np .sum (G .kernel != (K + K .T ) / 2 ) == 0 )
489- K = G .build_kernel_to_data (G .data_nu )
490- assert ( np .sum (G .kernel != (K + K .T ) / 2 ) == 0 )
487+ K = G .build_kernel_to_data (G .data , knn = G . knn + 1 )
488+ np .testing . assert_equal (G .kernel - (K + K .T ) / 2 , 0 )
489+ K = G .build_kernel_to_data (G .data_nu , knn = G . knn + 1 )
490+ np .testing . assert_equal (G .kernel - (K + K .T ) / 2 , 0 )
491491
492492
493493def test_exact_interpolate ():
0 commit comments