7.14 그래디언트 벡터의 정의와 계산
1. 그래디언트 벡터의 정의
다변수 스칼라 함수 f: \mathbb{R}^n \to \mathbb{R}가 주어졌을 때, 그래디언트 벡터(gradient vector)는 f의 각 독립 변수에 대한 편미분을 성분으로 하는 벡터이다. 변수 벡터 \mathbf{x} = [x_1, x_2, \dots, x_n]^T에 대하여 그래디언트는 다음과 같이 정의된다.
\nabla f(\mathbf{x}) = \frac{\partial f}{\partial \mathbf{x}} = \begin{bmatrix} \dfrac{\partial f}{\partial x_1} \\[8pt] \dfrac{\partial f}{\partial x_2} \\[8pt] \vdots \\[8pt] \dfrac{\partial f}{\partial x_n} \end{bmatrix}
여기서 \nabla는 나블라 연산자(nabla operator)이며, 그래디언트 벡터는 \text{grad}\, f로 표기하기도 한다. 그래디언트는 함수 f가 가장 빠르게 증가하는 방향을 가리키며, 그 크기는 해당 방향으로의 변화율의 최댓값과 같다.
2. 그래디언트의 기하학적 의미
2.1 등위면과의 관계
스칼라 함수 f(\mathbf{x}) = c (상수)로 정의되는 등위면(level surface)을 고려하자. 등위면 위의 임의의 곡선 \mathbf{r}(t)에 대해 f(\mathbf{r}(t)) = c이므로 양변을 t에 대해 미분하면
\frac{d}{dt} f(\mathbf{r}(t)) = \nabla f \cdot \frac{d\mathbf{r}}{dt} = 0
이다. 이는 그래디언트 벡터 \nabla f가 등위면에 대해 항상 법선 방향(normal direction)임을 의미한다.
2.2 방향도함수와의 관계
단위 벡터 \hat{\mathbf{u}} 방향으로의 방향도함수(directional derivative)는
D_{\hat{\mathbf{u}}} f = \nabla f \cdot \hat{\mathbf{u}} = \lVert \nabla f \rVert \cos\theta
로 주어진다. 여기서 \theta는 \nabla f와 \hat{\mathbf{u}} 사이의 각도이다. 이로부터 다음 성질을 도출할 수 있다.
- \theta = 0일 때 방향도함수가 최대: D_{\hat{\mathbf{u}}} f = \lVert \nabla f \rVert
- \theta = \pi일 때 방향도함수가 최소: D_{\hat{\mathbf{u}}} f = -\lVert \nabla f \rVert
- \theta = \pi/2일 때 방향도함수가 0: 등위면 접선 방향
3. 그래디언트의 좌표 표현
3.1 직교 좌표계
직교 좌표계(Cartesian coordinate system) (x, y, z)에서 그래디언트는
\nabla f = \frac{\partial f}{\partial x} \hat{\mathbf{e}}_x + \frac{\partial f}{\partial y} \hat{\mathbf{e}}_y + \frac{\partial f}{\partial z} \hat{\mathbf{e}}_z
이다.
3.2 원통 좌표계
원통 좌표계(cylindrical coordinate system) (r, \phi, z)에서는
\nabla f = \frac{\partial f}{\partial r} \hat{\mathbf{e}}_r + \frac{1}{r} \frac{\partial f}{\partial \phi} \hat{\mathbf{e}}_\phi + \frac{\partial f}{\partial z} \hat{\mathbf{e}}_z
이다.
3.3 구면 좌표계
구면 좌표계(spherical coordinate system) (r, \theta, \phi)에서는
\nabla f = \frac{\partial f}{\partial r} \hat{\mathbf{e}}_r + \frac{1}{r} \frac{\partial f}{\partial \theta} \hat{\mathbf{e}}_\theta + \frac{1}{r \sin\theta} \frac{\partial f}{\partial \phi} \hat{\mathbf{e}}_\phi
이다.
3.4 일반 곡선 좌표계
일반 곡선 좌표계에서 계량 텐서(metric tensor) g_{ij}가 주어지면, 그래디언트의 반변 성분(contravariant component)은
(\nabla f)^i = g^{ij} \frac{\partial f}{\partial x^j}
로 계산된다. 여기서 g^{ij}는 계량 텐서의 역행렬 성분이며, 아인슈타인 합산 규약(Einstein summation convention)을 사용하였다.
4. 그래디언트 계산의 실제 예
4.1 예제 1: 2차 형식
f(\mathbf{x}) = \mathbf{x}^T \mathbf{A} \mathbf{x}에서 \mathbf{A}가 n \times n 대칭 행렬일 때, 그래디언트를 계산하자. 함수를 성분으로 전개하면
f(\mathbf{x}) = \sum_{i=1}^{n} \sum_{j=1}^{n} A_{ij} x_i x_j
이므로
\frac{\partial f}{\partial x_k} = \sum_{j=1}^{n} A_{kj} x_j + \sum_{i=1}^{n} A_{ik} x_i = 2 \sum_{j=1}^{n} A_{kj} x_j
이다. 마지막 등호에서 \mathbf{A}의 대칭성 A_{ij} = A_{ji}를 이용하였다. 따라서
\nabla f = 2 \mathbf{A} \mathbf{x}
이다.
4.2 예제 2: 벡터 노름
f(\mathbf{x}) = \lVert \mathbf{x} \rVert^2 = \mathbf{x}^T \mathbf{x}이면, \mathbf{A} = \mathbf{I} (단위 행렬)인 경우에 해당하므로
\nabla \lVert \mathbf{x} \rVert^2 = 2 \mathbf{x}
이다. 또한 g(\mathbf{x}) = \lVert \mathbf{x} \rVert = \sqrt{\mathbf{x}^T \mathbf{x}}의 그래디언트는 연쇄 법칙에 의해
\nabla \lVert \mathbf{x} \rVert = \frac{\mathbf{x}}{\lVert \mathbf{x} \rVert}
이며, 이는 \mathbf{x} 방향의 단위 벡터이다.
4.3 예제 3: 로봇공학에서의 포텐셜 함수
장애물 회피를 위한 인공 포텐셜 함수(artificial potential function)를 고려하자. 장애물 위치를 \mathbf{x}_o, 로봇 위치를 \mathbf{x}라 하면, 반발 포텐셜(repulsive potential)은
U_{\text{rep}}(\mathbf{x}) = \begin{cases} \dfrac{1}{2} \eta \left( \dfrac{1}{d(\mathbf{x})} - \dfrac{1}{d_0} \right)^2, & d(\mathbf{x}) \leq d_0 \\[8pt] 0, & d(\mathbf{x}) > d_0 \end{cases}
로 정의된다. 여기서 d(\mathbf{x}) = \lVert \mathbf{x} - \mathbf{x}_o \rVert는 장애물까지의 거리, d_0는 영향 범위, \eta는 양의 상수이다. d(\mathbf{x}) \leq d_0인 영역에서 그래디언트를 계산하면
\nabla U_{\text{rep}} = \eta \left( \frac{1}{d(\mathbf{x})} - \frac{1}{d_0} \right) \frac{1}{d^2(\mathbf{x})} \frac{\mathbf{x} - \mathbf{x}_o}{\lVert \mathbf{x} - \mathbf{x}_o \rVert}
이며, 반발력은 \mathbf{F}_{\text{rep}} = -\nabla U_{\text{rep}} 방향으로 작용한다.
5. 행렬·벡터 함수에 대한 그래디언트 공식
로봇공학에서 자주 사용되는 그래디언트 공식을 정리하면 다음과 같다.
| 함수 f(\mathbf{x}) | 그래디언트 \nabla f |
|---|---|
| \mathbf{a}^T \mathbf{x} | \mathbf{a} |
| \mathbf{x}^T \mathbf{A} \mathbf{x} (\mathbf{A} 대칭) | 2\mathbf{A}\mathbf{x} |
| \mathbf{x}^T \mathbf{x} | 2\mathbf{x} |
| \lVert \mathbf{x} - \mathbf{a} \rVert^2 | 2(\mathbf{x} - \mathbf{a}) |
| \lVert \mathbf{A}\mathbf{x} - \mathbf{b} \rVert^2 | 2\mathbf{A}^T(\mathbf{A}\mathbf{x} - \mathbf{b}) |
| \ln(\mathbf{a}^T \mathbf{x}) | \dfrac{\mathbf{a}}{\mathbf{a}^T \mathbf{x}} |
6. 수치적 그래디언트 계산
해석적 그래디언트를 구하기 어려운 경우 수치적 방법을 사용한다. 중앙 차분법(central difference method)에 의한 i번째 성분의 근사는
\frac{\partial f}{\partial x_i} \approx \frac{f(\mathbf{x} + h \mathbf{e}_i) - f(\mathbf{x} - h \mathbf{e}_i)}{2h}
이다. 여기서 \mathbf{e}_i는 i번째 표준 단위 벡터, h는 미소 변위이다. n차원 공간에서 전체 그래디언트를 수치적으로 계산하려면 함수를 2n회 평가해야 한다.
자동 미분(automatic differentiation)은 수치 미분의 반올림 오차(round-off error)와 절단 오차를 동시에 피하면서 기계 정밀도(machine precision)로 정확한 그래디언트를 계산하는 기법이다. 전방 모드(forward mode)와 역방향 모드(reverse mode)가 있으며, 역방향 모드는 n이 클 때 특히 효율적이다.
7. 로봇공학에서의 그래디언트 응용
7.1 최적화 기반 제어
로봇 제어에서 비용 함수(cost function) J(\mathbf{q})를 최소화하는 문제에 그래디언트 하강법(gradient descent)을 적용한다.
\mathbf{q}_{k+1} = \mathbf{q}_k - \alpha \nabla J(\mathbf{q}_k)
여기서 \alpha > 0는 학습률(learning rate)이다.
7.2 역기구학에서의 그래디언트
역기구학 오차 함수
e(\mathbf{q}) = \frac{1}{2} \lVert \mathbf{x}_d - \mathbf{f}(\mathbf{q}) \rVert^2
의 그래디언트는
\nabla e = -\mathbf{J}^T(\mathbf{q}) \bigl(\mathbf{x}_d - \mathbf{f}(\mathbf{q})\bigr)
이며, 이를 경사법에 적용하면 수렴이 보장되는 역기구학 해법을 구성할 수 있다.
7.3 경로 계획
포텐셜 필드(potential field) 방법에서 로봇은 인력 포텐셜(attractive potential)과 반발 포텐셜의 합으로 구성된 총 포텐셜
U(\mathbf{x}) = U_{\text{att}}(\mathbf{x}) + U_{\text{rep}}(\mathbf{x})
의 음의 그래디언트 방향으로 이동한다.
\dot{\mathbf{x}} = -\nabla U(\mathbf{x})
이 방법은 계산이 간단하지만 국소 최소점(local minimum)에 빠질 수 있다는 한계가 있다.
8. 참고 문헌
- Marsden, J. E., & Tromba, A. J. (2012). Vector Calculus. 6th ed. W. H. Freeman.
- Siciliano, B., Sciavicco, L., Villani, L., & Oriolo, G. (2009). Robotics: Modelling, Planning and Control. Springer.
- Khatib, O. (1986). “Real-Time Obstacle Avoidance for Manipulators and Mobile Robots.” International Journal of Robotics Research, 5(1), 90–98.
- Boyd, S., & Vandenberghe, L. (2004). Convex Optimization. Cambridge University Press.
- Petersen, K. B., & Pedersen, M. S. (2012). The Matrix Cookbook. Technical University of Denmark.
v 0.1