Agreement and distance#

The distance between two positions is always based on their differences in truth-value assignments, and their agreement is closely related to this difference: if \(\delta\) is a normalised distance function, then the normalised agreement of two positions \(x\) and \(y\) is given as \(1 - \delta(x, y)\).

The distance functions below accept pairs of agents and output the agreement or distance of that pair. To obtain the differences among more than two positions, use difference_matrix() to obtain a square matrix of distances.

taupy.analysis.polarisation.difference_matrix(positions, measure)[source]#

Create a quadratic matrix \(D_{ij}\) in which rows and columns are filled by positions. The value at \(D_{ij}\) is the distance, calculated by measure, between positions \(i\) and \(j\).

This matrix of distances is the fundamental object to calculate most polarisation measures.

Hamming distance#

For positions that assign truth values to the same propositions, particularly for complete positions of the same debate, the Hamming distance is the most easy distance measure. It simply counts the items that two positions evaluate differently.

taupy.analysis.agreement.hamming_distance(pos1, pos2)[source]#

Returns the Hamming distance between two positions of equal length. The Hamming distance counts the number of differences in truth-value attributions. This distance can only be calculated for positions with the same domain (complete positions on the same debate have the same domain).

The Hamming distance can be normalised to the number of proposition to which the positions assign truth values (their “length”).

taupy.analysis.agreement.normalised_hamming_distance(pos1, pos2)[source]#

Returns the Hamming distance normalised by the number of propositions in the positions’ domain.

Closely related to the Hamming distance is Betz’ normalised agreement, or bna() for short. For two positions of equal domain, \(x\) and \(y\), \(\text{bna}(x,y) = 1 - \text{HD}(x,y) / \text{len}(x)\).

taupy.analysis.agreement.bna(pos1, pos2)[source]#

A normalised agreement measure for positions of equal length, which is used by [Betz2013], page 39. Here, agreement is normalised to the length of the positions.

Edit distance#

The notion of difference and agreement is meaningful for positions of different domains as well. The edit distance is equal to the minimal number of operations that are necessary to transform one position into the other. Each operation is assigned to a weight, and the edit distance is calculated as a weighted sum of the operations. There are three operations: switching of a truth value, adding of a truth-value assignment, and deletion of one. The edit distance is generally asymmetric if the weights are unequal.

Hint

When all operations in the edit distance have the same weight, the edit distance is a generalisation of the Hamming distance. For positions of equal domain, it then simplifies to the Hamming distance.

taupy.analysis.agreement.edit_distance(pos1, pos2, weights={'deletion': 1.0, 'insertion': 1.0, 'substitution': 1.0})[source]#

A generalised distance measure that does not require that the positions share their domain. Compared to edit distances for ordered sequences (e.g. Leventsthein distance), it is far easier to compare two positions in terms of TDS:

For each item, two positions can have four states:
  • They agree on the item, which does not increase the distance

There are three operations that do increase the distance:
  • Substitution: The positions are equal after transposition, i.e. changing a truth-value

  • Insertion: One position does not make a statement concerning one proposition. Adding the respective truth-value attribution makes the two positions equal w.r.t the statement.

  • Deletion: One position does make a statement that the other does not care about. The positions can be made equal if the first position forgets its statement.

In the following measure, these operations are all weighted with factor 1. Another implementation is needed to factor in different weights.

The edit distance can be normalised by first calculating the maximal distance given the union of the positions’ domains and the weights allocated to the operations.

taupy.analysis.agreement.normalised_edit_distance(pos1, pos2, weights={'deletion': 1.0, 'insertion': 1.0, 'substitution': 1.0})[source]#

The (weighted) edit distance, normalised to return a value in [0, 1]. Normalisation is understood as the relation between actual and maximal difference. Maximal difference is achieved in the edit distance if the most costly action is performed for all items.

taupy.analysis.agreement.normalised_edit_agreement(pos1, pos2)[source]#

An agreement function based on the normalised edit distance is defined for convenience. It equals \(1- ext{normalised ED}(x,y)\).