Euclidean Distance

class defSim.dissimilarity_component.EuclideanDistance.EuclideanDistance(exclude=[])

Bases: defSim.dissimilarity_component.dissimilarity_calculator.DissimilarityCalculator

Implements the DissimilarityCalculator as a calculator of the euclidean 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=[])

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

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

Calculates normalized euclidean distance of the agents’ feature vectors where feature values do not exceed the [0,1] bounds.

The distances are adjusted by the square root of the number of features, so that maximally dissimilar agents always have a distance of 1 regardless of the number of features.

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.

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

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.