Concepts / Matrix representations of data relationships

Matrix representations of data relationships

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

  • Programming

From Data Points to Relationships

Clustering is often introduced as grouping similar data points. A graph-based representation makes that goal visible: each data point becomes a vertex, and the relationship between two points becomes a weighted edge. The resulting similarity graph can then be represented with matrices that record pairwise similarity, node connectivity, and the structure used for graph-based clustering.

Point 1vertexW[1,2]similarity weightSimilarity graphweighted edgesPoint 2vertexW[1,3]similarity weightWsimilarity matrixPoint 3vertexW[2,3]similarity weightpairwise relationshippairwise relationshippairwise relationshippairwise relationshippairwise relationshippairwise relationshipedge weightedge weightedge weightmatrix entrymatrix entrymatrix entry
How does each data point become a vertex, and how do pairwise similarity values become weighted edges and entries in W?

Building the Similarity Matrix

The similarity matrix W records the pairwise relationships represented by the graph. An entry of W corresponds to the similarity weight associated with a pair of data points. Large weights represent stronger relationships, while small weights represent weaker relationships. The way weights are assigned depends on the chosen similarity definition. One possible construction uses a distance function d and a parameter σ, applying the specified exponential expression to the distance between two points.

For this illustration, the three rows and three columns correspond to three data points. The value 0.9 represents a stronger relationship between Point 1 and Point 2 than the values 0.2 and 0.3 represent for the other pairings. These numbers are an illustrative choice; the source concept is that W stores pairwise similarity weights.

Partitioning the Graph

Once the data has been represented as a similarity graph, clustering becomes a graph-partitioning problem. A good partition places strongly connected points in the same group and leaves weaker connections between groups. In matrix terms, the clustering objective is expressed through high-weight internal edges and low-weight edges between groups.

Point 10.9 to Point 2Cluster APoints 1 and 2Point 20.9 to Point 1Cluster BPoint 3Point 30.2 and 0.3 to others0.9internal edge0.2 and 0.3between-cluster edgesstrong similarityweak similarityweak similaritycontainsseparated from Cluster B byconnected through
What changes when the similarity graph is divided into clusters, and how does the partition separate strong internal connections from weaker connections between groups?
Worked example

A Three-Point Partition

Using the illustrative weights W[1,2] = 0.9, W[1,3] = 0.2, and W[2,3] = 0.3, identify a partition that reflects stronger internal similarity and weaker connections between groups.

  1. 1
    Compare the pairwise weights

    The relationship between Points 1 and 2 has weight 0.9, which is larger than the relationships from Point 3 to Points 1 and 2.

  2. 2
    Propose the groups

    Place Points 1 and 2 in one group and Point 3 in another group.

  3. 3
    Check the partition

    The 0.9 relationship is internal to the first group, while 0.2 and 0.3 are connections between the proposed groups.

Result

The partition {Point 1, Point 2} and {Point 3} illustrates the objective of high-weight internal connections and lower-weight connections between groups.

Reading Node Degrees

Definition

The degree matrix D records the total similarity associated with each data point. D is diagonal, and each diagonal entry Dᵢ,ᵢ equals the sum of the corresponding row of W. Every off-diagonal entry of D is zero.

Row 1 of W0, 0.9, 0.2D[1,1]1.1Row 2 of W0.9, 0, 0.3D[2,2]1.2Row 3 of W0.2, 0.3, 0D[3,3]0.5Off-diagonal entries0sum = 1.1sum = 1.2sum = 0.5not placed off diagonalnot placed off diagonalnot placed off diagonal
How is each diagonal entry of D calculated from a row of W, and why are all off-diagonal entries of D zero?
Formula, step by step
  1. 1
    For Point 1, add the first row: 0 + 0.9 + 0.2 = 1.1.
  2. 2
    For Point 2, add the second row: 0.9 + 0 + 0.3 = 1.2.
  3. 3
    For Point 3, add the third row: 0.2 + 0.3 + 0 = 0.5.
  4. 4
    Place 1.1, 1.2, and 0.5 on the diagonal of D.
  5. 5
    Place zero in every off-diagonal position.

Forming the Laplacian

Definition

The unnormalized graph Laplacian is defined by L = D - W. It combines the degree information in D with the pairwise similarity information in W.

