def test_katz_sim(self): G = self.G katz_sim, nodelist = katz(G) nt.assert_equal(len(nodelist), 6) for i in range(6): nt.assert_true(i in nodelist) nt.assert_equal(len(katz_sim), 6) for i in range(self.G.katz_sim.shape[0]): for j in range(self.G.katz_sim.shape[1]): print i, ',', j nt.assert_almost_equal(self.G.katz_sim[i,j], katz_sim[i,j], places=4)
def test_katz_sim(self): G = self.G katz_sim, nodelist = katz(G) nt.assert_equal(len(nodelist), 6) for i in range(6): nt.assert_true(i in nodelist) nt.assert_equal(len(katz_sim), 6) for i in range(self.G.katz_sim.shape[0]): for j in range(self.G.katz_sim.shape[1]): print i, ',', j nt.assert_almost_equal(self.G.katz_sim[i, j], katz_sim[i, j], places=4)
### VERTEX SIMILARITY graphs = pickle.load(open('data/graphs_networkx.pkl', 'rb')) results = dict() for graph_type, G in graphs.iteritems(): print "Calculating for %s" % (graph_type) results[graph_type] = dict() print "ASCOS ---------------------------" results[graph_type]["ascos"] = ascos(G) print "COSINE ---------------------------" results[graph_type]["cosine"] = cosine(G) print "JACCARD --------------------------" results[graph_type]["jaccard"] = jaccard(G) print "KATZ -----------------------------" results[graph_type]["katz"] = katz(G) print "LHN ------------------------------" results[graph_type]["lhn"] = lhn(G) print "RSS2 -----------------------------" results[graph_type]["rss2"] = rss2(G) print "DICE -----------------------------" results[graph_type]["dice"] = dice(G) print "INVERSE LOG WEIGHTED --------------" results[graph_type]["inverse_log_weighted"] = inverse_log_weighted(G) pickle.dump(results, open("data/sim_metrics.pkl", "wb")) ### IMAGE SIMILARITY # Let's make a concept by concept data frame contrast_lookup = pandas.read_csv("data/contrast_by_concept_binary_df.tsv",
### VERTEX SIMILARITY graphs = pickle.load(open('data/graphs_networkx.pkl','rb')) results = dict() for graph_type,G in graphs.iteritems(): print "Calculating for %s" %(graph_type) results[graph_type] = dict() print "ASCOS ---------------------------" results[graph_type]["ascos"] = ascos(G) print "COSINE ---------------------------" results[graph_type]["cosine"] = cosine(G) print "JACCARD --------------------------" results[graph_type]["jaccard"] = jaccard(G) print "KATZ -----------------------------" results[graph_type]["katz"] = katz(G) print "LHN ------------------------------" results[graph_type]["lhn"] = lhn(G) print "RSS2 -----------------------------" results[graph_type]["rss2"] = rss2(G) print "DICE -----------------------------" results[graph_type]["dice"] = dice(G) print "INVERSE LOG WEIGHTED --------------" results[graph_type]["inverse_log_weighted"] = inverse_log_weighted(G) pickle.dump(results,open("data/sim_metrics.pkl","wb")) ### IMAGE SIMILARITY # Let's make a concept by concept data frame contrast_lookup = pandas.read_csv("data/contrast_by_concept_binary_df.tsv",sep="\t",index_col=0)