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

Is there a way to configure initial state for iteration 0? #245

Closed
cosmosanalytics opened this issue Jan 29, 2023 · 9 comments
Closed

Is there a way to configure initial state for iteration 0? #245

cosmosanalytics opened this issue Jan 29, 2023 · 9 comments

Comments

@cosmosanalytics
Copy link

image

@GiulioRossetti
Copy link
Owner

Yes, have a look at the docs: https://ndlib.readthedocs.io/en/latest/reference/mconf/Mconf.html

@cosmosanalytics
Copy link
Author

I mean for Weighted Hegselmann-Krause model

@cosmosanalytics
Copy link
Author

How to do
config.add_model_initial_configuration("Infected", infected_nodes)
for Weighted Hegselmann-Krause model?

@cosmosanalytics
Copy link
Author

I have a brain functional weighted network and want to simulate how an infected node can propagate through the network. All the models don't consider weights except Weighted Hegselmann-Krause model (though it is an opinion model not an epidemic model). Do you have any suggestions on how to simulate infectious propagation through weighted network?

@cosmosanalytics
Copy link
Author

I specify epsilon to 1, different nodes starting from different initial states may slow converge to extreme opinion 1, which can represent infection of different degrees at different nodes propagates through the network. The question is: can I specify the initial state for each node at the beginning of the simulation??
image

@GiulioRossetti
Copy link
Owner

Yes, it is not documented but it is indeed possible. As soon as I have access to my laptop I'll provide you a code snippet for your use case.

@cosmosanalytics
Copy link
Author

Thank you so much!

@GiulioRossetti
Copy link
Owner

Ok, here's a minimal example on how to force ndlib to set the initial statuses for any opinon dynamic model:

import networkx as nx
import ndlib.models.ModelConfig as mc
import ndlib.models.opinions as opn

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

# Model selection
model = opn.WHKModel(g)

# Model Configuration
config = mc.Configuration()
config.add_model_parameter("epsilon", 0.32)

# Setting the edge parameters
weight = 0.2
if isinstance(g, nx.Graph):
    edges = g.edges
else:
    edges = [(g.vs[e.tuple[0]]['name'], g.vs[e.tuple[1]]['name']) for e in g.es]

for e in edges:
    config.add_edge_configuration("weight", e, weight)


model.set_initial_status(config)

initial_statuses = {node: 0 for node in g.nodes()}  # custom initial statuses: values in [-1, 1]
model.status = initial_statuses
model.initial_status = initial_statuses

# Simulation execution
iterations = model.iteration_bunch(20)

As you can see, you have to procede with the standard configuration then generate a dictionary node->initial_value and manually assign it to the internal model variables. It is not particularly "clean" but it does the job.

@cosmosanalytics
Copy link
Author

Thank you very much! It works!
image

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