import matplotlib.pyplot as plt import numpy as np import cascade_creation import convex_optimization import algorithms import rip_condition def compare_greedy_and_lagrange_cs284r(): """ Compares the performance of the greedy algorithm on the lagrangian sparse recovery objective on the Facebook dataset for the CS284r project """ G = cascade_creation.InfluenceGraph(max_proba = .8) G.import_from_file("../datasets/subset_facebook_SNAPnormalize.txt") A = cascade_creation.generate_cascades(G, p_init=.05, n_cascades=100) #Greedy G_hat = algorithms.greedy_prediction(G, A) algorithms.correctness_measure(G, G_hat, print_values=True) #Lagrange Objective G_hat = algorithms.recovery_l1obj_l2constraint(G, A, passed_function=convex_optimization.type_lasso, floor_cstt=.05, lbda=10) algorithms.correctness_measure(G, G_hat, print_values=True) def watts_strogatz(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") A = cascade_creation.generate_cascades(G, p_init=.05, n_cascades=n_cascades) if passed_function==algorithms.greedy_prediction: G_hat = algorithms.greedy_prediction(G, A) else: G_hat = algorithms.recovery_passed_function(G, A, passed_function=passed_function, floor_cstt=.1, lbda=lbda, n_cascades=n_cascades) algorithms.correctness_measure(G, G_hat, print_values=True) 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] sparse_recov = [.25, .32, .7, .82, .89, .92] plt.axis((0, np.log(6000), 0, 1)) plt.xlabel("Number of Cascades") plt.ylabel("F1 score") plt.grid(color="lightgrey") plt.plot(x, greedy, 'ko-', color="lightseagreen", label='Greedy') plt.plot(x, lasso, 'ko-', color="orange", label="Lasso") plt.plot(x, max_likel, 'ko-', color="coral", label="MLE") plt.plot(x, sparse_recov, 'ko-', color="k", label="Sparse MLE") plt.legend(loc="lower right") plt.savefig("../paper/figures/"+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)