Menu

Orthogonal Matrix – Detailed Understanding on Orthogonal and Orthonormal Second Order Matrices

Welcome to a deep dive into the concepts of orthogonal and orthonormal second-order matrices. By the end of this blog post, you’ll understand what these terms mean, their significance in data science, and see them in action with some clear examples.

Introduction

In linear algebra and data science, the concept of orthogonality is fundamental. This idea extends to matrices, where we encounter terms like orthogonal and orthonormal matrices. A second-order matrix, also known as a $2 \times 2$ matrix, has two rows and two columns. Let’s delve into the definitions:

Definitions

  1. Orthogonal Matrix: A square matrix $A$ is orthogonal if its transpose $A^T$ is also its inverse $A^{-1}$. This means:
    $A^T A = AA^T = I$
    Where $I$ is the identity matrix.

  2. Orthonormal Matrix: It’s a special kind of orthogonal matrix where the columns (or rows) are not just orthogonal (perpendicular) to each other but also have unit length. For a $2 \times 2$ matrix, this means:
    $ \begin{bmatrix}
    a & b \\
    c & d \\
    \end{bmatrix} $

The columns $[a, c]^T$ and $[b, d]^T$ are orthogonal and their norms (lengths) are both equal to 1.

Why are they important?

Orthogonal matrices have some beautiful properties:

  • Their eigenvalues have a magnitude of 1.
  • They preserve the length of vectors when used for transformations.
  • The determinant of an orthogonal matrix is always +1 or -1.

These properties have found numerous applications in data science, such as in principal component analysis (PCA), QR decomposition, and some algorithms in machine learning.

1. Orthogonal Matrix

A square matrix $A$ is orthogonal if its transpose $A^T$ is also its inverse $A^{-1}$. This means:
$A^T A = AA^T = I$
Where $I$ is the identity matrix.

Example:

Consider the matrix:
$ A = \begin{bmatrix}
\frac{3}{5} & \frac{4}{5} \\
\frac{4}{5} & -\frac{3}{5} \\
\end{bmatrix} $

Verification:

To verify if this is orthogonal, we should compute the product $A^T A$:

$ A^T = \begin{bmatrix}
\frac{3}{5} & \frac{4}{5} \\
\frac{4}{5} & -\frac{3}{5} \\
\end{bmatrix} $

$ A^T A = \begin{bmatrix}
\frac{3}{5} & \frac{4}{5} \\
\frac{4}{5} & -\frac{3}{5}
\end{bmatrix}
\times
\begin{bmatrix}
\frac{3}{5} & \frac{4}{5} \\
\frac{4}{5} & -\frac{3}{5}
\end{bmatrix} = \begin{bmatrix}
1 & 0 \\
0 & 1
\end{bmatrix}
= I $

import numpy as np

# Define the matrix A as mentioned in the post
A = np.array([[3/5, 4/5], [4/5, -3/5]])

# Verify if the matrix is orthogonal
A_transpose = A.T
product = np.dot(A_transpose, A)
identity_matrix = np.identity(2)

is_orthogonal = np.allclose(product, identity_matrix)  # Check if product is close to identity matrix
print(f"Matrix A is orthogonal: {is_orthogonal}")
Matrix A is orthogonal: True
# Properties of Orthogonal matrices
eigenvalues = np.linalg.eigvals(A)
are_eigenvalues_unit_magnitude = np.allclose(np.abs(eigenvalues), 1)

determinant = np.linalg.det(A)
is_determinant_plus_minus_one = np.isclose(np.abs(determinant), 1)

print(f"Eigenvalues have magnitude of 1: {are_eigenvalues_unit_magnitude}")
print(f"Determinant of A is +1 or -1: {is_determinant_plus_minus_one}")
Eigenvalues have magnitude of 1: True
Determinant of A is +1 or -1: True

2. Orthonormality:

It’s a special kind of orthogonal matrix where the columns (or rows) are not just orthogonal (perpendicular) to each other but also have unit length. For a $2 \times 2$ matrix, this means:
$ \begin{bmatrix}
a & b \\
c & d \\
\end{bmatrix} $

The column vectors $[ \frac{3}{5}, \frac{4}{5}]^T$ and $[\frac{4}{5}, -\frac{3}{5}]^T$ are orthogonal since their dot product is zero.

The lengths (or norms) of the vectors are:
$ \sqrt{ (\frac{3}{5})^2 + (\frac{4}{5})^2 } = 1 $
$ \sqrt{ (\frac{4}{5})^2 + (-\frac{3}{5})^2 } = 1 $

As both columns are orthogonal with unit norms, our matrix (A) is orthonormal.

# Check orthonormality of columns
col1 = A[:, 0]
col2 = A[:, 1]

dot_product = np.dot(col1, col2)
is_orthogonal_cols = np.isclose(dot_product, 0)  # Columns are orthogonal if their dot product is close to 0

norm_col1 = np.linalg.norm(col1)
norm_col2 = np.linalg.norm(col2)
is_unit_norms = np.isclose(norm_col1, 1) and np.isclose(norm_col2, 1)  # Check if norms are close to 1

is_orthonormal = is_orthogonal_cols and is_unit_norms
print(f"Columns of Matrix A are orthonormal: {is_orthonormal}")
Columns of Matrix A are orthonormal: True

Significance in Data Science:

  1. Data Transformation: Orthogonal matrices are used for transforming data without distortion. This is particularly useful in PCA where we aim to reduce dimensionality while preserving as much data variance as possible.

  2. Stability: Orthogonal transformations are numerically stable, which is beneficial when dealing with large datasets or when precision is crucial.

  3. Decompositions: Orthogonal matrices are crucial in the QR decomposition, which splits a matrix into an orthogonal matrix and an upper triangular matrix. This decomposition is foundational in many algorithms.

Conclusion:

Orthogonal and orthonormal matrices play a pivotal role in the world of data science and linear algebra. Their properties of preserving vector lengths and angles are invaluable in various applications, ensuring data integrity and precision in transformations. Understanding these concepts can unlock a deeper comprehension of numerous algorithms and methodologies in data science.

Course Preview

Machine Learning A-Z™: Hands-On Python & R In Data Science

Free Sample Videos:

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science

Machine Learning A-Z™: Hands-On Python & R In Data Science