diff options
| author | jeanpouget-abadie <jean.pougetabadie@gmail.com> | 2014-11-30 11:13:23 -0500 |
|---|---|---|
| committer | jeanpouget-abadie <jean.pougetabadie@gmail.com> | 2014-11-30 11:13:23 -0500 |
| commit | 2a6010634417eac9bf2ac4682ac3675dc5074518 (patch) | |
| tree | f67d814dc0ad9d3936464d07199426ab7cca5b0e /jpa_test/algorithms.py | |
| parent | 3cbe733eb6ea3ee2a7b9b28319da6f2145ab4e46 (diff) | |
| download | cascades-2a6010634417eac9bf2ac4682ac3675dc5074518.tar.gz | |
correctness measure
Diffstat (limited to 'jpa_test/algorithms.py')
| -rw-r--r-- | jpa_test/algorithms.py | 23 |
1 files changed, 20 insertions, 3 deletions
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 |
