aboutsummaryrefslogtreecommitdiffstats
path: root/src/algorithms.py
diff options
context:
space:
mode:
authorjeanpouget-abadie <jean.pougetabadie@gmail.com>2015-02-01 16:33:04 -0500
committerjeanpouget-abadie <jean.pougetabadie@gmail.com>2015-02-01 16:33:04 -0500
commite8369874088c0ae4b1d98f79f5bae3319de2ac6d (patch)
tree1ab49efbcdab69a7eaad354bb869883b769ab9c9 /src/algorithms.py
parent0991a13214af4023259465f132f09e6c66f3895c (diff)
downloadcascades-e8369874088c0ae4b1d98f79f5bae3319de2ac6d.tar.gz
updating code to Python 3
Diffstat (limited to 'src/algorithms.py')
-rw-r--r--src/algorithms.py23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/algorithms.py b/src/algorithms.py
index 5b07f78..c880a7b 100644
--- a/src/algorithms.py
+++ b/src/algorithms.py
@@ -2,7 +2,6 @@ import numpy as np
import networkx as nx
import cascade_creation
from collections import Counter
-from itertools import izip
import convex_optimization
import timeout
@@ -15,7 +14,7 @@ def greedy_prediction(G, cascades):
G_hat = cascade_creation.InfluenceGraph(max_proba=None)
G_hat.add_nodes_from(G.nodes())
for node in G_hat.nodes():
- print node
+ print(node)
# Avoid cases where infection time is None or 0
tmp = [cascade for cascade in cascades if cascade.infection_time(node)
[0]]
@@ -41,14 +40,14 @@ def recovery_l1obj_l2constraint(G, cascades, floor_cstt, passed_function,
G_hat = cascade_creation.InfluenceGraph(max_proba=None)
G_hat.add_nodes_from(G.nodes())
for node in G_hat.nodes():
- print node
+ print(node)
try:
M, w = cascade_creation.icc_matrixvector_for_node(cascades, node)
p_node, __ = passed_function(M,w, *args, **kwargs)
G_hat = cascade_creation.add_edges_from_proba_vector(G=G_hat,
p_node=p_node, node=node, floor_cstt=floor_cstt)
except timeout.TimeoutError:
- print "TimeoutError, skipping to next node"
+ print("TimeoutError, skipping to next node")
return G_hat
@@ -69,14 +68,14 @@ def correctness_measure(G, G_hat, print_values=False):
f1_score = 2.* tp / (2 * tp + fp + fn)
if print_values:
- print "False Positives: {}".format(fp)
- print "False Negatives: {}".format(fn)
- print "True Positives: {}".format(tp)
- print "True Negatives: {}".format(tn)
- print "-------------------------------"
- print "Precision: {}".format(precision)
- print "Recall: {}".format(recall)
- print "F1 score: {}".format(f1_score)
+ print("False Positives: {}".format(fp))
+ print("False Negatives: {}".format(fn))
+ print("True Positives: {}".format(tp))
+ print("True Negatives: {}".format(tn))
+ print("-------------------------------")
+ print("Precision: {}".format(precision))
+ print("Recall: {}".format(recall))
+ print("F1 score: {}".format(f1_score))
return fp, fn, tp, tn