Giter Site home page Giter Site logo

giuliorossetti / ndlib Goto Github PK

View Code? Open in Web Editor NEW
269.0 12.0 79.0 2.12 MB

Network Diffusion Library - (for NetworkX and iGraph)

Home Page: http://ndlib.readthedocs.io/

License: BSD 2-Clause "Simplified" License

Python 100.00%
complex-networks epidemics opinion-dynamics simulation

ndlib's Introduction

NDlib - Network Diffusion Library

pyversions Build Status Coverage Status Documentation Status DOI Downloads Downloads SBD++

plot

NDlib provides implementations of several spreading and opinion dynamics models.

The project documentation can be found on ReadTheDocs.

If you use NDlib as support to your research consider citing:

G. Rossetti, L. Milli, S. Rinzivillo, A. Sirbu, D. Pedreschi, F. Giannotti. NDlib: a Python Library to Model and Analyze Diffusion Processes Over Complex Networks. Journal of Data Science and Analytics. 2017. DOI:0.1007/s41060-017-0086-6 (pre-print available on arXiv)

G. Rossetti, L. Milli, S. Rinzivillo, A. Sirbu, D. Pedreschi, F. Giannotti. "NDlib: Studying Network Diffusion Dynamics", IEEE International Conference on Data Science and Advanced Analytics, DSAA. 2017.

Promo Video

Promo

Installation

To install the library just download (or clone) the current project and copy the ndlib folder in the root of your application.

Alternatively use pip:

sudo pip install ndlib

Documentation, Tutorials and Online Environments

For examples, tutorials and a complete reference visit the project documentation website on ReadTheDocs.

If you would like to test NDlib functionalities withouth installing anything on your machine consider using the preconfigured Jupyter Hub instances offered by SoBigData++.

Jupyter Notebook Tutorial

Interested in an extensive tutorial on NDlib? Check out the official Jupyter Notebooks!

NDlib Overview

NDlib-Rest

Collaborate with us!

NDlib is an active project, any contribution is welcome!

If you like to include your model in NDlib (as well as in NDlib-REST) feel free to fork the project, open an issue and contact us.

How to contribute to this project?

Contributing is good, doing it correctly is better! Check out our rules, issue a proper pull request /bug report / feature request.

Do you want to be part of the NDlib community to discuss enhancements, desiderata, bug fix? Join us on Slack!

We are a welcoming community... just follow the Code of Conduct.

ndlib's People

Contributors

a1shadows avatar alinasirbu avatar bhaskar24 avatar fossabot avatar gaianoseworthy avatar giacomozoppi avatar giuliorossetti avatar gmavros1 avatar hatwhale avatar jameshughes89 avatar letiziam avatar michaeldorner avatar neserende avatar pyup-bot avatar sumaiya1229 avatar szhorvat avatar tdrumhel1 avatar tensaiz avatar valentinapansanella avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ndlib's Issues

Error running the basic code

After running the basic sample code from here: https://ndlib.readthedocs.io/en/latest/tutorial.html#visualize-the-results I am getting this error message:

Traceback (most recent call last):
File "C:/.../experiment.py", line 24, in
from ndlib.viz.bokeh.DiffusionTrend import DiffusionTrend
File "C:\Users\hanele\Anaconda3\lib\site-packages\ndlib\viz\bokeh\DiffusionTrend.py", line 1, in
from ndlib.viz.bokeh.DiffusionViz import DiffusionPlot
File "C:\Users\hanele\Anaconda3\lib\site-packages\ndlib\viz\bokeh\DiffusionViz.py", line 3, in
from bokeh.models import Title
ImportError: cannot import name 'Title'
.

I have networkx and bokeh installed. What is the issue?

Tutorial example fails - KeyError: 2

During execution of the tutorial example in the documentation, the final example fails to execute, throwing a KeyError

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/anaconda3/envs/eng-net/lib/python3.6/site-packages/ndlib/models/DiffusionModel.py in build_trends(self, iterations)
    317                 try:
--> 318                     status_delta[st].append(it['status_delta'][st])
    319                     node_count[st].append(it['node_count'][st])

KeyError: 2

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
<ipython-input-10-186a6bb0293e> in <module>
     14 sis_model.set_initial_status(config)
     15 iterations = sis_model.iteration_bunch(200)
---> 16 trends = model.build_trends(iterations)
     17 
     18 viz = DiffusionTrend(sis_model, trends)

~/anaconda3/envs/eng-net/lib/python3.6/site-packages/ndlib/models/DiffusionModel.py in build_trends(self, iterations)
    319                     node_count[st].append(it['node_count'][st])
    320                 except:
--> 321                     status_delta[st].append(it['status_delta'][str(st)])
    322                     node_count[st].append(it['node_count'][str(st)])
    323 

Running in a conda env for python 3.6.

No triggering_status in NodeNumericalAttribute ?

Hello !
I'm currently a engineer student and I'm using NdLib for a project. I'm quite new to NdLib so I strongly hope my question/bug report is relevant. In short, I think the class NodeNumericalAttribute has no parameter "triggering_status" as indicated in the documentation.

