diff options
Diffstat (limited to 'jpa_test/cascade_creation.py')
| -rw-r--r-- | jpa_test/cascade_creation.py | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/jpa_test/cascade_creation.py b/jpa_test/cascade_creation.py index ac094b9..f8defc7 100644 --- a/jpa_test/cascade_creation.py +++ b/jpa_test/cascade_creation.py @@ -3,8 +3,7 @@ import numpy as np class InfluenceGraph(nx.Graph): """ - Inherits from the graph class - with new init function and other attributes + networkX graph with mat and logmat attributes """ def __init__(self, max_proba, *args, **kwargs): self.max_proba = max_proba @@ -19,7 +18,7 @@ class InfluenceGraph(nx.Graph): def mat(self): if not hasattr(self, '_mat'): self._mat = (self.max_proba * np.random.rand(len(self), len(self)) - * nx.adjacency_matrix(self)) + * np.asarray(nx.adjacency_matrix(self))) return self._mat @property @@ -31,9 +30,8 @@ class InfluenceGraph(nx.Graph): def icc_cascade(G, p_init): """ - input: graph with prob as edge attr - returns: 2D boolean matrix with indep. casc. - where True means node was active at that time step + Returns boolean vectors for one cascade + True means node was active at that time step p_init: proba that node in seed set """ susceptible = np.ones(G.number_of_nodes(), dtype=bool) @@ -59,13 +57,8 @@ def test(): """ unit test """ - G = nx.erdos_renyi_graph(1000, 1, directed=True) - G.logmat = np.zeros((G.number_of_nodes(), G.number_of_nodes())) - G.mat = G.logmat - for edge in G.edges(data=True): - edge[2]['weight'] = .3*np.random.rand() - G.logmat[edge[0],edge[1]] = np.log(1 - edge[2]["weight"]) - G.mat[edge[0], edge[1]] = edge[2]["weight"] + G = InfluenceGraph(max_proba = .3) + G.erdos_init(n = 100, p = 1) import time t0 = time.time() print len(icc_cascade(G, p_init=.1)) |
