Special Matrices — Identity Matrix, Diagonal Matrix, Symmetric Matrix
Special Matrices -- Identity Matrix, Diagonal Matrix, Symmetric Matrix
Some matrix types appear frequently in AI, and they have special structures and properties. Understanding them can help you quickly grasp the meaning of optimizer behavior, regularization effects, and data transformations.
** Identity Matrix I
All elements on the main diagonal are 1, and all others are 0
Multiplying by any matrix = unchanged
Equivalent to the number "1"
** Diagonal Matrix
Only values on the main diagonal
Each dimension is scaled independently
Equivalent to an audio equalizer
** Symmetric matrix
Transpose = itself
Symmetric with respect to the main diagonal
All eigenvalues are real numbers
Identity matrix: the "1" in mathematics
[ \mathbf{I}_n = \begin{bmatrix} 1 & 0 & \cdots & 0 \ 0 & 1 & \cdots & 0 \ \vdots & \vdots & \ddots & \vdots \ 0 & 0 & \cdots & 1 \end{bmatrix} ]
For any shape-compatible matrix A: ( \mathbf{I}A = A ), ( A\mathbf{I} = A ).
Diagonal matrix: independently scales each dimension
[ \mathbf{D} = \text{diag}(d_1, d_2, \dots, d_n) = \begin{bmatrix} d_1 & 0 & \cdots & 0 \ 0 & d_2 & \cdots & 0 \ \vdots & \vdots & \ddots & \vdots \ 0 & 0 & \cdots & d_n \end{bmatrix} ]
Diagonal matrix multiplied by a vector = applying different scaling factors to each component of the vector independently.
Symmetric matrix: remains the same after transposition
( \mathbf{A}^T = \mathbf{A} ), which means ( a_{ij} = a_{ji} ).
Symmetric matrices have a very important property:All eigenvalues are real numbers.The eigenvectors are mutually orthogonal.
This makes symmetric matrices extremely useful in optimization and statistics—the covariance matrix and the Hessian matrix are both symmetric matrices.
Real-life examples
**Identity matrix: an operation that does nothing.
You open an image in PS and save it without any edits. Input = Output.
The identity matrix is the mathematical expression for this "doing nothing."
**Diagonal Matrix: Audio Equalizer
Each slider in the equalizer independently controls the volume of a frequency band—high frequency +3dB, low frequency -2dB, mid frequency unchanged.
Each frequency band is independent and scaled separately. This is the behavior of a diagonal matrix.
**Symmetric Matrix: Reflection in a Mirror
When standing in front of a mirror, your left hand corresponds to the right hand's position in the mirror. Up and down remain the same, but left and right are swapped.
A symmetric matrix is similar—it is symmetric about the main diagonal, and the values remain unchanged after swapping the up and down positions.
Mathematical definition
| Matrix type | Definition conditions | Notation |
|---|---|---|
| Identity matrix | ( I_{ii}=1, I_{ij}=0 ; (i \neq j) ) | ( \mathbf{I}_n ) |
| Diagonal matrix | ( D_{ij}=0 ) when ( i \neq j ) | diag(d₁,...,dₙ) |
| Symmetric matrix | ( A_{ij} = A_{ji} ) for all i,j | ( \mathbf{A} = \mathbf{A}^T ) |
Python hands-on practice
Example
import
numpy
as
np
identity matrix
I
=
np.
eye
(
3
)
A
=
np.
array
(
[
[
4
,
7
,
2
]
,
[
3
,
5
,
1
]
,
[
6
,
8
,
9
]
]
)
(
"I @ A == A:"
,
np.
allclose
(
I
@
A
,
A
)
)
Diagonal Matrix: Independent Scaling
D
=
np.
diag
(
[
2
,
3
,
5
]
)
v
=
np.
array
(
[
1
,
1
,
1
]
)
(
"D @ [1,1,1] ="
,
D
@
v
)
[2, 3, 5]
Symmetric matrix
S
=
np.
array
(
[
[
1
,
4
,
5
]
,
[
4
,
2
,
6
]
,
[
5
,
6
,
3
]
]
)
(
"S symmetric:"
,
np.
allclose
(
S.
T
,
S
)
)
eigenvalues
=
np.
linalg
.
eigvals
(
S
)
(
"Eigenvalues are all real:"
,
np.
all
(
np.
isreal
(
eigenvals
)
)
)
The covariance matrix is naturally symmetric
data
=
np.
random
.
randn
(
100
,
5
)
cov
=
np.
cov
(
data.
T
)
(
"Covariance matrix is symmetric:"
,
np.
allclose
(
cov
,
cov.
T
)
)
Original prompt (Chinese, left untranslated)
I @ A == A: True
D @ [1,1,1] = [2 3 5]
S 对称: True
特征值全实数: True
协方差矩阵对称: True
Application scenarios in AI
Adam optimizer = diagonal matrix adaptive scaling
Adam maintains an exponentially moving average of the squared gradients for each parameter, $v_t$, and updates using $(\theta_{t+1} = \theta_t - \eta \cdot m_t / \sqrt{v_t})$. Mathematically, $(1/\sqrt{v_t})$ scales each parameter component independently—this is a diagonal matrix multiplied by the gradient vector. Active gradient components are scaled down by the learning rate, while inactive gradient components are scaled up.
Covariance matrix used in PCA
The first step of PCA dimensionality reduction: calculating the covariance matrix of the centered data $(\Sigma = X^TX/(n-1))$. This is a symmetric matrix $(\Sigma_{ij} = \Sigma_{ji})$ whose eigenvalues are all real numbers. The eigenvectors corresponding to the largest $k$ eigenvalues are the principal component directions. The PCA class in sklearn performs this operation internally.
Identity initialization of recurrent neural networks
The recurrent weight matrices of RNN and LSTM are often initialized as identity matrices. This ensures that in the early stages of training, information in the hidden state is passed "unchanged," preventing gradients from decaying too quickly across time steps. This technique is called IRNN (Identity RNN).
Xavier/Glorot Initialization
Xavier initialization carefully selects the variance of the weights to keep the variance of the output of each layer consistent: ( Var(W) = 2/(n_{in} + n_{out}) ). This is equivalent to constraining the diagonal matrix (variance) from a normal distribution with this variance.