swnn.multipartite_graph module

swnn.multipartite_graph.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)

swnn.multipartite_graph.pca_transform(X1, X2=None, n_pcs=50, base_on='stacked', **kwargs)

base_on: {‘x1’, ‘x2’, ‘stacked’}

swnn.multipartite_graph.approx_knn(X_ref, X_que=None, metric='cosine', k=5, precis=0.1, leaf_size=5, leaf_size_max=30, algorithm='kd_tree', metric_params=None, **kwargs)
Parameters
  • algorithm ({'auto', 'ball_tree', 'kd_tree', 'brute'}) – default=’auto’

  • leaf_size (int, default=30) – Leaf size passed to BallTree or KDTree.