Mathematics

[선형대수학#11] 내적(Inner Product)

j.d 2026. 3. 26. 22:18

이번 포스팅에서는 벡터의 길이와 각도를 다루는 내적을 정리한다. 내적은 벡터 간의 유사성을 측정하는 가장 기본적인 도구이며, 추천 시스템의 cosine similarity부터 신경망의 가중합까지 ML 전반에 걸쳐 사용된다.

 

벡터의 길이와 거리

길이(Length, Norm)

$\mathbb{R}^2$에서 $\mathbf{a} = \begin{pmatrix} a_1 \\ a_2 \end{pmatrix}$의 길이(norm)는 피타고라스 정리로부터 자연스럽게 정의된다.

 

출처: http://mathonline.wikidot.com/the-norm-of-a-vector

 

$$\lVert \mathbf{a} \rVert = \sqrt{a_1^2 + a_2^2}$$

 

이를 $\mathbb{R}^n$으로 일반화하면 $ \lVert \mathbf{a} \rVert = \sqrt{a_1^2 + a_2^2 + \cdots + a_n^2} $이다.

 

벡터 간의 거리

$\mathbb{R}^2$에서 두 벡터 $\mathbf{a} = \begin{pmatrix} a_1 \\ a_2 \end{pmatrix}, \quad \mathbf{b} = \begin{pmatrix} b_1 \\ b_2 \end{pmatrix}$ 사이의 거리는 차이 벡터의 길이로 정의된다.

 

출처: https://mbernste.github.io/posts/normed_vector_space/

 

$$\lVert \mathbf{b} - \mathbf{a} \rVert = \sqrt{(b_1 - a_1)^2 + (b_2 - a_2)^2}$$

 

$\mathbb{R}^n$에서는 동일한 방식으로 $\lVert \mathbf{b} - \mathbf{a} \rVert = \sqrt{(b_1 - a_1)^2 + (b_2 - a_2)^2 + \cdots + (b_n - a_n)^2}$이다.

 

즉, 벡터 간의 거리란 두 벡터를 점으로 봤을 때의 유클리드 거리(Euclidean distance)와 같다.

 

내적

$\mathbb{R}^n$에서 두 벡터 $\mathbf{a}, \mathbf{b}$의 내적(dot product)은 대응하는 성분의 곱의 합으로 정의된다.

 

$$\mathbf{a} \cdot \mathbf{b} = a_1 b_1 + a_2 b_2 + \cdots + a_n b_n = \sum_{i=1}^{n} a_i b_i$$

 

정의 자체는 단순하다. 그렇다면 이 연산이 기하학적으로 무엇을 의미하는지 코사인 법칙을 통해 확인해보자.

 

내적의 기하학적 의미

출처: https://mathinsight.org/dot_product

 

$\mathbb{R}^2$에서 두 벡터 $\mathbf{a}, \mathbf{b}$사이의 각도를 $\theta$라 하면, 코사인 법칙에 의해

 

$$\lVert \mathbf{b} - \mathbf{a} \rVert^2 = \lVert \mathbf{b} \rVert^2 + \lVert \mathbf{a} \rVert^2 - 2 \lVert \mathbf{a} \rVert \lVert \mathbf{b} \rVert \cos\theta$$

 

가 성립한다. 이를 $ \cos\theta $에 대해 정리하면

 

$$\cos\theta = \frac{\lVert \mathbf{b} \rVert^2 + \lVert \mathbf{a} \rVert^2 - \lVert \mathbf{b} - \mathbf{a} \rVert^2}{2 \lVert \mathbf{a} \rVert \lVert \mathbf{b} \rVert}$$

 

이다. 분자를 직접 전개해 보자.

 

$$\begin{aligned}
\lVert \mathbf{b} \rVert^2 + \lVert \mathbf{a} \rVert^2 - \lVert \mathbf{b} - \mathbf{a} \rVert^2 
&= (b_1^2 + b_2^2) + (a_1^2 + a_2^2) - \{(b_1 - a_1)^2 + (b_2 - a_2)^2\} \\
&= b_1^2 + b_2^2 + a_1^2 + a_2^2 - (b_1^2 - 2a_1b_1 + a_1^2) - (b_2^2 - 2a_2b_2 + a_2^2) \\
&= b_1^2 + b_2^2 + a_1^2 + a_2^2 - b_1^2 + 2a_1b_1 - a_1^2 - b_2^2 + 2a_2b_2 - a_2^2 \\
&= 2(a_1b_1 + a_2b_2)
\end{aligned}$$

 

분자가 $2(\mathbf{a} \cdot \mathbf{b})$임을 알 수 있다. 따라서 

 

$$\cos\theta = \frac{\mathbf{a} \cdot \mathbf{b}}{\lVert \mathbf{a} \rVert \lVert \mathbf{b} \rVert} \quad (0 \le \theta \le \pi)$$

 

이다. 즉, 내적은 두 벡터 사이의 각도와 직접 연결된다. 내적의 값과 각도의 관계를 정리하면 다음과 같다.

 

  • $\mathbf{a} \cdot \mathbf{b} > 0$: 예각 $(\theta < 90^\circ)$
  • $\mathbf{a} \cdot \mathbf{b} = 0$: 직각 $(\theta = 90^\circ)$
  • $\mathbf{a} \cdot \mathbf{b} < 0$: 둔각 $(\theta > 90^\circ)$

 

이때, 두 벡터 $\mathbf{a}, \mathbf{b}$가 $ \mathbf{a} \cdot \mathbf{b} = 0$이면 두 벡터를 직교(orthogonal)라고 한다. 

 

내적 공간(Inner Product Space)

지금까지 $\mathbb{R}^n$에서 $\mathbf{a} \cdot \mathbf{b} = a_1 b_1 + a_2 b_2 + \cdots + a_n b_n$이라는 구체적인 연산읠 정의했다. 이것은 dot product라 불리며, 내적(inner product)의 한 종류다. inner prodcut란 아래 4가지 공리를 만족하는 연산을 총칭하는 말이다. dot product 외에도 가중합이나 함수의 적분 등 다양한 inner product가 존재하지만, 이들은 모두 4가지 공리를 공유한다. 이러한 inner product가 정의된 벡터 공간을 내적 공간(inner product space)이라 한다.

 

실벡터 공간 $V$에서의 세 벡터 $\mathbf{a}, \mathbf{b}. \mathbf{c}$와 스칼라 $k$가 주어졌을 때, 다음 네 가지 조건을 만족하는 연산 $\langle \cdot, \cdot \rangle$이 정의되면 $V$를 내적 공간이라 한다.

 

$$\begin{aligned}
&\text{(1)} \quad \langle \mathbf{a}, \mathbf{a} \rangle \ge 0 \quad (\langle \mathbf{a}, \mathbf{a} \rangle = 0 \iff \mathbf{a} = \mathbf{0}) \quad &&\text{(양의 정부호성)} \\
&\text{(2)} \quad \langle \mathbf{a}, \mathbf{b} \rangle = \langle \mathbf{b}, \mathbf{a} \rangle \quad &&\text{(대칭성)} \\
&\text{(3)} \quad \langle \mathbf{a} + \mathbf{b}, \mathbf{c} \rangle = \langle \mathbf{a}, \mathbf{c} \rangle + \langle \mathbf{b}, \mathbf{c} \rangle \quad &&\text{(분배법칙)} \\
&\text{(4)} \quad \langle k\mathbf{a}, \mathbf{b} \rangle = k\langle \mathbf{a}, \mathbf{b} \rangle \quad &&\text{(스칼라 동차성)}
\end{aligned}$$

 

조건 (1)은 자기 자신과의 내적이 항상 0 이상이며, 0이 되는 경우는 영벡터뿐임을 뜻한다. 이것이 길이(norm)을 $ \lVert \mathbf{a} \rVert = \sqrt{\langle \mathbf{a}, \mathbf{a} \rangle} $로 정의할 수 있게 해주는 근거이다. 조건 (2) ~ (4)는 내적이 선형성과 대칭성을 가진 연산임을 보장한다. $\mathbb{R}^n$에서의 dot product가 이 네 조건을 만족하는 것을 쉽게 확인할 수 있다.

 

단위 벡터(Unit Vector)

길이가 1인 벡터를 단위 벡터(unit vector)라 한다. 영벡터가 아닌 $\mathbf{a}$를 단위 벡터 $\mathbf{u}$로 변환하는 과정을 정규화(normalization)라 하며, 다음과 같다.

 

$$ \mathbf{u} = \frac{1}{\lVert \mathbf{a} \rVert} \mathbf{a} $$

 

방향은 유지하되 크기만 1로 맞추는 연산이다.

 

직교 집합과 일차 독립

내적 공간 $V$에서 $S = \{\mathbf{v}_1, \mathbf{v}_2, \dots, \mathbf{v}_n\}$이 영벡터가 아닌 벡터들로 이루어진 유한 직교 집합(orthogonal set)이면, $S$는 linearly independent이다. 여기서 직교 집합이란 서로 다른 원소 간의 내적이 모두 0인 집합을 뜻한다.

 

$$\langle \mathbf{v}_i, \mathbf{v}_j \rangle = 0 \quad (i \neq j)$$

 

이 성질이 중요한 이유는, 직교 집합들의 집합이 자동으로 linear independent임을 보장하기 때문이다. 이전 포스팅에서 다뤘듯이 linear independent인 $n$개의 벡터가 있으면 그것이 곧 $n$차원 공간의 basis가 된다. 따라서 직교 집합은 basis를 구성하는 데 매우 편리한 도구이다.