Concepts / Distance functions for similarity construction

Distance functions for similarity construction

A similarity graph represents each data point as a vertex and each pairwise similarity as an edge weight.

  • Programming

From distances to connections

Clustering is often introduced as the task of grouping similar data points. A graph-based formulation makes that idea visible: each data point becomes a vertex, and the relationship between two points becomes a weighted edge. The central challenge is to decide how strongly two points should be connected. A distance function measures how far apart two points are, and a similarity construction converts that distance into an edge weight.

The weight should represent similarity rather than distance. In the clustering formulation described by the source, points placed in the same group should have high-weight internal edges, while points placed in different groups should have low-weight edges between them. Thus, the graph stores the pairwise evidence that a clustering method uses.

Data points as weighted vertices

Suppose a collection contains three data points. The graph representation gives each point a vertex. Every pairwise relationship is represented by an edge whose weight records the similarity assigned to that pair. A larger edge weight means that the pair has been assigned a stronger similarity in the graph.

pairwise relationshippairwise relationshippairwise relationshippairwise relationshippairwise relationshippairwise relationshipPoint 1vertexSimilarityweight between 1 and 2Point 2vertexSimilarityweight between 1 and 3Point 3vertexSimilarityweight between 2 and 3
How do individual data points become vertices, and how are pairwise similarity values represented as weighted edges?

A distance function is one possible starting point for assigning these weights. The source describes using a distance function d together with a parameter σ in a specified exponential expression. That expression uses the distance between two points to define an entry of the similarity matrix W. The important construction idea is that pairwise distances are transformed into pairwise similarity weights before the graph is partitioned.

Reading the similarity matrix

The weighted graph can be recorded as a similarity matrix W. Each entry Wᵢ,ⱼ represents the similarity weight associated with the relationship between data point i and data point j. In this way, the matrix is not a separate idea from the graph: it is a tabular representation of the graph's pairwise edge weights.

encodesencodesencodesW₁,₂0.8Point 1 to Point 2edge weight 0.8W₁,₃0.2Point 1 to Point 3edge weight 0.2W₂,₃0.3Point 2 to Point 3edge weight 0.3
How does each entry Wᵢ,ⱼ map to the relationship connecting data points i and j, and what does the full matrix represent?

A three-point similarity matrix

Use the generated similarity matrix W to identify the pairwise weights and calculate the degree associated with each point.

Choose W: Let W contain the pairwise weights 0.8 for Points 1 and 2, 0.2 for Points 1 and 3, and 0.3 for Points 2 and 3. These values are a generated teaching example.

Read Point 1's row: The row for Point 1 contains the weights 0.8 and 0.2 for its relationships with the other points.

Read Point 2's row: The row for Point 2 contains the weights 0.8 and 0.3 for its relationships with the other points.

Read Point 3's row: The row for Point 3 contains the weights 0.2 and 0.3 for its relationships with the other points.

The matrix records all pairwise similarity weights. The degree calculation uses the sum of the corresponding row of W.

Degrees from row sums

The degree matrix D is a diagonal matrix. Its diagonal entry Dᵢ,ᵢ equals the sum of the corresponding row of W. The degree therefore collects the total similarity weight associated with a data point, according to the weights recorded in W.

sumsumsumRow 10.8 + 0.2D₁,₁1.0Row 20.8 + 0.3D₂,₂1.1Row 30.2 + 0.3D₃,₃0.5
How are the similarities in each row of W summed to produce the corresponding diagonal entry of D?

Calculating D from W

For the generated pairwise weights 0.8, 0.2, and 0.3, calculate the diagonal entries of the degree matrix.

Point 1: Add the similarities in Point 1's row: 0.8 + 0.2 = 1.0. Therefore D₁,₁ = 1.0.

Point 2: Add the similarities in Point 2's row: 0.8 + 0.3 = 1.1. Therefore D₂,₂ = 1.1.

Point 3: Add the similarities in Point 3's row: 0.2 + 0.3 = 0.5. Therefore D₃,₃ = 0.5.

Place the values on the diagonal: Because D is diagonal, the three calculated values occupy D₁,₁, D₂,₂, and D₃,₃. The off-diagonal positions of D are zero.

For this generated example, the degree matrix has diagonal entries 1.0, 1.1, and 0.5.

Partitioning the graph

Once pairwise similarities have been represented as weighted edges, clustering becomes a graph-partitioning problem. A useful partition places strongly connected points in the same group and keeps weakly connected relationships between groups. This expresses both sides of the clustering objective: high-weight internal edges and low-weight edges that cross from one group to another.

internal relationshipinternal relationshipcross-group relationshipcross-group relationshipweak connection between groupsPoint 1Group APoints 1 and 2Point 2Group BPoint 3Point 3Strong edge0.8Weak edge0.2 or 0.3
How does dividing the graph into groups separate strongly connected points from weakly connected points?

In the generated example, Points 1 and 2 have weight 0.8 between them, while their relationships with Point 3 have weights 0.2 and 0.3. A partition placing Points 1 and 2 together and Point 3 in another group follows the stated objective: the strongest relationship remains internal, and the weaker relationships cross the group boundary.

Subtracting W from D

The unnormalized graph Laplacian is defined as L = D - W. It combines the diagonal degree information in D with the pairwise similarity information in W. The Laplacian is the central mathematical object in this graph-based formulation of clustering.

combinesubtractcontainscontainsDdiagonal degreesLD - WDiagonal entriesdegree minus W diagonalWpairwise weightsOff-diagonal entriesnegative W entries
How does subtracting W from D produce L, and what happens to diagonal and off-diagonal entries?

Building L in the generated example

Use the generated degree values 1.0, 1.1, and 0.5 together with the generated similarity weights to construct the unnormalized graph Laplacian.

Start with D: Place 1.0, 1.1, and 0.5 on the diagonal of D.

Use W: Use the pairwise weights 0.8, 0.2, and 0.3 in the corresponding positions of W.

Subtract: Compute each entry of L by subtracting the corresponding entry of W from the corresponding entry of D.

Interpret the positions: On the diagonal, D contributes the degree and W is subtracted. Off the diagonal, D contributes its diagonal structure while the pairwise W entries are subtracted.

The result is the unnormalized graph Laplacian L = D - W. Its entries combine total connection strength with pairwise similarity structure.

Three matrices, three roles

ObjectWhat it containsHow it is obtainedRole in the construction
WPairwise similarity weightsWeights are defined from pairwise relationships; a distance function and parameter σ can be used in an exponential similarity expressionRepresents the weighted graph's relationships
DDiagonal degree valuesEach diagonal entry is the sum of the corresponding row of WRecords the total similarity weight associated with each point
LThe unnormalized graph LaplacianL = D - WServes as the central mathematical object in the graph-based clustering formulation

The sequence from pairwise similarities to the unnormalized graph Laplacian.

A reliable way to remember the sequence is: first construct W from pairwise similarity information; then sum each row of W to obtain the diagonal entries of D; finally subtract W from D to obtain L. W describes relationships, D summarizes each point's total relationship weight, and L combines those two views.

Common construction mistakes

  • Treating W as a distance matrix rather than a similarity matrix.

    The graph formulation described here uses entries of W as similarity weights on edges.

    Fix: Interpret Wᵢ,ⱼ as the similarity weight assigned to the relationship between points i and j.

  • Using one W entry as the degree of a point.

    The degree matrix is defined from the sum of the corresponding row of W.

    Fix: Add all similarity weights in the relevant row before placing the result on D's diagonal.

  • Putting degree values throughout D.

    D is diagonal.

    Fix: Place each degree only in its matching diagonal position.

  • Constructing L by adding D and W.

    The unnormalized graph Laplacian is defined by subtraction.

    Fix: Use L = D - W and subtract corresponding entries.

  • Choosing groups based only on isolated point labels.

    The graph-partitioning objective concerns high-weight internal edges and low-weight edges between groups.

    Fix: Inspect the weight structure represented by W.

Check your construction

MEDIUM

A generated three-point graph has pairwise similarity weights 0.6 between Points 1 and 2, 0.1 between Points 1 and 3, and 0.4 between Points 2 and 3. Explain which pair has the strongest internal connection if Points 1 and 2 are proposed as one group. Then calculate the three diagonal entries of D by summing the corresponding rows of W, and state how L is obtained from D and W.

Hints
  • The strongest proposed internal connection is the largest weight between the two points in the proposed group.
  • For each degree, add the two pairwise weights appearing in that point's row.
  • After constructing D, use the unnormalized definition L = D - W.
  1. A distance function can provide pairwise information that is converted into similarity weights. Those weights form W, where each data point is a vertex and each pairwise relationship is a weighted edge. Graph partitioning seeks groups with high-weight internal edges and low-weight edges between groups. The degree matrix D is diagonal, with each Dᵢ,ᵢ equal to the sum of row i of W. The unnormalized graph Laplacian is then constructed as L = D - W.

Key Takeaways

  • A similarity graph represents data points as vertices and pairwise similarities as weighted edges.
  • A distance function and parameter can be used to define similarity weights for W through a specified exponential expression.
  • Graph partitioning aims for high-weight connections inside groups and low-weight connections between groups.
  • The degree matrix D is diagonal, and each diagonal entry is the sum of the corresponding row of W.
  • The unnormalized graph Laplacian combines the two matrices through L = D - W.