I'm using Ubuntu 20.04.2, NDLib 5.1.0 and Python 3.8.

I wanted to use NodeNumericalAttribute in order to build a specific epidemic model where you need to test whether to person is vaccinated or not to move from a status to an other. Though, as I looked into the source code of the class NodeNumericalAttribute, I did not find any mention of "triggering_status". I decided to check by myself with the code below. I expected that the two rules c1 ( the one in commentary and the actual one) would do the exact same thing, as all of my nodes have an age between 0 and 100. Yet, when you run this code with a condition and the other, you get the graphs shown below.
vm=MultiPlot()
g = nx.erdos_renyi_graph(1000,0.001)

# Setting edge attribute
attr = {n: {"Age": random.choice(range(0, 100))} for n in g.nodes()}
nx.set_node_attributes(g, attr)

# Composite Model instantiation
model = gc.CompositeModel(g)

# Model statuses
model.add_status("Susceptible")
model.add_status("Infected")
model.add_status("Removed")

# Compartment definition
# c1a = cpm.NodeNumericalAttribute("Age", value=[0, 100], op="IN", probability=1,triggering_status="Infected")
c1b = cpm.NodeStochastic(1,triggering_status="Infected")

c2 = cpm.NodeStochastic(0.01)

# Rule definition
model.add_rule("Susceptible", "Infected", c1b)
model.add_rule("Infected", "Removed", c2)

# Model initial status configuration
config = mc.Configuration()
config.add_model_parameter('fraction_infected', 0.1)

# Simulation execution
model.set_initial_status(config)
iterations = model.iteration_bunch(100)
trends = model.build_trends(iterations)

Capture d’écran du 2021-05-09 17-57-48
Capture d’écran du 2021-05-09 17-58-38

Thus, I wonder if the parameter "triggering_status" actually is implemented in NodeNumericalAttribute ? By the way, I think the issue is the same for NodeNumericalVariable.

I really hope the answer to the question is not obvious and I thank you by advance for your help.
Have a good day,
Justin

Support weighted graphs for epidemic models

Currently, the SIR model, for instance, samples neighbouring nodes with equal probability. I would like to see an option where edge weights can be used to weight the sampling.

Numbers For Individual Iterations

I'm not 100% sure if this is better as a feature request or just a standard issue, but I'll tag feature require either way.

Would there be a way (or could there be a way) to extract the number of susceptible individuals in a network after, let's say, 100 iterations? This would be useful for if we want to develop a probability distribution of the model given certain settings.

wrong UserWarning with subgraph

Hi,

I am passing the giant component of my graph
giant = max(nx.connected_component_subgraphs(g), key=len)
as
model = epidemics.SIRModel(giant)

and I get
UserWarning: Graph with less than 100 nodes: a single node will be set as infected
even if my giant has 993 nodes...

it seems a bug or I am doing something wrong ...

thanks for the support

Error on config with add_node_set_configuration

I get:
ConfigurationException: {'message': 'Missing mandatory model parameter(s)', 'parameters': {'beta'}}
on this:

model = ep.SISModel(G)
cfg = mc.Configuration()
for n in list(G.nodes()):
    cfg.add_node_set_configuration('beta', parm_beta) #different infection probability
cfg.add_model_parameter('lambda', 0.005) #recovery probability
cfg.add_model_parameter("fraction_infected", 0.05)  #initial infected
model.set_initial_status(cfg)
# Simulation execution
iterations = model.iteration_bunch(numiter)

where parm_beta is a dict node,value ({'node1': 0.02, 'node2': 0.02,'node3': 0.01, etc...})
ndlib is version 5
What is wrong?
PS with a "standard" 'beta' assignment works well...

Many thanks for this wonderful and useful package.
RB

Disable TQDM

In my current model, the slowest part overall is the loading of tqdm (as far as I know), and thus I am looking to disable it temporarily. What would be the easiest way to do this, if it is possible? And, if not, could it be a possible future feature?

Crash when using multiruns

I'm currently working on Python 3.7 using Spyder 4.1.3 on Anaconda. I'm working with the following example code:

import networkx as nx
import ndlib.models.ModelConfig as mc
import ndlib.models.epidemics as ep
from ndlib.viz.mpl.DiffusionTrend import DiffusionTrend
from ndlib.utils import multi_runs

# Network topology
g = nx.erdos_renyi_graph(1000, 0.1)

# Model selection
model = ep.SIRModel(g)

# Model Configuration
cfg = mc.Configuration()
cfg.add_model_parameter('beta', 0.001)
cfg.add_model_parameter('gamma', 0.01)
cfg.add_model_parameter("fraction_infected", 0.01)
model.set_initial_status(cfg)


# Simulation execution
trends = multi_runs(model, execution_number = 8, iteration_number = 14, infection_sets=None)

# Visualization
viz = DiffusionTrend(model, trends)
viz.plot("diffusion.pdf")

