-
Notifications
You must be signed in to change notification settings - Fork 80
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
Comments
Yes, have a look at the docs: https://ndlib.readthedocs.io/en/latest/reference/mconf/Mconf.html |
I mean for Weighted Hegselmann-Krause model |
How to do |
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? |
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. |
Thank you so much! |
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. |
The text was updated successfully, but these errors were encountered: