From 6145d1adab1197300d64560b7d26fddd59bdf41d Mon Sep 17 00:00:00 2001 From: jeanpouget-abadie Date: Wed, 4 Feb 2015 23:54:08 -0500 Subject: small changes --- src/cascade_creation.py | 1 + src/convex_optimization.py | 2 +- src/make_plots.py | 39 +++++++++++++++++++++++++++++++++++---- 3 files changed, 37 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/cascade_creation.py b/src/cascade_creation.py index a71fce7..cdf7484 100644 --- a/src/cascade_creation.py +++ b/src/cascade_creation.py @@ -70,6 +70,7 @@ class InfluenceGraph(nx.DiGraph): self._mat = self.max_proba * np.random.rand(len(self), len(self) ) * np.asarray(nx.adjacency_matrix(self).todense().T) if self.sparse_edges: + 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))) diff --git a/src/convex_optimization.py b/src/convex_optimization.py index fce89b8..81bee2b 100644 --- a/src/convex_optimization.py +++ b/src/convex_optimization.py @@ -90,7 +90,7 @@ def diff_and_opt(M_val, w_val, f_x, f_xz): def F(x=None, z=None): if x is None: - return 0, cvxopt.matrix(-.7, (n,1)) + return 0, cvxopt.matrix(-.01, (n,1)) elif z is None: y, y_diff = f_x(x, M_val, w_val) return cvxopt.matrix(float(y), (1, 1)),\ diff --git a/src/make_plots.py b/src/make_plots.py index 10fd657..d719337 100644 --- a/src/make_plots.py +++ b/src/make_plots.py @@ -34,7 +34,7 @@ def compute_graph(graph_name, n_cascades, lbda, passed_function, min_proba, """ G = cascade_creation.InfluenceGraph(max_proba=max_proba, min_proba=min_proba, - sparse_edges=True) + sparse_edges=sparse_edges) G.import_from_file(graph_name) A = cascade_creation.generate_cascades(G, p_init=.05, n_cascades=n_cascades) @@ -77,6 +77,37 @@ def plot_watts_strogatz_graph(): plt.savefig("../paper/figures/"+"watts_strogatz.pdf") +def plot_barabasi_albert_graph(): + """ + plot information in a pretty way + """ + plt.clf() + fig = plt.figure(1) + labels = [50, 100, 500, 1000, 2000, 5000] + 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] + lasso = [.25, .3, .55, .67, .76, .83] + greedy = [.1, .13, .33, .47, .6, .75] + + fig, ax = plt.subplots() + + plt.axis((np.log(45), np.log(5500), 0, 1)) + plt.xlabel("Number of Cascades") + plt.ylabel("F1 score") + plt.grid(color="lightgrey") + ax.plot(x, greedy, 'ko-', color="lightseagreen", label='Greedy') + ax.plot(x, lasso, 'ko-', color="orange", label="Lasso") + ax.plot(x, max_likel, 'ko-', color="cornflowerblue", label="MLE") + ax.plot(x, sparse_recov, 'ko-', color="k", label="Our Method") + plt.legend(loc="lower right") + ax.set_xticks(x) + ax.set_xticklabels(tuple(labels)) + plt.savefig("../paper/figures/"+"barabasi_albert.pdf") + + + def plot_ROC_curve(figure_name): """ plot information in a pretty way @@ -137,8 +168,8 @@ if __name__=="__main__": #convex_optimization.type_lasso) if 1: compute_graph("../datasets/kronecker_graph_256_cross.txt", - n_cascades=1000, lbda=.001, min_proba=.2, max_proba=.7, + n_cascades=100, lbda=.01, min_proba=.2, max_proba=.7, passed_function= - convex_optimization.sparse_recovery, - #convex_optimization.type_lasso, + #convex_optimization.sparse_recovery, + convex_optimization.type_lasso, sparse_edges=False) \ No newline at end of file -- cgit v1.2.3-70-g09d2