Agent attributes (initialization component)

This component is concerned with initializing the attributes of the agents at the start of the simulation run. The following methods are available:

Initializing the attributes can be done using the following function:

initialize_attributes

To initialize attributes, the following function can be called:

defSim.agents_init.agents_init.initialize_attributes(network: networkx.classes.graph.Graph, realization: str, **kwargs)

This function works as a factory method for the AttributesInitializer component. It calls the initialize_attributes function of a specific implementation of the AttributesInitializer and passes to it the kwargs dictionary.

Parameters
  • network – The network that will be modified.

  • realization – The specific AttributesInitializer that shall be used to initialize the attributes. Options are “random_categorical” and “random_continuous”.

  • kwargs – The parameter dictionary with all optional parameters.

set_categorical_attribute

defSim.agents_init.agents_init.set_categorical_attribute(network: networkx.classes.graph.Graph, name: str, values: list, distribution: str = 'uniform', **kwargs)

Adds a categorical attribute to all nodes in a network. The values for that attribute are drawn from a list of possible values provided by the user.

Parameters
  • network – The graph object whose nodes’ attributes are modified.

  • name – the name of the attribute. This is used as a key to call the attribute value in other functions.

  • values – A list that contains all possible values for that attribute.

  • distribution – ‘gaussian’, ‘uniform’, or ‘custom’ are possible values.

  • kwargs

    a dictionary containing the parameter name and value for each distribution, these are:

    for gaussian: loc and scale. loc would be the index of the most common value in the values list

    for custom distribution: c. an array-like containing the probabilities for each entry in the values list.

set_continuous_attribute

defSim.agents_init.agents_init.set_continuous_attribute(network: networkx.classes.graph.Graph, name: str, shape: tuple = 1, distribution: str = 'uniform', **kwargs)

Adds a continuous attribute to all nodes in a network. The values of the attribute are drawn from a distribution that is set by the user. Random values are drawn using the numpy.random module.

Parameters
  • network – The graph object whose nodes’ attributes are modified.

  • shape – sets the output shape of the attribute value. Allows e.g. for multidimensional opinion vectors

  • name – the name of the attribute. This is used as a key to call the attribute value in other functions

  • distribution – “normal”, “uniform”, “beta”, “triangular” are possible distributions to choose from

  • kwargs

    a dictionary containing the parameter name and value for each distribution, these are:

    loc, scale to set center and spread for the normal distribution (truncated at [0,1])

    a, b to set center and shape for the beta distribution for the beta distribution

    loc to set center for the triangular distribution

Abstract Base Class

The Abstract Base Class of the agent attribute initializer:

class defSim.agents_init.agents_init.AttributesInitializer(**kwargs)

Initializes and changes attributes of nodes in the network.

__init__(**kwargs)
Parameters

kwargs – This dictionary contains all the implementation-specific parameters.

abstract initialize_attributes(network: networkx.classes.graph.Graph, **kwargs)

Gives initial values to the nodes in the network. Values could e.g. be based on their position in the network.

Parameters

network – The network that will be modified.