1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
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 = [50, 100, 500, 1000, 2000, 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, 5000, 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)
|