When it reaches trends = multi_runs(model, execution_number = 8, iteration_number = 14, infection_sets=None) it freezes. Do you have any ideas or recommendations on fixing this?

Thank you!

[Multiplot Error] Not able to run the multiplot visualization example

Describe the bug
While running the Multiplot visualization example in the tutorial, I am getting the following error.

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-6-a6f8d12c6bbd> in <module>
      4 vm.add_plot(p2)
      5 m = vm.plot()
----> 6 show(m)

/usr/local/lib/python3.6/dist-packages/bokeh/io/showing.py in show(obj, browser, new, notebook_handle, notebook_url, **kw)
    137         return run_notebook_hook(state.notebook_type, 'app', obj, state, notebook_url, **kw)
    138 
--> 139     return _show_with_state(obj, state, browser, new, notebook_handle=notebook_handle)
    140 
    141 #-----------------------------------------------------------------------------

/usr/local/lib/python3.6/dist-packages/bokeh/io/showing.py in _show_with_state(obj, state, browser, new, notebook_handle)
    175 
    176     if state.file or not shown:
--> 177         _show_file_with_state(obj, state, new, controller)
    178 
    179     return comms_handle

/usr/local/lib/python3.6/dist-packages/bokeh/io/showing.py in _show_file_with_state(obj, state, new, controller)
    158 
    159     '''
--> 160     filename = save(obj, state=state)
    161     controller.open("file://" + filename, new=NEW_PARAM[new])
    162 

/usr/local/lib/python3.6/dist-packages/bokeh/io/saving.py in save(obj, filename, resources, title, template, state, **kwargs)
     83 
     84     filename, resources, title = _get_save_args(state, filename, resources, title)
---> 85     _save_helper(obj, filename, resources, title, template)
     86     return abspath(filename)
     87 

/usr/local/lib/python3.6/dist-packages/bokeh/io/saving.py in _save_helper(obj, filename, resources, title, template)
    145     '''
    146     from ..embed import file_html
--> 147     html = file_html(obj, resources, title=title, template=template)
    148 
    149     with io.open(filename, mode="w", encoding="utf-8") as f:

/usr/local/lib/python3.6/dist-packages/bokeh/embed/standalone.py in file_html(models, resources, title, template, template_variables, theme, suppress_callback_warning, _always_new)
    301         models_seq = models
    302 
--> 303     with OutputDocumentFor(models_seq, apply_theme=theme, always_new=_always_new) as doc:
    304         (docs_json, render_items) = standalone_docs_json_and_render_items(models_seq, suppress_callback_warning=suppress_callback_warning)
    305         title = _title_from_models(models_seq, title)

/usr/lib/python3.6/contextlib.py in __enter__(self)
     79     def __enter__(self):
     80         try:
---> 81             return next(self.gen)
     82         except StopIteration:
     83             raise RuntimeError("generator didn't yield") from None

/usr/local/lib/python3.6/dist-packages/bokeh/embed/util.py in OutputDocumentFor(objs, apply_theme, always_new)
    132             doc = Document()
    133             for model in objs:
--> 134                 doc.add_root(model)
    135 
    136         # handle a single shared document

/usr/local/lib/python3.6/dist-packages/bokeh/document/document.py in add_root(self, model, setter)
    317             self._roots.append(model)
    318         finally:
--> 319             self._pop_all_models_freeze()
    320         self._trigger_on_change(RootAddedEvent(self, model, setter))
    321 

/usr/local/lib/python3.6/dist-packages/bokeh/document/document.py in _pop_all_models_freeze(self)
   1054         self._all_models_freeze_count -= 1
   1055         if self._all_models_freeze_count == 0:
-> 1056             self._recompute_all_models()
   1057 
   1058     def _recompute_all_models(self):

/usr/local/lib/python3.6/dist-packages/bokeh/document/document.py in _recompute_all_models(self)
   1077             d._detach_document()
   1078         for a in to_attach:
-> 1079             a._attach_document(self)
   1080         self._all_models = recomputed
   1081         self._all_models_by_name = recomputed_by_name

