aboutsummaryrefslogtreecommitdiffstats
path: root/jpa_test
diff options
context:
space:
mode:
authorjeanpouget-abadie <jean.pougetabadie@gmail.com>2014-12-01 10:12:59 -0500
committerjeanpouget-abadie <jean.pougetabadie@gmail.com>2014-12-01 10:12:59 -0500
commitb1a6d4397bd1dc784a68987fc645eabe2bbcc8ec (patch)
tree4b683937a3c4cb32e75da37174e3c7dc9b1bc924 /jpa_test
parentddbb95cbac65a74016839e253cda39466fa13308 (diff)
downloadcascades-b1a6d4397bd1dc784a68987fc645eabe2bbcc8ec.tar.gz
small bug fixes
Diffstat (limited to 'jpa_test')
-rw-r--r--jpa_test/algorithms.py4
-rw-r--r--jpa_test/cascade_creation.py12
-rw-r--r--jpa_test/convex_optimization.py9
3 files changed, 18 insertions, 7 deletions
diff --git a/jpa_test/algorithms.py b/jpa_test/algorithms.py
index cf4ce50..76a3c51 100644
--- a/jpa_test/algorithms.py
+++ b/jpa_test/algorithms.py
@@ -44,7 +44,9 @@ def sparserecovery(G, cascades):
G_hat.add_nodes_from(G.nodes())
for node in G_hat.nodes():
M, w = cascade_creation.icc_matrixvector_for_node(cascades, node)
+ M = M.astype("int8")
edges_node = convex_optimization.l1regls(M,w)
+ print edges_node
def correctness_measure(G, G_hat):
@@ -64,7 +66,7 @@ def test():
unit test
"""
G = cascade_creation.InfluenceGraph(max_proba = .3)
- G.erdos_init(n = 100, p = .1)
+ G.erdos_init(n = 100, p = .5)
import time
t0 = time.time()
A = cascade_creation.generate_cascades(G, .1, 100)
diff --git a/jpa_test/cascade_creation.py b/jpa_test/cascade_creation.py
index 2b53963..09f0c45 100644
--- a/jpa_test/cascade_creation.py
+++ b/jpa_test/cascade_creation.py
@@ -80,8 +80,8 @@ def icc_matrixvector_for_node(cascades, node):
M = []
for cascade in cascades:
t_i = cascade.infection_time(node)[0]
- if t_i > 0 or t_i is None:
- indicator = np.zeros(len(cascade))
+ if t_i != 0:
+ indicator = np.zeros(len(cascade[:t_i]))
if t_i > 0:
indicator[-1] = 1
w.append(indicator)
@@ -107,6 +107,9 @@ def icc_cascade(G, p_init):
< np.random.rand(G.number_of_nodes())
active = active & susceptible
susceptible = susceptible - active
+ if not cascade:
+ print "Empty cascade, consider changing p_init or n_nodes. Retrying."
+ return icc_cascade(G, p_init)
return cascade
@@ -122,12 +125,11 @@ def test():
unit test
"""
G = InfluenceGraph(max_proba = .3)
- G.erdos_init(n = 100, p = 1)
+ G.erdos_init(n = 10, p = 1)
import time
t0 = time.time()
- A = generate_cascades(G, .1, 10)
+ A = generate_cascades(G, .1, 2)
M, w = icc_matrixvector_for_node(A, 0)
- print w
t1 = time.time()
print t1 - t0
diff --git a/jpa_test/convex_optimization.py b/jpa_test/convex_optimization.py
index fdd321e..e83c605 100644
--- a/jpa_test/convex_optimization.py
+++ b/jpa_test/convex_optimization.py
@@ -45,7 +45,14 @@ def l1regls(M_val, w_val):
return cvxopt.solvers.cpl(c,F, G, h)['x']
-if __name__=="__main__":
+
+def test():
+ """
+ unit test
+ """
M_val = np.random.rand(100, 20)
w_val = np.random.rand(100)
print l1regls(M_val, w_val)
+
+if __name__=="__main__":
+ test()