Dissimilarity component

The dissimilarity component handles calculating the dissimilarity between agents before and during the simulation run. Each method should contain a function calculate_dissimilarity to calculate dissimilarity between two agents and a function calculate_dissimilarity_networkwide to calculate dissimilarity at the start of the simulation run.

select_calculator

defSim.dissimilarity_component.dissimilarity_calculator.select_calculator(realization: str)defSim.dissimilarity_component.dissimilarity_calculator.DissimilarityCalculator

This function works as a factory method for the dissimilarity_component. It returns an instance of the Calculator that is asked for.

Parameters

realization – The type of DissimilarityCalculator. Possible options are [“hamming”, “euclidean”, “manhatttan”]

Returns

An instance of a DissimilarityCalculator


Some useful methods when programming your own dissimilarity measure:

Abstract Base Class (ABC)

The Abstract Base Class of the dissimilarity component:

class defSim.dissimilarity_component.dissimilarity_calculator.DissimilarityCalculator(exclude=None)

This class is responsible for determining the distance between nodes, either from one node to another, or for every agent in the network to another. The distance could be based on their attributes or actual geodesic distance.

The class contains the attribute ‘exclude’ which accepts a list of strings with the names of agent features that should not be used to calculate between agent similarity.

__init__(exclude=None)

Initialize self. See help(type(self)) for accurate signature.

abstract calculate_dissimilarity(network: networkx.classes.graph.Graph, agent1_id: int, agent2_id: int) → float

This function calculates how dissimilar two agents are based on their attributes and/or their distance in the network. Can for example be used to determine whether a neighbor is selected for the influence process.

Parameters
  • network – The network in which the agents exist.

  • agent1_id – The index of the first agent.

  • agent2_id – The index of the agent to compare with.

:returns a float value, representing the distance between the two agents

abstract calculate_dissimilarity_networkwide(network: networkx.classes.graph.Graph)

Calculates the distance from each agent to each other and sets that distance as an attribute on the edge between them.

Parameters

network – The network that is modified.