swnn.stagewise_knn

swnn.stagewise_knn(X, stage_lbs, stage_order, leaf_size=5, n_pcs=30, k=30, pca_base_on='stack', binary_edge=True, norm_dists=False, **kwargs)

Build multipartite KNN-graph stage-by-stage.

Parameters
  • X (np.ndarray or sparse matrix) – data matrix, of shape (n_samples, n_features)

  • stage_lbs (Sequence) – stage labels for each sample (nodes in build_graph)

  • stage_order (Sequence) – stage order

  • binary_edge (bool (default=True)) – whether to use the binarized edges. Set as True may cause some information loss but a more robust result.

  • k (Union[Sequence[int], int]) – the number of nearest neighbors to be calculated.

  • n_pcs (Union[Sequence[int], int]) – The number of principal components after PCA reduction. If pca_base_on is None, this will be ignored.

  • pca_base_on (str {'x1', 'x2', 'stacked', None} (default='stacked')) – if None, perform KNN on the original data space.

  • leaf_size (int (default=5)) – Leaf size passed to BallTree or KDTree, for adjusting the approximation level. The higher the faster, while of less promises to find the exact nearest neighbors. Setting as 1 for brute-force (exact) KNN.

  • norm_dists (bool) – whether to normalize the distance for each pair of adjacent-stages.

Returns

  • distmat (sparse.csr_matrix) – the distance matrix, of shape (n_samples, n_samples)

  • connect (sparse.csr_matrix) – the connectivities matrix, of shape (n_samples, n_samples)