From 1fb56392a467e805457b5aad3edf74d65020676e Mon Sep 17 00:00:00 2001 From: Dimitri Lozeve Date: Thu, 14 Jun 2018 12:19:39 +0100 Subject: [PATCH] Implement weight rank clique filtration --- filtration.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 filtration.py diff --git a/filtration.py b/filtration.py new file mode 100644 index 0000000..99d7c3f --- /dev/null +++ b/filtration.py @@ -0,0 +1,21 @@ +import numpy as np +import igraph as ig +import dionysus as d + + +def wrcf(G, weight="weight"): + # Define filtration step 0 as the set of all nodes + filt = d.Filtration() + for v in G.vs: + filt.append(d.Simplex([v.index], 0)) + # Rank all edge weights + distinct_weights = np.unique(G.es[weight])[::-1] + for t, w in enumerate(distinct_weights): + # At filtration step t, threshold the graph at weight[t] + subg = G.subgraph_edges(G.es(lambda e: e[weight] >= w)) + # Find all maximal cliques and define them to be simplices + for clique in subg.maximal_cliques(): + for s in d.closure([d.Simplex(clique)], len(clique)): + filt.append(d.Simplex(s, t+1)) + filt.sort() + return(filt)