File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -445,6 +445,48 @@ def test_random_landmarking_with_precomputed_affinity():
445445 assert G .landmark_op .shape == (n_landmark , n_landmark )
446446
447447
448+ def test_random_landmarking_with_precomputed_distance ():
449+ """Random landmarking should work with precomputed distance matrices"""
450+ dist = np .array (
451+ [
452+ [0 , 1 , 4 , 4 , 4 , 4 ],
453+ [1 , 0 , 4 , 4 , 4 , 4 ],
454+ [4 , 4 , 0 , 1 , 4 , 4 ],
455+ [4 , 4 , 1 , 0 , 4 , 4 ],
456+ [4 , 4 , 4 , 4 , 0 , 1 ],
457+ [4 , 4 , 4 , 4 , 1 , 0 ],
458+ ]
459+ )
460+
461+ n_landmark = 3
462+ random_state = 42
463+
464+ G = graphtools .Graph (
465+ dist ,
466+ precomputed = "distance" ,
467+ n_landmark = n_landmark ,
468+ random_landmarking = True ,
469+ random_state = random_state ,
470+ bandwidth = 1 , # deterministic affinity: exp(-dist)
471+ decay = 1 ,
472+ thresh = 0 ,
473+ knn = 3 ,
474+ )
475+
476+ # Trigger landmark construction
477+ _ = G .landmark_op
478+
479+ rng = np .random .default_rng (random_state )
480+ landmark_indices = rng .choice (dist .shape [0 ], n_landmark , replace = False )
481+ expected_clusters = np .asarray (
482+ G .kernel [:, landmark_indices ].argmax (axis = 1 )
483+ ).reshape (- 1 )
484+
485+ assert np .array_equal (G .clusters , expected_clusters )
486+ assert G .transitions .shape == (dist .shape [0 ], n_landmark )
487+ assert G .landmark_op .shape == (n_landmark , n_landmark )
488+
489+
448490#############
449491# Test API
450492#############
You can’t perform that action at this time.
0 commit comments