From 2a6010634417eac9bf2ac4682ac3675dc5074518 Mon Sep 17 00:00:00 2001 From: jeanpouget-abadie Date: Sun, 30 Nov 2014 11:13:23 -0500 Subject: correctness measure --- jpa_test/algorithms.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'jpa_test/algorithms.py') diff --git a/jpa_test/algorithms.py b/jpa_test/algorithms.py index 7cdf093..2a32f57 100644 --- a/jpa_test/algorithms.py +++ b/jpa_test/algorithms.py @@ -30,6 +30,19 @@ def greedy_prediction(G, cascades): if (cascade.infection_time(parent) == \ [item - 1 for item in cascade.infection_time(node)]): unaccounted[t] = False + return G_hat + + +def correctness_measure(G, G_hat): + """ + Measures correctness of estimated graph G_hat to ground truth G + """ + edges = set(G.edges()) + edges_hat = set(G_hat.edges()) + fp = edges_hat - edges + fn = edges - edges_hat + gp = edges | edges_hat + return fp, fn, gp def test(): @@ -37,11 +50,15 @@ def test(): unit test """ G = cascade_creation.InfluenceGraph(max_proba = .3) - G.erdos_init(n = 100, p = 1) + G.erdos_init(n = 100, p = .1) import time t0 = time.time() - A = cascade_creation.generate_cascades(G, .1, 4) - greedy_prediction(G, A) + A = cascade_creation.generate_cascades(G, .1, 100) + G_hat = greedy_prediction(G, A) + fp, fn, gp = correctness_measure(G, G_hat) + print "False Positive: {}".format(len(fp)) + print "False Negative: {}".format(len(fn)) + print "Good Positives: {}".format(len(gp)) t1 = time.time() print t1 - t0 -- cgit v1.2.3-70-g09d2