/usr/local/lib/python3.6/dist-packages/bokeh/model.py in _attach_document(self, doc)
    669         '''
    670         if self._document is not None and self._document is not doc:
--> 671             raise RuntimeError("Models must be owned by only a single document, %r is already in a doc" % (self))
    672         doc.theme.apply_to_model(self)
    673         self._document = doc

RuntimeError: Models must be owned by only a single document, BoxZoomTool(id='1020', ...) is already in a doc

To Reproduce
Steps to reproduce the behavior:

  • NDlib version: 5.0.2
  • Operating System: Linux
  • Python version: 3.6
  • Bokeh: 2.0.2
    Sample code that is giving the error:
from ndlib.viz.bokeh.MultiPlot import MultiPlot
vm = MultiPlot()
vm.add_plot(p)
vm.add_plot(p2)
m = vm.plot()
show(m)

The code is present under: Tutorial

Expected behavior
We should be able to generate the bokeh plot.

List tqdm as requirement in the docs

When installing ndlib through pip and then trying to import ndlib.models.epidemics, it will fail due to missing the package tqdm, but it isn't listed as a requirement in the documentation or installed automatically through pip.

After installing tqdm it will work normally.

TypeError: "method" object is not iterable

Hi,

My friend is trying to use the Voter model sample and keeps running into an error.

Here is his code (straight from the sample):

import networkx as nx
import ndlib.models.ModelConfig as mc
import ndlib.models.opinions.VoterModel as vt

# Network topology
g = nx.erdos_renyi_graph(1000, 0.1)

# Model selection
model = vt.VoterModel(g)
config = mc.Configuration()
config.add_model_parameter('percentage_infected', 0.1)

model.set_initial_status(config)

# Simulation execution
iterations = model.iteration_bunch(200)

His error:

TypeError                                 Traceback (most recent call last)
c:\users\Friend\appdata\local\temp\tmp9eye_m.py in <module>()
     14 
     15 # Simulation execution
---> 16 iterations = model.iteration_bunch(200)

C:\Users\Friend\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\ndlib\models\DiffusionModel.py in iteration_bunch(self, bunch_size, node_status)
    189         system_status = []
    190         for it in past.builtins.xrange(0, bunch_size):
--> 191             its = self.iteration(node_status)
    192             system_status.append(its)
    193         return system_status
C:\Users\Friend\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\ndlib\models\opinions\VoterModel.py in iteration(self, node_status)
     51 
     52         # select a random node
---> 53         listener = list(self.graph.nodes)[np.random.randint(0, self.graph.number_of_nodes())]
     54 
     55         # select a random neighbour
TypeError: 'method' object is not iterable 

What is he doing wrong?

attribute a newly infected node to the source node

Is your feature request related to a problem? Please describe.
I wonder if there's a way to attribute a newly infected node to the source node. That is, if a node gets infected, can I know which node infects it? This is very important when doing influence maximization or outbreak control on a cascading model.

Describe the solution you'd like
The model.iteration() function should return the source of each newly affected node. I believe this information should have been computed within the function scope, but isn't returned by the function.

Thank you!

Custom Model With Diverging Paths

I am back with another question! Let's say we wanted to create a custom model by importing the DiffusionModel partial class, like you mentioned in #171 and wanted to make it such that the model is SE(IA)R, such that E -> I with rate = alpha and E -> A with rate = phi, what would be the best way to do this? My current code blocks for transitions are borrowed from the SEIR class, and are pasted below:

if u_status == 2:
                if self.progress[u] < 1:
                    self.progress[u] += self.params['model']['alpha']
                else:
                    actual_status[u] = 3  # I
                    del self.progress[u]

if u_status == 2:
                if self.progress[u] < 1:
                    self.progress[u] += self.params['model']['phi']
                else:
                    actual_status[u] = 4  # A
                    del self.progress[u]

Python 3.8: "TypeError: alpha must be a float or None" Hotfix

For those currently using NDlib and running into the "TypeError: alpha must be a float or None" bug when plotting with MatPlotLib using Python 3.8, here is a following hotfix:

  1. Go to the installation path of NDlib, example: "/home/$USER/.local/lib/python3.8/site-packages/ndlib/"
  2. Find the DiffusionViz.py file, usually under: "/viz/mpl/DiffusionViz.py"
  3. Go to line 69, edit alpha = "0.2" to alpha = 0.2

This should fix the issue, and I'll submit the changes as well.

Memetic Distribution Modeling

There are multiple meme models that can be assessed for information diffusion. I would consider contributing with some sample pieces of code for these models.

The problem with all these models is that they do not factor in competing pieces of information or information mutation.

[Bokeh v2.0.2][DeprecationWarnings]

Describe the bug
Running the Visulization Code under Tutorials, gives the following warning:

BokehDeprecationWarning: 'legend' keyword is deprecated, 
use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead.

To Reproduce
Steps to reproduce the behavior:
Running the Visualization Code under the Tutorial Viz Section, results in the warning as shown above.
This happens for both DiffusionTrend and DiffusionPrevalence

  • NDlib version: 5.0.2
  • Operating System: Linux
  • Python version: 3.6
  • Bokeh: 2.0.2

Expected behavior
Change the use of kwargs legend in the DiffusionPlots

Additional context
This warning will show up for all Bokeh versions >=1.4.0
https://docs.bokeh.org/en/latest/docs/releases.html#release-1-4-0

viz.title not working

Hi,

I am able to set the ylabel with something like viz.ylabel = 'nodes fraction' , but the equivalent for the title does not work ... viz.title = 'some_title' -- basically the title still gives me the info in model.params['model']

thanks

Seeding strategy (Infected)

Hello,

Unfortunately, I can't set the certain set of infected nodes in epidemics or opinion dinamics models to change the seeding strategy from random to the high degree, low degree, high betweeness seeding.
I tried to set the infected nodes with the help of cycle 'for' like in the models with threshold or profile but I could find the option.
Maybe, I did not get the documentation right.

Thank you in advance!

issues with alpha parameter (SEIR)

hi,

I just started to check out the SEIR model implementation and here are a couple of notes:

  1. your 𝛼 seems to work similarly** to the one of the referenced paper, therefore is the inverse of the [see point 2] period
  2. 𝛼 is not related to the incubation , but the latent period > see #155

** the transition E>I happens after 1 / 𝛼 times steps, right? – as below

self.progress[u] += self.params['model']['alpha']

AttributeError: type object 'EdgeCategoricalAttribute' has no attribute 'NodeCategoricalAttribute'

Hi!
I am a beginner who is trying to learn NDlib for my thesis. I have been following the NDlib documentation. I was trying to run the code given on the link below for Node Categorical Attribute

[https://ndlib.readthedocs.io/en/latest/custom/compartments/NodeCategoricalAttribute.html]

while I was running I got the attribute error: type object 'EdgeCategoricalAttribute' has no attribute 'NodeCategoricalAttribute'

Can anyone help me with that?

Thanks!

SWIR Experiments show very inconsistent and failed results across experiments.

I have noticed lately that SWIR models are very unstable in terms of generating results, and sometimes blackout with no infected nodes at all. When I run the simulation with the same model parameters on the same network, the results come far from comparison .
The code that I use for training is :
`import ndlib.models.epidemics.SWIRModel as swir

import networkx as nx

for x in range(0,10):
csv_social=pd.read_csv("../condensed_epidemic_humans_net.txt",sep='\t',names=['Source','Target'],skiprows=[0])
social_epidemic_net=nx.convert_matrix.from_pandas_edgelist(csv_social,source='Source',target='Target')
model=swir.SWIRModel(social_epidemic_net)
config = mc.Configuration()
config.add_model_parameter('kappa',5e-08)
config.add_model_parameter('mu',5e-05)
config.add_model_parameter('nu',5e-05)
config.add_model_initial_configuration("Infected", seeders)
model.set_initial_status(config)
iterations = model.iteration_bunch(15)
y_pred=[]
for iterx in range(0,15):
infected=0
for kx in iterations[iterx]["status"]:
if iterations[iterx]["status"][kx]==1:
infected=infected+1
y_pred.append(infected)

When printing the predicted nodes count , I get the results :

[233, 11050, ]
[233, 0]
[233, 646110]
[233, 0]
[233, 0]
[233, 368725]

I was wondering if my experimental code is mistaken, but I don't experience this issue in the other models ( SIR and SEIR). Even though the experiments are probabilistic simulations, getting 0 infections and such varied values are worrying me.

Any suggestions on this would be extremely helpful.
Regards,

Dynamic model expects dynamic graph but not streaming network

Running through tests for dynamic networks, as in tutorial here

As is, error is thrown that seems to indicate that the ndlib.models.dynamic.DynKerteszThresholdModel.DynKerteszThresholdModel object should receive a DynGraph as input, since a base networkx graph (g) does not have a temporal_snapshots_ids attribute, like a DynGraph (dg) does:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-13-88e2748d22a3> in <module>
     12 
     13 # Model selection
---> 14 model = ks.DynKerteszThresholdModel(g)
     15 
     16 # Model Configuration

~/anaconda3/envs/eng-net/lib/python3.6/site-packages/ndlib/models/dynamic/DynKerteszThresholdModel.py in __init__(self, graph)
     24              :param graph: A networkx graph object
     25          """
---> 26         super(self.__class__, self).__init__(graph)
     27         self.available_statuses = {
     28             "Susceptible": 0,

~/anaconda3/envs/eng-net/lib/python3.6/site-packages/ndlib/models/DynamicDiffusionModel.py in __init__(self, graph)
     57         self.initial_status = {}
     58 
---> 59         snapshot_ids = self.dyngraph.temporal_snapshots_ids()
     60         self.min_snapshot_id = min(snapshot_ids)
     61         self.max_snapshot_id = max(snapshot_ids)

AttributeError: 'Graph' object has no attribute 'temporal_snapshots_ids'

However, modifying the tutorial code to use dg (model = ks.DynKerteszThresholdModel(dg)) returns another, less obvious error code that I have been unable to find a cause of:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-14-594262860f33> in <module>
     31 
     32 # Simulation interaction graph based execution
---> 33 iterations = model.execute_iterations()

~/anaconda3/envs/eng-net/lib/python3.6/site-packages/ndlib/models/DynamicDiffusionModel.py in execute_iterations(self, node_status)
     82                 self.graph = nx.Graph()
     83                 self.graph.add_edge(e[0], e[1])
---> 84                 its = self.iteration(node_status)
     85                 system_status.append(its)
     86         return system_status

~/anaconda3/envs/eng-net/lib/python3.6/site-packages/ndlib/models/dynamic/DynKerteszThresholdModel.py in iteration(self, node_status)
     70         # streaming
     71         if self.stream_execution:
---> 72             raise ValueError("Streaming network not allowed.")
     73         # snapshot
     74         else:

ValueError: Streaming network not allowed.

This is strange since, before executing the iterations, calling model.stream_execution returns False.

Can rules be used to update continuous variables instead of discrete states

I read through the custom model definition docs and I understand the compartment concept to implement rules. but I noticed that every rule shows a transition from one discrete state to another discrete state.

Is it currently possible to create rules that update a continuous variable (state), much like certain opinion dynamic models (e.g: the opinion variable in the Cognitive Opinion Dynamics model)?

Or can custom models only be created when using discrete states?

Pseudo-Dynamic Network Simulation

If this idea is successful, I will make a short tutorial about it and submit it to be added to the "Read The Docs" or submit it as its own model. Let's say we wanted to simulate quarantines using a standard static NetworkX graph (I use Barabasi_Albert for testing, so let's use that), with an average degree of X, where, if a general quarantine goes into effect, the average degree is lowered to Y, with Y <= X.

For ease of example, let's say there are 3 stages of quarantine: Just family (stage A), a small bubble of friends (stage B), generally open (stage C). 100% of edges are accessible in stage C, only 50% in stage B, and only 25% in stage C. This means 50% of edges would have the C attribute (only accessible in stage C), 25% would have the B attribute (only accessible in stages B and C), and 25% would have the A attribute (accessible in all stages).

How would you recommend going about designing this? I suspect the easiest way is to build a custom model (not using the composite model class, but actually building one) and adding this to it.

Zombie Epidemiology

Is your feature request related to a problem? Please describe.
It is a possible Halloween special? Unfortunately, this would have to be adapted to be usable in a network setting. I would like to contribute, and guidance is heavily appreciated.

Describe the solution you'd like
There is the SZR model, the SIZR model, the Quarantine model, and the Treatment model.

Describe alternatives you've considered
https://ndlib.readthedocs.io/en/latest/custom/custom.html#examples

Additional context
https://math.uchicago.edu/~shmuel/Modeling/WHEN%20ZOMBIES%20ATTACK!-%20MATHEMATICAL%20MODELLING%20OF%20AN%20OUTBREAK%20OF%20ZOMBIE%20INFECTION.pdf

TypeError: alpha must be a float or None

When attempting to visualize a composite model, I am running into the error that is the title of this bug report.

Steps to reproduce the behavior:

  • NDlib version: 5.0.2
  • OS Version: Manjaro Linux 5.4.40-1
  • Python version: Python 3.8

Code Executed:

import networkx as nx
import ndlib.models.ModelConfig as mc
import ndlib.models.CompositeModel as gc
import ndlib.models.compartments as ns
from ndlib.viz.mpl.DiffusionTrend import DiffusionTrend

# Network generation
g = nx.erdos_renyi_graph(1000, 0.1)

# Composite Model instantiation
model = gc.CompositeModel(g)

# Model statuses
model.add_status("Susceptible")
model.add_status("Infected")
model.add_status("Removed")
model.available_statuses

# Compartment definition
c1 = ns.NodeStochastic(0.02, triggering_status="Infected")
c2 = ns.NodeStochastic(0.01)

# Rule definition
model.add_rule("Susceptible", "Infected", c1)
model.add_rule("Infected", "Removed", c2)

# Model initial status configuration
cfg = mc.Configuration()
cfg.add_model_parameter('fraction_infected', 0.01)

# Simulation execution
model.set_initial_status(cfg)
iterations = model.iteration_bunch(5)

# Visualization
trends = model.build_trends(iterations)
viz = DiffusionTrend(model, trends)
viz.plot()

Expected behavior:
A plot of the number of people in each compartment at each timestamp for all the iterations.

Screenshot:
image

Probability Based on Number of Neighbors

Guess who is back with a new idea?

For my current project, my team is inquiring into developing a disease where the probability (or rate) of becoming infected depends on the number of infected neighbors more explicably. As it stands, I know the probability of infection is a test where a node will run a check of the probability of infection for each sick neighbor (so 2 sick neighbors means 2 rolls of the die), but this one is a little different.

For example, let's say we define the probability on a static value (beta), the number of susceptible neighbors (S) and the number of infected neighbors (I). So the transition of S -> I depends on probability = (betaSI). How would this be possible, seeing as it's a unique way of checking?

Seed value error in multi_runs

When using multi_runs, some of my classmates got the following error:

Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\multiprocessing\pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\ndlib\utils.py", line 71, in __execute
    np.random.seed(seed)
  File "mtrand.pyx", line 246, in numpy.random.mtrand.RandomState.seed
  File "_mt19937.pyx", line 166, in numpy.random._mt19937.MT19937._legacy_seeding
  File "_mt19937.pyx", line 180, in numpy.random._mt19937.MT19937._legacy_seeding
ValueError: Seed must be between 0 and 2**32 - 1
"""

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_12920/4199588637.py in <module>
     18 
     19 # Simulation multiple execution
---> 20 trends = multi_runs(model1, execution_number=10, iteration_number=100, infection_sets=None, nprocesses=4)

~\AppData\Local\Programs\Python\Python39\lib\site-packages\ndlib\utils.py in multi_runs(model, execution_number, iteration_number, infection_sets, nprocesses)
     56 
     57             for result in results:
---> 58                 executions.append(result.get())
     59 
     60     return executions

~\AppData\Local\Programs\Python\Python39\lib\multiprocessing\pool.py in get(self, timeout)
    769             return self._value
    770         else:
--> 771             raise self._value
    772 
    773     def _set(self, i, obj):

ValueError: Seed must be between 0 and 2**32 - 1

Numpy added this check in numpy/numpy@6b1a120, because seeds larget than 32 bits get truncated back to 32 bit, leading to the same stream of random numbers for two different seeds. A quick and dirty fix I did was changing line 71 in ndlib/utils.py as follows:

-    np.random.seed(seed)
+    np.random.seed(seed % 2**32)

This will results in the multiple seeds leading to the same stream of random numbers, so you may want to change the way you generate seeds to fall between 0 and 2**32-1 instead.

issue with saving plot

Hi,

how would you save the plot ?
plt.savefig() does not work...

I think in general would be better to return a usual matplotlib plot object with viz.plot(), so that one can customise axis, etc... -- it's maybe better to open another issue for this feature request

Thanks

Parallel pool starting very late (not starting at all?)

hi,

recently it happened sometimes that with multi_runs nothing happen within the first 20 sec, in the sense that I don't see the cpus workload ramping (one 1 at 100% -- usually I check via htop)

Is this a known behaviour ? I am not sure if they don't run at all or if it takes simply more time to start the pool...

However, when I interrupt the kernel of my jupyter notebook, I get this

Screenshot 2019-06-18 at 16 30 15

(again, at the time I kill the kernel, only 1 cpu is at 100%)

Any idea ? thanks

Missing ndlib/models/compartments/enums/NumericalType.py

Describe the bug
After installed the library and use it. An error is launched when execute the script of according figure below.
image

To Reproduce
Steps to reproduce the behavior:

  • NDlib version
  • Linux(Ubunto 20.12), OSX (Catalina 10.15.7) e Windows (10 Home)
  • Python 3.8

Processes Upon Processes

I am currently running my code in an online computing server, and was contacted by an admin to ask about something that is going on. I ran a few processes tests (using the "top" command in bash), and got the following result:

top - 14:50:07 up 17 days,  7:14,  1 user,  load average: 44.71, 37.14, 33.64
Tasks: 879 total,  62 running, 817 sleeping,   0 stopped,   0 zombie
%Cpu(s): 94.9 us,  4.9 sy,  0.0 ni,  0.0 id,  0.1 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem : 19647166+total, 11478744+free, 27502984 used, 54181228 buff/cache
KiB Swap: 10485756 total, 10483964 free,     1792 used. 16307368+avail Mem  

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+  P COMMAND                                      
83560 gnosewo1  20   0 2146604 1.205g   1684 R  29.5  0.6   0:02.19 34 python 
83561 gnosewo1  20   0 2146604 1.205g   1568 R  28.8  0.6   0:02.15 28 python 
83553 gnosewo1  20   0 2146600 1.205g   1612 R  28.5  0.6   0:02.97 42 python 
83555 gnosewo1  20   0 2146600 1.205g   1548 R  28.5  0.6   0:02.77 28 python 
83566 gnosewo1  20   0 2146608 1.205g   1644 R  28.2  0.6   0:01.63 30 python 
82891 gnosewo1  20   0 2804688 1.855g  20780 S  27.9  1.0   1:46.83 40 python 
83565 gnosewo1  20   0 2146608 1.205g   1492 R  27.9  0.6   0:01.62 32 python 
83572 gnosewo1  20   0 2146612 1.205g   1456 R  27.9  0.6   0:00.89 42 python 
83547 gnosewo1  20   0 2120996 1.181g   2288 S  27.6  0.6   0:03.45 40 python 
83563 gnosewo1  20   0 2146604 1.205g   1656 R  27.0  0.6   0:01.78 40 python 
83557 gnosewo1  20   0 2146600 1.205g   1648 R  26.6  0.6   0:02.43 34 python 
83558 gnosewo1  20   0 2146604 1.205g   1676 R  26.3  0.6   0:02.30 42 python 
83570 gnosewo1  20   0 2146608 1.205g   1616 R  26.3  0.6   0:01.07 36 python 
83552 gnosewo1  20   0 2146600 1.205g   1548 R  26.0  0.6   0:03.31 36 python 
83569 gnosewo1  20   0 2146608 1.205g   1500 R  25.7  0.6   0:01.18 42 python 
83548 gnosewo1  20   0 2146596 1.205g   1792 R  25.4  0.6   0:03.20 32 python 
83551 gnosewo1  20   0 2146596 1.205g   1716 R  25.4  0.6   0:03.31 32 python 
83556 gnosewo1  20   0 2146600 1.205g   1440 R  25.4  0.6   0:02.58 32 python 
83567 gnosewo1  20   0 2146608 1.205g   1428 R  25.4  0.6   0:01.39 30 python 
83554 gnosewo1  20   0 2146600 1.205g   1792 R  25.1  0.6   0:02.85 34 python 
83559 gnosewo1  20   0 2146604 1.205g   1524 R  24.8  0.6   0:02.35 36 python 
83550 gnosewo1  20   0 2146596 1.205g   1680 R  24.5  0.6   0:03.34 30 python 
83568 gnosewo1  20   0 2146608 1.205g   1580 R  24.1  0.6   0:01.22 30 python 
83571 gnosewo1  20   0 2146612 1.205g   1596 R  24.1  0.6   0:00.91 32 python 
83562 gnosewo1  20   0 2146604 1.205g   1656 R  23.5  0.6   0:01.69 28 python 
83564 gnosewo1  20   0 2146604 1.205g   1468 R  22.9  0.6   0:01.53 38 python 
83573 gnosewo1  20   0 2146616 1.205g   1524 R  21.9  0.6   0:00.70 34 python 
83574 gnosewo1  20   0 2146616 1.205g   1512 R  18.5  0.6   0:00.59 38 python 
83575 gnosewo1  20   0 2146620 1.205g   1676 R  15.4  0.6   0:00.49 36 python 
83545 gnosewo1  20   0 2120996 1.181g   2032 S  13.8  0.6   0:03.44 38 python 
83576 gnosewo1  20   0 2146620 1.205g   1500 R  12.5  0.6   0:00.40 42 python 
83577 gnosewo1  20   0 2146620 1.205g   1576 R   8.5  0.6   0:00.27 40 python 
83543 gnosewo1  20   0 2120996 1.181g   2028 S   5.6  0.6   0:03.47 28 python 
83544 gnosewo1  20   0 2120996 1.181g   2036 S   5.6  0.6   0:03.44 30 python 
83578 gnosewo1  20   0 2144548 1.205g   1836 R   3.8  0.6   0:00.12 38 python 
82983 gnosewo1  20   0  137744   1828    444 R   1.3  0.0   0:02.46 36 top 
83579 gnosewo1  20   0 2105828 1.169g   1084 R   0.6  0.6   0:00.02 38 python 
82887 gnosewo1  20   0  113436   1604   1288 S   0.0  0.0   0:00.07 30 slurm_script 
82925 gnosewo1  20   0  187352   2828   1004 S   0.0  0.0   0:00.01 40 sshd 
82926 gnosewo1  20   0  126104   2404   1708 S   0.0  0.0   0:00.03 42 bash 
83539 gnosewo1  20   0 2120992 1.181g   2056 S   0.0  0.6   0:03.48 42 python 
83540 gnosewo1  20   0 2120992 1.181g   2036 S   0.0  0.6   0:03.47 40 python 
83541 gnosewo1  20   0 2120992 1.181g   2032 S   0.0  0.6   0:03.54 30 python 
83542 gnosewo1  20   0 2120996 1.181g   2056 S   0.0  0.6   0:03.52 38 python 
83580 gnosewo1  20   0 2101628 1.165g    844 S   0.0  0.6   0:00.00 34 python 
83581 gnosewo1  20   0 2101628 1.165g    844 S   0.0  0.6   0:00.00 34 python 
83582 gnosewo1  20   0 2101628 1.165g    844 S   0.0  0.6   0:00.00 34 python 
83583 gnosewo1  20   0 2101628 1.165g    844 S   0.0  0.6   0:00.00 34 python 
83584 gnosewo1  20   0 2101628 1.165g    844 S   0.0  0.6   0:00.00 34 python 

This is on an 8 core processor using the multi_runs command. It should be noted that for approximately 90%+ of the time, the only process using ANY CPU power is the first, all others are at 0.0%.

Do you have any idea what is actually going on here? The usage is quite odd, given that approximately half of the processes are inactive at literally all times, and the other half are only active at max 10% of the time, with this one super process.

Edit: It should be noted that usage percents aren't constant here. When active, the 50% that are usually 0 will slowly climb there way up to about 60, before stopping again.

Edit 2: The number of processes also seems to vary. The lowest I've encountered is 32 (which is the standard), but it often goes up to the 62 you see here.

Using Multiple processors to speed up simulation

Is there any way I can speed up the diffusion simulation leveraging the multiple cores I have in my machine. I want to speed up a single experiment, for a relatively larger net.
Is there any way for optimization already existing.
Regards,

[Minor Typos] [Profile Model Documentation]

Describe the bug
Two minor typos discovered in the Documentation of the Profile Model

  • Each node has its own profile describing how many it is likely likely it is to accept a behaviour similar to the one that is currently spreading.
  • we set the initially infected node set to the 10% of the overall population and assign a profile of 0.25 0.15(as used in the example, either we change the text or in the corresponding example code) to all the nodes.
# Setting nodes parameters
profile = 0.15

To Reproduce
Refer to the latest Docs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.