Ddiagonal degree valuesD - Wentry-by-entry subtractionLunnormalized LaplacianWpairwise similaritiesfirst matrixsubtracted matrixresult
How do the entries of D and W combine through L = D - W?
Worked example

Entry-by-Entry Construction

Construct L for the illustrative matrices W and D.

  1. 1
    Subtract on the diagonal

    At position [1,1], calculate 1.1 - 0 = 1.1. At [2,2], calculate 1.2 - 0 = 1.2. At [3,3], calculate 0.5 - 0 = 0.5.

  2. 2
    Subtract off the diagonal

    At [1,2], calculate 0 - 0.9 = -0.9. At [1,3], calculate 0 - 0.2 = -0.2. At [2,3], calculate 0 - 0.3 = -0.3. The corresponding remaining positions are calculated in the same way.

  3. 3
    Assemble the result

    Place each calculated difference in the matching position of L.

Result

L = [[1.1, -0.9, -0.2], [ -0.9, 1.2, -0.3], [ -0.2, -0.3, 0.5]]

Three Matrices Three Roles

Wpairwise similaritiesDrow-sum degreesLD - Wsum each rowcombine with Wsubtract from D
What does each matrix represent, and how does information move from pairwise similarities to degrees and then to the Laplacian?
MatrixWhat it representsHow it is constructed
WPairwise similarity relationshipsIts entries contain similarity weights between data points
DTotal similarity associated with each data pointIt is diagonal; Dᵢ,ᵢ is the sum of row i of W
LThe unnormalized graph LaplacianL = D - W

The three matrix roles in the graph-based formulation

The construction is sequential but the roles are different. W starts with pairwise relationships. D compresses each row of W into one diagonal value, representing the row's total similarity. L then compares this diagonal degree information with the original pairwise similarities through subtraction.

Common Matrix Mistakes

  • Common mistake

    Treating W as the degree matrix

    What it looks like

    Using the individual pairwise weights as the diagonal entries of D.

    Why it fails

    W records pairwise similarities, while D uses the sum of an entire row of W for each diagonal entry.

    Do this instead

    For each i, calculate Dᵢ,ᵢ by summing row i of W, then set every off-diagonal entry of D to zero.

  • Common mistake

    Putting row sums throughout D

    What it looks like

    Writing 1.1 in several positions of the first row of D.

    Why it fails

    The degree matrix is diagonal, so its nonzero degree values belong on matching diagonal positions.

    Do this instead

    Place the degree for Point i at Dᵢ,ᵢ and use zero elsewhere in that row and column.

  • Common mistake

    Computing L as W - D

    What it looks like

    Reversing the subtraction in the Laplacian formula.

    Why it fails

    The unnormalized graph Laplacian is defined as L = D - W.

    Do this instead

    Start with D and subtract W entry by entry.

  • Common mistake

    Assuming clustering only requires strong internal edges

    What it looks like

    Choosing a group with strong internal relationships while ignoring the weights connecting it to other groups.

    Why it fails

    The clustering objective includes both high-weight internal edges and low-weight edges between groups.

    Do this instead

    Evaluate internal and between-group relationships together.

Check Your Construction

MEDIUM

Suppose a three-point similarity matrix is W = [[0, 0.6, 0.1], [0.6, 0, 0.2], [0.1, 0.2, 0]]. Calculate D and then construct L using L = D - W. Finally, identify which pair of points has the strongest similarity and propose a partition that places that pair together.

Hints
  • Calculate each diagonal entry of D by summing one row of W.
  • Put zero in every off-diagonal position of D.
  • Subtract the corresponding entry of W from the corresponding entry of D.
  1. 1
    Begin with W, the matrix of pairwise similarity weights. Sum each row of W to obtain the diagonal entries of D, and keep every off-diagonal entry of D equal to zero. Then form the unnormalized graph Laplacian with L = D - W. The clustering objective is represented by a partition with high-weight internal connections and low-weight connections between groups.

Key Takeaways

  • A similarity graph turns data points into vertices and pairwise similarities into weighted edges.
  • The matrix W records the pairwise similarity weights.
  • The diagonal degree matrix D is obtained by summing each row of W.
  • The unnormalized graph Laplacian is L = D - W.
  • Graph partitioning seeks groups with strong internal connections and weak connections between groups.

Related concepts

More concepts starting with M