def make_feats(g): counts5 = np.array(orca.orbit_counts("node", 5, g)) for v, n in zip(counts5, g.nodes): if g.nodes[n]["node_feature"][0] > 0: anchor_v = v break v5 = np.sum(counts5, axis=0) return v5, anchor_v
def count_exact(queries, targets, args): print("WARNING: orca only works for node anchored") # TODO: non node anchored n_matches_baseline = np.zeros(73) for target in targets: counts = np.array(orca.orbit_counts("node", 5, target)) if args.count_method == "bin": counts = np.sign(counts) counts = np.sum(counts, axis=0) n_matches_baseline += counts # don't include size < 5 n_matches_baseline = list(n_matches_baseline)[15:] counts5 = [] num5 = 10 #len([q for q in queries if len(q) == 5]) for x in list(sorted(n_matches_baseline, reverse=True))[:num5]: print(x) counts5.append(x) print("Average for size 5:", np.mean(np.log10(counts5))) atlas = [ g for g in nx.graph_atlas_g()[1:] if nx.is_connected(g) and len(g) == 6 ] queries = [] for g in atlas: for v in g.nodes: g = g.copy() nx.set_node_attributes(g, 0, name="anchor") g.nodes[v]["anchor"] = 1 is_dup = False for g2 in queries: if nx.is_isomorphic( g, g2, node_match=(lambda a, b: a["anchor"] == b["anchor"]) if args.node_anchored else None): is_dup = True break if not is_dup: queries.append(g) print(len(queries)) n_matches_baseline = count_graphlets(queries, targets, n_workers=args.n_workers, method=args.count_method, node_anchored=args.node_anchored, min_count=10000) counts6 = [] num6 = 20 #len([q for q in queries if len(q) == 6]) for x in list(sorted(n_matches_baseline, reverse=True))[:num6]: print(x) counts6.append(x) print("Average for size 6:", np.mean(np.log10(counts6))) return counts5 + counts6
import orca import networkx as nx counts = orca.orbit_counts("node", 5, nx.gnm_random_graph(30, 100)) print(f'Number of nodes: {len(counts)}') print(f'Number of graphlets: {len(counts[0])}') print('Counts: ', counts)