Open
Description
For a different causal inference project, I'm writing a few spatial/feature matching algorithms.
I think we may want to offer a Mutual_KNN()
constructor in Graph
, and also bring a Symmetric_KNN()
? or have symmetric/mutual
options in a knn constructor?
This is like the current .symmetrize()
function, but instead of adding edges to the KNN
graph to induce symmetry, it removes edges to the KNN
graph who are not mutually k-near.
This could also be implemented as a separate function for arbitrary graphs after weighting/kerneling, since it's just based on the edge set:
def mutual_knn(x, k=5):
graph = KNN.from_array(x, k=k)
directed_edges_array = graph.sparse != graph.sparse.T
removed = (graph.sparse - directed_edges_array) > 0
removed.eliminate_zeros()
return WSP2W(WSP(removed))
Activity