aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cascade_creation.py11
-rw-r--r--src/make_plots.py31
2 files changed, 31 insertions, 11 deletions
diff --git a/src/cascade_creation.py b/src/cascade_creation.py
index df0384e..a90939b 100644
--- a/src/cascade_creation.py
+++ b/src/cascade_creation.py
@@ -28,6 +28,17 @@ class InfluenceGraph(nx.DiGraph):
self.add_edges_from(G.edges())
self.add_edges_from([(node_2, node_1) for node_1, node_2 in G.edges()])
+ def powerlaw_cluster(self, n, m, p, seed=139):
+ """
+ n : number of nodes
+ m : number of random edges to add for each node
+ p : proba of adding triangle for each random edge
+ seed : random number generator
+ """
+ G = nx.powerlaw_cluster_graph(n, m, p, seed)
+ self.add_edges_from(G.edges())
+ self.add_edges_from([(node_2, node_1) for node_1, node_2 in G.edges()])
+
def import_from_file(self, file_name):
"""
Takes a file from the Stanford collection of networks
diff --git a/src/make_plots.py b/src/make_plots.py
index 556d27a..980b613 100644
--- a/src/make_plots.py
+++ b/src/make_plots.py
@@ -27,12 +27,12 @@ def compare_greedy_and_lagrange_cs284r():
algorithms.correctness_measure(G, G_hat, print_values=True)
-def watts_strogatz(n_cascades, lbda, passed_function):
+def compute_graph(graph_name, n_cascades, lbda, passed_function):
"""
Test running time on different algorithms
"""
G = cascade_creation.InfluenceGraph(max_proba=.7, min_proba=.2)
- G.import_from_file("../datasets/watts_strogatz_300_30_point3.txt")
+ G.import_from_file(graph_name)
A = cascade_creation.generate_cascades(G, p_init=.05, n_cascades=n_cascades)
if passed_function==algorithms.greedy_prediction:
@@ -49,12 +49,13 @@ def plot_graph(figure_name):
plot information in a pretty way
"""
plt.clf()
- x = [np.log(50), np.log(100), np.log(500), np.log(1000), np.log(2000), np.log(5000)]
- greedy = [.09, .15, .4, .63, .82, .92]
- lasso = [.07, .30, .46, .65, 0, 0]
- max_likel = [.21, .29, .67, .8, .87, .9]
+ x = [50, 100, 500, 1000, 2000, 5000]
sparse_recov = [.25, .32, .7, .82, .89, .92]
- plt.axis((0, np.log(6000), 0, 1))
+ max_likel = [.21, .29, .67, .8, .87, .9]
+ lasso = [.07, .30, .46, .65, 0, 0]
+ greedy = [.09, .15, .4, .63, .82, .92]
+
+ plt.axis((0, 5500, 0, 1))
plt.xlabel("Number of Cascades")
plt.ylabel("F1 score")
plt.grid(color="lightgrey")
@@ -67,7 +68,15 @@ def plot_graph(figure_name):
if __name__=="__main__":
- watts_strogatz(n_cascades=5000, lbda=.002, passed_function=
- #convex_optimization.sparse_recovery)
- #algorithms.greedy_prediction)
- convex_optimization.type_lasso) \ No newline at end of file
+ if 0:
+ compute_graph("../datasets/watts_strogatz_300_30_point3.txt",
+ n_cascades=5000, lbda=.002, passed_function=
+ #convex_optimization.sparse_recovery)
+ #algorithms.greedy_prediction)
+ convex_optimization.type_lasso)
+ if 1:
+ compute_graph("../datasets/watts_strogatz_300_30_point3.txt",
+ n_cascades=300, lbda=.002, passed_function=
+ convex_optimization.sparse_recovery)
+ #algorithms.greedy_prediction)
+ #convex_optimization.type_lasso) \ No newline at end of file