Skip to content

Commit

Permalink
Merge branch 'master' into pyup-update-networkx-1.11-to-2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
GiulioRossetti committed Sep 30, 2017
2 parents 8b15dcd + d9e9955 commit a5e64e7
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 31 deletions.
2 changes: 1 addition & 1 deletion ndlib/models/dynamic/DynSIModel.py
Expand Up @@ -51,7 +51,7 @@ def iteration(self, node_status=True):

# streaming
if self.stream_execution:
u, v = self.graph.edges()[0]
u, v = list(self.graph.edges)[0]
u_status = self.status[u]
v_status = self.status[v]

Expand Down
2 changes: 1 addition & 1 deletion ndlib/models/dynamic/DynSIRModel.py
Expand Up @@ -58,7 +58,7 @@ def iteration(self, node_status=True):

# streamong
if self.stream_execution:
u, v = self.graph.edges()[0]
u, v = list(self.graph.edges)[0]
u_status = self.status[u]
v_status = self.status[v]

Expand Down
2 changes: 1 addition & 1 deletion ndlib/models/dynamic/DynSISModel.py
Expand Up @@ -57,7 +57,7 @@ def iteration(self, node_status=True):

# streaming
if self.stream_execution:
u, v = self.graph.edges()[0]
u, v = list(self.graph.edges)[0]
u_status = self.status[u]
v_status = self.status[v]

Expand Down
2 changes: 1 addition & 1 deletion ndlib/models/epidemics/IndependentCascadesModel.py
Expand Up @@ -65,7 +65,7 @@ def iteration(self, node_status=True):
if actual_status[u] != 1:
continue

neighbors = self.graph.neighbors(u) # neighbors and successors (in DiGraph) produce the same result
neighbors = list(self.graph.neighbors(u)) # neighbors and successors (in DiGraph) produce the same result

# Standard threshold
if len(neighbors) > 0:
Expand Down
4 changes: 2 additions & 2 deletions ndlib/models/epidemics/KerteszThresholdModel.py
Expand Up @@ -76,7 +76,7 @@ def iteration(self, node_status=True):
i = 0
while i < number_node_blocked:
# select a random node
node = self.graph.nodes()[np.random.randint(0, self.graph.number_of_nodes())]
node = list(self.graph.nodes)[np.random.randint(0, self.graph.number_of_nodes())]

# node not infected
if actual_status[node] == 0:
Expand Down Expand Up @@ -107,7 +107,7 @@ def iteration(self, node_status=True):
actual_status[node] = 1
continue

neighbors = self.graph.neighbors(node)
neighbors = list(self.graph.neighbors(node))
if len(neighbors) == 0:
continue

Expand Down
4 changes: 2 additions & 2 deletions ndlib/models/epidemics/ProfileThresholdModel.py
Expand Up @@ -96,9 +96,9 @@ def iteration(self, node_status=True):
actual_status[u] = 1
continue

neighbors = self.graph.neighbors(u)
neighbors = list(self.graph.neighbors(u))
if isinstance(self.graph, nx.DiGraph):
neighbors = self.graph.predecessors(u)
neighbors = list(self.graph.predecessors(u))

infected = 0
for v in neighbors:
Expand Down
4 changes: 2 additions & 2 deletions ndlib/models/epidemics/ThresholdModel.py
Expand Up @@ -64,9 +64,9 @@ def iteration(self, node_status=True):
if actual_status[u] == 1:
continue

neighbors = self.graph.neighbors(u)
neighbors = list(self.graph.neighbors(u))
if isinstance(self.graph, nx.DiGraph):
neighbors = self.graph.predecessors(u)
neighbors = list(self.graph.predecessors(u))

infected = 0
for v in neighbors:
Expand Down
4 changes: 2 additions & 2 deletions ndlib/models/opinions/CognitiveOpDynModel.py
Expand Up @@ -176,10 +176,10 @@ def iteration(self, node_status=True):
# then interact with peers
for i in range(0, self.graph.number_of_nodes()):
# select a random node
n1 = self.graph.nodes()[np.random.randint(0, self.graph.number_of_nodes())]
n1 = list(self.graph.nodes)[np.random.randint(0, self.graph.number_of_nodes())]

# select all of the nodes neighbours (no digraph possible)
neighbours = self.graph.neighbors(n1)
neighbours = list(self.graph.neighbors(n1))
if len(neighbours) == 0:
continue

Expand Down
2 changes: 1 addition & 1 deletion ndlib/models/opinions/MajorityRuleModel.py
Expand Up @@ -61,7 +61,7 @@ def iteration(self, node_status=True):
"node_count": node_count.copy(), "status_delta": status_delta.copy()}

# select q random nodes
discussion_group = [self.graph.nodes()[i]
discussion_group = [list(self.graph.nodes)[i]
for i in np.random.randint(0, self.graph.number_of_nodes(), self.params['model']['q'])]

# compute majority
Expand Down
6 changes: 3 additions & 3 deletions ndlib/models/opinions/QVoterModel.py
Expand Up @@ -62,14 +62,14 @@ def iteration(self, node_status=True):
"node_count": node_count.copy(), "status_delta": status_delta.copy()}

