aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/algorithms.py6
-rw-r--r--src/cascade_creation.py6
-rw-r--r--src/convex_optimization.py4
-rw-r--r--src/make_plots.py18
4 files changed, 18 insertions, 16 deletions
diff --git a/src/algorithms.py b/src/algorithms.py
index 24a63f3..43c6721 100644
--- a/src/algorithms.py
+++ b/src/algorithms.py
@@ -38,7 +38,7 @@ def recovery_passed_function(G, cascades, floor_cstt, passed_function,
passed_function should have similar structure to ones in convex_optimation
"""
G_hat = cascade_creation.InfluenceGraph(max_proba=None)
- G_hat.add_nodes_from(G.nodes())
+ G_hat.add_nodes_from(G.nodes())
f_x, f_xz = passed_function(*args, **kwargs)
@@ -83,8 +83,8 @@ def correctness_measure(G, G_hat, print_values=True):
print("Precision: {}".format(precision))
print("Recall: {}".format(recall))
print("F1 score: {}".format(f1_score))
- print("Fall Out: {}".format(fall_out))
- print("l2_norm: {}".format(norm))
+ print("Fall Out: {}".format(fall_out))
+ print("l2_norm: {}".format(norm))
return fp, fn, tp, tn
diff --git a/src/cascade_creation.py b/src/cascade_creation.py
index cdf7484..714c120 100644
--- a/src/cascade_creation.py
+++ b/src/cascade_creation.py
@@ -65,7 +65,8 @@ class InfluenceGraph(nx.DiGraph):
if not hasattr(self, '_mat'):
if self.min_proba is None or self.max_proba is None:
print("You forgot to initialize the min and max proba")
- self._mat = np.zeros((self.number_of_nodes(), self.number_of_nodes()))
+ self._mat = np.zeros((self.number_of_nodes(),
+ self.number_of_nodes()))
else:
self._mat = self.max_proba * np.random.rand(len(self), len(self)
) * np.asarray(nx.adjacency_matrix(self).todense().T)
@@ -73,7 +74,8 @@ class InfluenceGraph(nx.DiGraph):
print("adding sparse edges to the graph")
#Adding sparse non-edges to the graph!
self._mat += .1 * np.random.rand(len(self), len(self)
- ) * np.random.binomial(1, p=.33, size=(len(self), len(self)))
+ ) * np.random.binomial(1, p=.33, size=(len(self),
+ len(self)))
return self._mat
@property
diff --git a/src/convex_optimization.py b/src/convex_optimization.py
index 0d506e1..000143f 100644
--- a/src/convex_optimization.py
+++ b/src/convex_optimization.py
@@ -33,7 +33,7 @@ def sparse_recovery(lbda, n_cascades):
y = lbda * theta_.norm(1) - 1./n_cascades*(
(w).dot(tensor.log(1-tensor.exp(M.dot(theta_))))
+ (1-w).dot(tensor.dot(M, theta_))
- )
+ )
z = tensor.row().T
z_ = z.flatten()
@@ -134,7 +134,7 @@ def test():
A = cascade_creation.generate_cascades(G, .1, 500)
M_val, w_val = cascade_creation.icc_matrixvector_for_node(A, 2)
print(len(M_val))
-
+
#Type lasso
if 0:
f_x, f_xz = type_lasso(lbda)
diff --git a/src/make_plots.py b/src/make_plots.py
index c45479e..8970cdf 100644
--- a/src/make_plots.py
+++ b/src/make_plots.py
@@ -54,7 +54,7 @@ def plot_watts_strogatz_graph():
plt.clf()
fig = plt.figure(1)
labels = [50, 100, 500, 1000, 2000, 5000]
- x = [np.log(50), np.log(100), np.log(500),
+ x = [np.log(50), np.log(100), np.log(500),
np.log(1000), np.log(2000), np.log(5000)]
sparse_recov = [.25, .32, .7, .82, .89, .92]
max_likel = [.21, .29, .67, .8, .87, .9]
@@ -84,7 +84,7 @@ def plot_barabasi_albert_graph():
plt.clf()
fig = plt.figure(1)
labels = [50, 100, 500, 1000, 2000, 5000]
- x = [np.log(50), np.log(100), np.log(500),
+ x = [np.log(50), np.log(100), np.log(500),
np.log(1000), np.log(2000), np.log(5000)]
sparse_recov = [.35, .38, .58, .69, .79, .86]
max_likel = [.35, .38, .56, .68, .78, .85]
@@ -188,13 +188,13 @@ def plot_ROC_curve(figure_name):
plt.ylabel("Precision")
plt.grid(color="lightgrey")
- ax.plot(recall_lasso_200, precision_lasso_200, 'ko-',
+ ax.plot(recall_lasso_200, precision_lasso_200, 'ko-',
color="lightseagreen", label="Lasso-200 cascades")
- ax.plot(recall_sparse_200, precision_sparse_200, 'ko-',
+ ax.plot(recall_sparse_200, precision_sparse_200, 'ko-',
color="k", label="Our Method-200 cascades")
- ax.plot(recall_lasso_50, precision_lasso_50, 'ko-',
+ ax.plot(recall_lasso_50, precision_lasso_50, 'ko-',
color="orange", label="Lasso-50 cascades")
- ax.plot(recall_sparse_50, precision_sparse_50, 'ko-',
+ ax.plot(recall_sparse_50, precision_sparse_50, 'ko-',
color="cornflowerblue", label="Our Method-50 cascades")
plt.legend(loc="upper right", fontsize=14)
plt.savefig("../paper/figures/"+"ROC_curve.pdf")
@@ -253,9 +253,9 @@ if __name__=="__main__":
#algorithms.greedy_prediction)
#convex_optimization.type_lasso)
if 0:
- compute_graph("../datasets/kronecker_graph_256_cross.txt",
+ compute_graph("../datasets/kronecker_graph_256_cross.txt",
n_cascades=50, lbda=0., min_proba=.2, max_proba=.7,
passed_function=
- convex_optimization.sparse_recovery,
+ convex_optimization.sparse_recovery,
#convex_optimization.type_lasso,
- sparse_edges=True) \ No newline at end of file
+ sparse_edges=True)