Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICEModel KeyError: 'com' #237

Open
jasongong11 opened this issue May 21, 2022 · 1 comment
Open

ICEModel KeyError: 'com' #237

jasongong11 opened this issue May 21, 2022 · 1 comment

Comments

@jasongong11
Copy link

Describe the bug
I run the tutorial code of ICEmodel. And it produces the error code:

  0%|          | 1/200 [00:00<00:00, 853.37it/s]
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-17-42574a55ef61> in <module>
     22 
     23 # Simulation execution
---> 24 iterations = model.iteration_bunch(200)

~/anaconda3/lib/python3.7/site-packages/ndlib/models/DiffusionModel.py in iteration_bunch(self, bunch_size, node_status)
    199         system_status = []
    200         for it in tqdm.tqdm(past.builtins.xrange(0, bunch_size)):
--> 201             its = self.iteration(node_status)
    202             system_status.append(its)
    203         return system_status

~/anaconda3/lib/python3.7/site-packages/ndlib/models/epidemics/ICPModel.py in iteration(self, node_status)
     84                         key = (u, v)
     85 
---> 86                         if self.params['nodes']['com'][u] == self.params['nodes']['com'][v]: # within same community
     87                             # Individual specified thresholds
     88                             if 'threshold' in self.params['edges']:

KeyError: 'com'

To Reproduce
The tutorial code I run:

import networkx as nx
import ndlib.models.ModelConfig as mc
import ndlib.models.epidemics as ep

g = nx.erdos_renyi_graph(1000, 0.1)

# Model selection
model = ep.ICPModel(g)

# Model Configuration
config = mc.Configuration()
config.add_model_parameter('fraction_infected', 0.1)
config.add_model_parameter('permeability', 0.3)


# Setting the edge parameters
threshold = 0.1
for e in g.edges():
    config.add_edge_configuration("threshold", e, threshold)

model.set_initial_status(config)

# Simulation execution
iterations = model.iteration_bunch(200)
  • NDlib version
  • Operating System
  • Python version
  • Version(s) of NDlib required libraries

Expected behavior
I guess this issue is probably the community information is not inputted into the model.params['node']

The tutorial code does not run any community detection analysis. And the model.params['node'] gives an empty dict.

Additional context

Name: ndlib
Version: 5.0.2
Summary: Network Diffusion Library
Home-page: https://github.com/GiulioRossetti/ndlib
Author: Giulio Rossetti
Author-email: [email protected]
License: BSD-Clause-2
Location: /home/jasongong/anaconda3/lib/python3.7/site-packages
Requires: bokeh, dynetx, future, netdispatch, networkx, numpy, python-igraph, scipy
Required-by: 
Note: you may need to restart the kernel to use updated packages.
@JKORELC
Copy link

JKORELC commented Mar 3, 2023

Hi @jasongong11,

Hopefully you found the answer by now. For anyone else that arrives here for the same reason, there is a simple solution.

   if self.params['nodes']['com'][u] == self.params['nodes']['com'][v]: # within same community
       # Individual specified thresholds
       if 'threshold' in self.params['edges']:
           ...

ICPModel Line #86

The documented example leaves out this crucial detail.

    for n in g.nodes():
        config.add_node_configuration("com", n, community)

Where community is predefined by the community detection algorithm you apply separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants