ModelConfig

The ModelConfig object is the common interface used to set up simulation experiments.

class ndlib.models.ModelConfig.Configuration

Configuration Object

It allows to specify four categories of experiment configurations:

  1. Model configuration
  2. Node Configuration
  3. Edge Configuration
  4. Initial Status

Every diffusion model has its own parameters (as defined in its reference page).

Model Configuration

Model configuration involves the instantiation of both the mandatory and optional parameters of the chosen diffusion model.

Configuration.add_model_parameter(self, param_name, param_value)

Set a Model Parameter

Parameters:
  • param_name – parameter identifier (as specified by the chosen model)
  • param_value – parameter value

Model parameters can be setted as in the following example:

import ndlib.models.ModelConfig as mc

# Model Configuration
config = mc.Configuration()
config.add_model_parameter("beta", 0.15)

The only model parameter common to all the diffusive approaches is fraction_infected that allows to specify the ratio of infected nodes at the beginning of the simulation.

Node Configuration

Node configuration involves the instantiation of both the mandatory and optional parameters attached to individual nodes.

Configuration.add_node_configuration(self, param_name, node_id, param_value)

Set a parameter for a given node

Parameters:
  • param_name – parameter identifier (as specified by the chosen model)
  • node_id – node identifier
  • param_value – parameter value
Configuration.add_node_set_configuration(self, param_name, node_to_value)

Set Nodes parameter

Parameters:
  • param_name – parameter identifier (as specified by the chosen model)
  • node_to_value – dictionary mapping each node a parameter value

Node parameters can be set as in the following example:

import ndlib.models.ModelConfig as mc

# Model Configuration
config = mc.Configuration()

threshold = 0.25
for i in g.nodes():
    config.add_node_configuration("threshold", i, threshold)

Edge Configuration

Edge configuration involves the instantiation of both the mandatory and optional parameters attached to individual edges.

Configuration.add_edge_configuration(self, param_name, edge, param_value)

Set a parameter for a given edge

Parameters:
  • param_name – parameter identifier (as specified by the chosen model)
  • edge – edge identifier
  • param_value – parameter value
Configuration.add_edge_set_configuration(self, param_name, edge_to_value)

Set Edges parameter

Parameters:
  • param_name – parameter identifier (as specified by the chosen model)
  • edge_to_value – dictionary mapping each edge a parameter value

Edge parameters can be set as in the following example:

import ndlib.models.ModelConfig as mc

# Model Configuration
config = mc.Configuration()

threshold = 0.25
for i in g.nodes():
    config.add_edge_configuration("threshold", i, threshold)

Status Configuration

Status configuration allows to specify explicitly the status of a set of nodes at the beginning of the simulation.

Configuration.add_model_initial_configuration(self, status_name, nodes)

Set initial status for a set of nodes

Parameters:
  • status_name – status to be set (as specified by the chosen model)
  • nodes – list of affected nodes

Node statuses can be set as in the following example:

import ndlib.models.ModelConfig as mc

# Model Configuration
config = mc.Configuration()

infected_nodes = [0, 1, 2, 3, 4, 5]
config.add_model_initial_configuration("Infected", infected_nodes)

Explicit status specification takes priority over the percentage specification expressed via model definition (e.g. fraction_infected).

Only the statuses implemented by the chosen model can be used to specify initial configurations of nodes.