# select a random listener
listener = self.graph.nodes()[np.random.randint(0, self.graph.number_of_nodes())]
listener = list(self.graph.nodes)[np.random.randint(0, self.graph.number_of_nodes())]

# select all of the listener's neighbours
neighbours = self.graph.neighbors(listener)
neighbours = list(self.graph.neighbors(listener))
if isinstance(self.graph, nx.DiGraph):
# consider only the predecessors
# assumed if a->b then b can be influenced by a
neighbours = self.graph.predecessors(listener)
neighbours = list(self.graph.predecessors(listener))

# select q random neighbours (with repetitions)
influence_group_state = [self.status[neighbours[i]]
Expand Down
10 changes: 5 additions & 5 deletions ndlib/models/opinions/SznajdModel.py
Expand Up @@ -52,24 +52,24 @@ def iteration(self, node_status=True):
status_delta = {st: 0 for st in self.available_statuses.values()}

# select a random node
speaker1 = self.graph.nodes()[np.random.randint(0, self.graph.number_of_nodes())]
speaker1 = list(self.graph.nodes)[np.random.randint(0, self.graph.number_of_nodes())]

# select a random neighbour
neighbours = self.graph.neighbors(speaker1)
neighbours = list(self.graph.neighbors(speaker1))
if isinstance(self.graph, nx.DiGraph):
# add also the predecessors
neighbours += self.graph.predecessors(speaker1)
neighbours += list(self.graph.predecessors(speaker1))

speaker2 = neighbours[np.random.randint(0, len(neighbours))]

if self.status[speaker1] == self.status[speaker2]:
# select listeners (all neighbours of two speakers)
neighbours = self.graph.neighbors(speaker1) + self.graph.neighbors(speaker2)
neighbours = list(self.graph.neighbors(speaker1)) + list(self.graph.neighbors(speaker2))

if isinstance(self.graph, nx.DiGraph):
# assumed if a->b then b can be influenced by a
# but not the other way around - the link between the speakers doesn't matter
neighbours = self.graph.successors(speaker1) + self.graph.successors(speaker2)
neighbours = list(self.graph.successors(speaker1)) + list(self.graph.successors(speaker2))

# update status of listeners
for listener in neighbours:
Expand Down
6 changes: 3 additions & 3 deletions ndlib/models/opinions/VoterModel.py
Expand Up @@ -50,14 +50,14 @@ def iteration(self, node_status=True):
"node_count": node_count.copy(), "status_delta": status_delta.copy()}

# select a random node
listener = self.graph.nodes()[np.random.randint(0, self.graph.number_of_nodes())]
listener = list(self.graph.nodes)[np.random.randint(0, self.graph.number_of_nodes())]

# select a random neighbour
neighbours = self.graph.neighbors(listener)
neighbours = list(self.graph.neighbors(listener))
if isinstance(self.graph, nx.DiGraph):
# difficult to have a digraph but assumed if a->b then b can be influenced by a
# but not the other way around
neighbours = self.graph.predecessors(listener)
neighbours = list(self.graph.predecessors(listener))

speaker = neighbours[np.random.randint(0, len(neighbours))]

Expand Down
8 changes: 4 additions & 4 deletions ndlib/test/test_ndlib.py
Expand Up @@ -412,19 +412,19 @@ def test_config(self):
config = mc.Configuration()
config.add_model_parameter('percentage_infected', 0.1)
config.add_model_initial_configuration("Infected", [1, 2, 3])
config.add_node_set_configuration("partial", {1:1, 2:2})
config.add_node_set_configuration("partial", {1: 1, 2: 2})
try:
model.set_initial_status(config)
except:
pass

config.add_edge_set_configuration("partial", {e: 1 for e in g.edges()[:10]})
config.add_edge_set_configuration("partial", {e: 1 for e in list(g.edges)[:10]})
try:
model.set_initial_status(config)
except:
pass
config.add_node_set_configuration("partial", {n: 1 for n in g.nodes()})
config.add_edge_set_configuration("partial", {e: 1 for e in g.edges()})
config.add_node_set_configuration("partial", {n: 1 for n in g.nodes})
config.add_edge_set_configuration("partial", {e: 1 for e in g.edges})
model.set_initial_status(config)

g = nx.complete_graph(100)
Expand Down
1 change: 1 addition & 0 deletions ndlib/test/test_parallel.py
Expand Up @@ -45,5 +45,6 @@ def test_multi_initial_set(self):
nprocesses=4)
self.assertIsNotNone(trends)


if __name__ == '__main__':
unittest.main()
4 changes: 2 additions & 2 deletions requirements.txt
@@ -1,8 +1,8 @@
mock==2.0.0
sphinx_rtd_theme==0.2.4
numpy==1.13.1
numpy==1.13.3
future==0.16.0
networkx==2.0
dynetx==0.1.6
dynetx==0.2.0
bokeh==0.12.9
matplotlib==2.0.2
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -13,7 +13,7 @@
# long_description = f.read()

setup(name='ndlib',
version='3.0.0',
version='3.0.1',
license='GNU General Public License v3 or later (GPLv3+)',
description='Network Diffusion Library',
url='https://github.com/GiulioRossetti/ndlib',
Expand Down

0 comments on commit a5e64e7

Please sign in to comment.