util#

This module contains functions to generate networks and save them to files.

pyseldonlib.utils.agents_from_file(model_string, file_path)[source]#

Load agents from a file.

Parameters:
  • model_string (str) – The model string. Allowed values are “DeGroot”, “Deffuant”, “DeffuantVector”, “ActivityDriven”, “Inertial”, “Float”.

  • file_path (str) – The file path.

Returns:

list

Return type:

The list of agents.

pyseldonlib.utils.agents_to_file(network, file_path)[source]#

Save agents to a file.

Parameters:
  • network (Network) – The network.

  • file_path (str) – The file path.

pyseldonlib.utils.generate_fully_connected(model_string, n_agents: int, weight: float = None, rng_seed: int = None)[source]#

Generate a fully connected Network for n_agents.

Parameters:
  • model_string (str) – The model string. Allowed values are “DeGroot”, “Deffuant”, “DeffuantVector”, “ActivityDriven”, “Inertial”, “Float”.

  • n_agents (int) – The number of agents.

  • weight (float) – The weight of the agent.

  • rng_seed (int, default=None) – The seed for the random number generator. If not provided, a random seed is picked.

Returns:

Network

Return type:

The fully connected network.

pyseldonlib.utils.generate_n_connections(model_string, n_agents: int, n_connections: int, self_interaction: bool = False, rng_seed: int = None)[source]#

Generate n_connections Network for n_agents.

Parameters:
  • model_string (str) – The model string. Allowed values are “DeGroot”, “Deffuant”, “DeffuantVector”, “ActivityDriven”, “Inertial”, “Float”.

  • n_agents (int) – The number of agents.

  • n_connections (int) – The number of connections.

  • self_interaction (bool, default=False) – If True, self iteraction is allowed.

  • rng_seed (int, default=None) – The seed for the random number generator. If not provided, a random seed is picked.

Returns:

Network

Return type:

The network.

pyseldonlib.utils.generate_network_from_file(model_string, file_path)[source]#

Generate a Network from a file.

Parameters:
  • model_string (str) – The model string. Allowed values are “DeGroot”, “Deffuant”, “DeffuantVector”, “ActivityDriven”, “Inertial”, “Float”.

  • file_path (str) – The file path.

Returns:

Network

Return type:

The network.

pyseldonlib.utils.generate_square_lattice(model_string, n_edge: int, weight: float)[source]#

Generate a square lattice Network.

Parameters:
  • model_string (str) – The model string. Allowed values are “DeGroot”, “Deffuant”, “DeffuantVector”, “ActivityDriven”, “Inertial”, “Float”.

  • n_edge (int) – The number of edges.

  • weight (float) – The weight of the agent.

Returns:

Network

Return type:

The square lattice network.

pyseldonlib.utils.network_to_dot_file(network, file_path)[source]#

Save the network to a dot file. This is a graph description language file.

Parameters:
  • network (Network) – The network.

  • file_path (str) – The file path.

pyseldonlib.utils.network_to_file(network, file_path)[source]#

Save the network to a file along with weights.

Parameters:
  • network (Network) – The network.

  • file_path (str) – The file path.