mixle.utils.hvis.neighbors moduleΒΆ
Sparse model-distance graphs, random-projection trees, and kNN.
Builds the sparse neighbor graphs (exact blockwise top-k and the approximate random-projection-forest variant) and the umap-style kNN arrays under the model distance d_ij = -log s_ij. The dense affinity matrix is never materialized.
- sparse_model_distances(posterior_mat, ll_mat=None, k=90, block_size=1024, affinity='bhattacharyya', evidence_cap=None)[source]
Sparse n x n matrix of model distances d_ij = -log s_ij.
Keeps the k nearest neighbors (largest affinity) per row. Built blockwise so the dense n x n affinity matrix is never materialized. Distances are non-negative. evidence_cap as in model_log_affinity.
- approx_sparse_model_distances(posterior_mat, ll_mat=None, k=90, affinity='bhattacharyya', evidence_cap=None, n_trees=8, leaf_size=None, candidate_multiplier=8, seed=None)[source]
Approximate sparse model distances without all-pairs graph construction.
A random-projection forest proposes candidate neighbors in normalized model-factor coordinates. Candidate pairs are then rescored with the exact model affinity used by sparse_model_distances, so approximation only enters through candidate recall. This is local/non-distributed today, but the proposal/evaluation split is the intended boundary for future distributed graph construction.
- model_knn(posterior_mat, ll_mat=None, k=15, block_size=1024, affinity='bhattacharyya', evidence_cap=None)[source]
k-nearest-neighbor arrays under the model distance d_ij = -log s_ij.
Returns (indices, distances), each n x k, sorted ascending per row with each point as its own first neighbor at distance 0 (the convention expected by umap-learn, where self counts toward n_neighbors). Built blockwise; the dense affinity matrix is never materialized. evidence_cap as in model_log_affinity.