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
|
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=.1, lbda=10)
algorithms.correctness_measure(G, G_hat, print_values=True)
def test():
"""
unit test
"""
G = cascade_creation.InfluenceGraph(max_proba=.3)
G.erdos_init(n=10, p=.2)
A = cascade_creation.generate_cascades(G, p_init=.2, n_cascades=100)
G_hat = algorithms.recovery_l1obj_l2constraint(G, A,
passed_function=convex_optimization.sparse_recovery,
floor_cstt=.1, lbda=10)
algorithms.correctness_measure(G, G_hat, print_values=True)
if __name__=="__main__":
test()
|