spamosaic.build_graph.determine_kSize
- spamosaic.build_graph.determine_kSize(adi, adj, knn_base, auto_thr)[source]
Dynamically determine the number of nearest neighbors for KNN search between two datasets of potentially imbalanced sizes.
This function adjusts the KNN size based on the relative number of observations between adi and adj. If the dataset sizes are sufficiently similar (i.e., ratio >= auto_thr), both sides use the same base KNN. Otherwise, the smaller dataset uses a scaled-down KNN count to balance the search.
- Parameters:
adi (AnnData) – First AnnData object.
adj (AnnData) – Second AnnData object.
knn_base (int) – Base number of nearest neighbors.
auto_thr (float) – Size similarity threshold (e.g., 0.8). If the ratio of smaller to larger dataset exceeds this, no scaling is applied.
- Returns:
Tuple of (knn_adi, knn_adj) representing KNN sizes for each dataset.
- Return type:
Tuple[int, int]