aboutsummaryrefslogtreecommitdiffstats
path: root/jpa_test
diff options
context:
space:
mode:
Diffstat (limited to 'jpa_test')
-rw-r--r--jpa_test/algorithms.py32
-rw-r--r--jpa_test/cascade_creation.py10
2 files changed, 33 insertions, 9 deletions
diff --git a/jpa_test/algorithms.py b/jpa_test/algorithms.py
new file mode 100644
index 0000000..2ee08ec
--- /dev/null
+++ b/jpa_test/algorithms.py
@@ -0,0 +1,32 @@
+import numpy as np
+import networkx as nx
+import cascade_creation
+
+
+def greedy_prediction(G, cascades):
+ """
+ returns estimated graph
+ """
+ G_hat = cascade_creation.InfluenceGraph(max_proba=None)
+ G.add_nodes_from(G.nodes())
+ for node in G.nodes():
+ unaccounted = cascades
+ for cascade in cascades:
+ time_step = 0
+ while not cascade[time_step][node]:
+ time_step += 1
+
+def test():
+ """
+ unit test
+ """
+ G = cascade_creation.InfluenceGraph(max_proba = .3)
+ G.erdos_init(n = 100, p = 1)
+ import time
+ t0 = time.time()
+ print len(cascade_creation.icc_cascade(G, p_init=.1))
+ t1 = time.time()
+ print t1 - t0
+
+if __name__=="__main__":
+ test()
diff --git a/jpa_test/cascade_creation.py b/jpa_test/cascade_creation.py
index 6e5c34e..19e799f 100644
--- a/jpa_test/cascade_creation.py
+++ b/jpa_test/cascade_creation.py
@@ -26,13 +26,12 @@ class InfluenceGraph(nx.Graph):
for edge in data:
split1 = edge.split('\t')
split2 = split1[1].split('\n')
-
u = int(split1[0])
v = int(split2[0])
G.add_edge(u,v)
self.add_nodes_from(G.nodes())
self.add_edges_from(G.edges())
-
+
@property
def mat(self):
if not hasattr(self, '_mat'):
@@ -73,13 +72,6 @@ def generate_cascades(G, p_init, n_cascades):
return [icc_cascade(G,p_init) for i in xrange(n_cascades)]
-def greedy_prediction(G, cascades):
- """
- returns estimated graph
- """
- G_hat = InfluenceGraph(max_proba=None)
- G.add_nodes_from(G.nodes())
-
def test():
"""
unit test