3. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4.1 Overflow and Underflow
4.1 Overflow and Underflow
One form of rounding error that is particularly devastating is underflow.
Underflow occurs when numbers near zero are rounded to zero.
Another highly damaging form of numerical error is overflow. Overflow
occurs when numbers with large magnitude are approximated as ∞ or
−∞.
One example of a function that must be stabilized against underflow and
overflow is the softmax function. The softmax function is often used to
predict the probabilities associated with a multinoulli distribution:
softmax(x)i =
exp(xi)
Σn
j=1exp(xj)
.
JIN HO LEE Chapter 4 Numerical Computation 2018-9-17 3 / 18
4. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4.2 Poor Conditioning
4.2 Poor Conditioning
input 의 작은 변화에 얼마나 빠르게 함수가 변하는가를 condisioning
이라고 한다. input 이 조금씩 변화할 때 함수가 급격하게 변하면 rounding
error 로 인해 문제가 될 수 있다.
함수 eigendecomposition 을 가지는 A ∈ Rn×n 에 대해 f(x) = A−1x 의
condition number 는 아래와 같이 정의된다:
max
i,j
λi
λj
=
maxi |λi|
minj |λj|
.
conditioning error 가 클수록 input 의 작은 변화에 민감하게 된다.
JIN HO LEE Chapter 4 Numerical Computation 2018-9-17 4 / 18
5. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4.3 Gradient-Based Optimization
4.3 Gradient-Based Optimization
대부분의 딥러닝 알고리즘은 최적화문제를 이용하여 학습한다.
최적화문제는 함수 f 에 대해 maxx f(x) 또는 minx f(x) 를 찾는 문제이다.
우리가 최대화 또는 최소화 하고 싶은 함수를 objective 또는 criterion
이라고 한다. 특히 최소화하고 싶은 함수를 cost function, loss function
또는 error function 이라고 한다.
maximize 또는 minimize 하게 하는 값은 ∗ 를 이용하여 표현한다. 예를 들어
x∗ = argminx f(x) 로 표기한다.
derivative f ′ of f 는 다음과 같이 정의된다:
f ′
(x) = lim
ε→0
f(x + ε) − f(x)
ε
.
JIN HO LEE Chapter 4 Numerical Computation 2018-9-17 5 / 18
6. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4.3 Gradient-Based Optimization
따라서 작은 ε 에 대해 f(x + ε) ≈ f(x) + εf ′(x) 이다. 특히 다음 부등식을
만족하는 충분히 작은 ε 이 존재한다:
f(x − ε · sign(f ′
(x))) < f(x).
이 방법을 이용하여 cost function 을 학습하는 방법을 gradient descent
라고 한다.
multiple input 에 대하여 cost function 은 f : Rn → R 같은 형태로
나타난다. 이 때 gradient descent(method of steepest descent) 는
x ′
= x − ε∇xf(x)
로 표현된다. 여기서 ε 을 learning rate 라고 한다.
JIN HO LEE Chapter 4 Numerical Computation 2018-9-17 6 / 18
7. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4.4 Constrained Optimization
4.4 Constrained Optimization
어떤 경우에는 함수 f 의 정의역 전체집합에서의 maximum 또는 minimum
이 아닌, 특정 정의역의 부분집합 S 에서의 maximum 또는 minimum 이
궁금한 경우가 있다. 이런 종류의 문제를 constraint optimization 이라고
하고, x ∈ S 이면 x 를 feasible point 라고 한다.
이번 절에서는 constraint optimization 문제를 푸는 일반적인 방법인
Karush-Kuhn-Tucker(KKT) approach 에 대해 알아보자. 그리고 KKT
approach 함께 generalized Lagrangian(or generalized Lagrangian function)
에 대해 알아보자.
Suppose that
S = {x|∀i, g(i)
(x) = 0 and ∀j, h(j)
(x) ≤ 0}.
i 에 대한 equations g(i)(x) = 0 을 equality constrains 라고 하고, j 에 대한
inequalities h(j)(x) ≤ 0 를 inequality constraints 라고 한다.
JIN HO LEE Chapter 4 Numerical Computation 2018-9-17 7 / 18
8. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4.4 Constrained Optimization
S 에 대한 generalized Lagrangian 은 아래와 같이 정의된다:
L(x, λ, α) = f(x) + Σiλig(i)
(x) + Σjαjh(j)
(x)
where λi and αj ≥ 0 are KKT multipliers.
unconstrained optimization of generalized Lagrangian 을 이용하여
constraint optimization 문제를 푸는 방법은 다음과 같다. 적어도 하나의
feasible point x 가 있고, 그 때의 f(x) 가 ∞ 가 아니라면
min
x
max
λ
max
α,α≥0
L(x, λ, α) = min
x∈S
f(x)
가 된다. 따라서
max
λ
max
α,α≥0
L(x, λ, α) = f(x)
를 얻을 수 있고 constraint 가 violated 되면
max
λ
max
α,α≥0
L(x, λ, α) = ∞
가 된다.
JIN HO LEE Chapter 4 Numerical Computation 2018-9-17 8 / 18
9. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4.4 Constrained Optimization
반대로 constrain maximization 문제를 풀기 위해서 위에서 얘기한
constraint minimization 문제에 −f(x) 를 적용하여 전개할 수 있다:
min
x
max
λ
max
α,α≥0
−f(x) + Σiλig(i)
(x) + Σjαjh(j)
(x).
위의 식에 -1 을 곱하면 minx 를 maxx 로 바꿀 수 있고, equality constraint
g(i) = 0 의 coefficients λi 의 부호를 반대로 하면 되므로 아래와 같이 쓸 수
있다
max
x
min
λ
max
α,α≥0
f(x) + Σiλig(i)
(x) − Σjαjh(j)
(x).
JIN HO LEE Chapter 4 Numerical Computation 2018-9-17 9 / 18
10. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4.4 Constrained Optimization
Duality
reference : Karush-Kuhn-Tucker conditions, Geoff Gordon, Ryan
Tibshirani, Optimization 10-725
집합 S 에서 함수 f(x) 의 최솟값을 찾는 문제를 생각해 보자
S = {x ∈ Rn
|∀i, g(i)
(x) = 0 and ∀j, h(j)
(x) ≤ 0}.
이 때, Lagrangian 은 아래와 같이 정의된다:
L(x, λ, α) = f(x) + Σm
i=1λigi(x) + Σr
j=1αjhj(x)
그리고 Lagrage dual function 은 아래와 같이 정의된다:
˜f(λ, α) = min
x∈Rn
L(x, λ, α).
이 때, f(x) −˜f(λ, α) 를 duality gap between x, λ and α 라고 한다.
JIN HO LEE Chapter 4 Numerical Computation 2018-9-17 10 / 18
11. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4.4 Constrained Optimization
f 의 constraint problem 은 ˜f 를 이용하여 아래와 같이 정의된다:
max
λ∈Rm,α∈Rr
˜f(λ, α) subject to α ≥ 0.
Properties
1. Dual problem is always convex, i.e., ˜f is always concave (even if primal
problem is not convex).
2. The primal and dual optimal values, f∗ and ˜f∗, always satisfy weak
duality: f∗ ≥ ˜f∗.
3. Slater’s condition: for convex primal, if there is an x such that
h1(x) < 0, · · · , hm(x) < 0 and g1(x) = · · · = gr(x) = 0
then strong duality holds: f = ˜f.
JIN HO LEE Chapter 4 Numerical Computation 2018-9-17 11 / 18
13. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4.4 Constrained Optimization
Sufficiency of KKT Conditions in the Convex Case
Theorem
Let x∗ be a feasible solution of minx∈S f(x) where f, g1, · · · , gm, h1, · · · , hp
are continuously differentiable convex functions over Rn and g1, · · · , gp are
affine functions. Suppose that there exist multipliers α1, · · · , αm ≥ 0,
λ1, · · · , λp ∈ R such that ∇f(x∗) + Σm
i=1λi∇gi(x∗) + Σr
j=1αj∇hj(x∗) = 0
and λigi(x∗) = 0 for i = 1, · · · , m. Then x∗ is the optimal solution of
minx∈S f(x).
Proof.
x ∈ S 에 대해 함수 s 를 다음과 같이 정의하자:
s(x) = f(x) + Σm
i=1λigi(x) + Σr
j=1αjhj(x).
convex 함수의 sum 은 convex 이므로 s(x) 는 convex 이다. 가정에 의해
∇s(x∗) = 0 이므로 x∗ = argminx s(x) 이다.
JIN HO LEE Chapter 4 Numerical Computation 2018-9-17 13 / 18
14. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4.4 Constrained Optimization
Proof.
또한 가정에 의해 모든 i, j 에 대해 λigi(x∗) = 0 이고 hj(x∗) = 0 이다. 따라서
f(x∗
) = f(x∗
) + Σm
i=1λigi(x∗
) + Σr
j=1αjhJ(x∗
) = s(x∗
).
x∗ = argminx s(x) 이므로 임의의 x ∈ S 에 대해 s(x∗) ≤ s(x) 이다. S 의
정의에 의해 gi(x) = 0, hi(x) ≤ 0 이고, 가정에 의해 αi ≥ 0 이므로
αihi(x) ≤ 0, λjgj(x) = 0 이다. 정리를 하면 다음을 얻을 수 있다:
f(x∗
) = f(x∗
) + Σm
i=1λigi(x∗
) + Σr
j=1αjhJ(x∗
)
= s(x∗
)
≤ s(x)
= f(x) + Σm
i=1λigi(x) + Σr
j=1αjhj(x)
≤ f(x)
JIN HO LEE Chapter 4 Numerical Computation 2018-9-17 14 / 18
15. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4.4 Constrained Optimization
Necessity
x 가 primal solution, λ와 α가 dual solution 이고 duality gap(strong duality
holds, e.g., under Slater’s condition) 이라고 하면 다음을 얻을 수 있다:
f(x∗
) = ˜f(λ∗
, α∗
)
= min
x∈Rn
f(x) + Σm
i=1λ∗
i gi(x) + Σr
j=1α∗
j hj(x)
≤ f(x∗
) + Σm
i=1λ∗
i hi(x) + Σr
j=1α∗
j gj(x)
≤ f(x∗
)
따라서, f(x∗) ≤ f(x∗) 에서 f(x∗) = f(x∗) 를 얻을 수 있으므로 모든 부등식은
등식이 된다.
KKT condition 을 만족하는 x∗, λ∗, α∗ 에 대해 아래의 식을 만족한다.
˜f(λ∗
, α∗
) = f(x∗
) + Σm
i=1λ∗
i gi(x∗
) + Σr
j=1α∗
j hj(x∗
)
= f(x∗
)
JIN HO LEE Chapter 4 Numerical Computation 2018-9-17 15 / 18
16. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4.4 Constrained Optimization
˜f 가 S 에서 최소값을 가지므로 x = x∗ 에서 함수 L(x, λ∗, α∗) 는 미분하면 0
이 된다. 즉, KKT condition 중 stationarity condition 을 만족한다.
이 전 슬라이드의 부등식이 모두 등식이므로 Σm
i=1λ∗
i gi(x) = 0 이어야 한다.
우리의 minimization problem 의 가정에서 모든 i에 대해 hi(x) ≤ 0 이고,
α ≥ 0 이므로 더해서 0 이려면 각각이 모두 0 이어야 한다. 따라서 KKT
condition 의 complementary slackness 를 만족한다.
JIN HO LEE Chapter 4 Numerical Computation 2018-9-17 16 / 18
17. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4.5 Example: Linear Least Squares
4.5 Example: Linear Least Squares
f(x) = 1
2||Ax − b||2
2 를 최소화하는 x 를 찾아보자. f 의 gradient 는 아래와
같다:
∇Xf(x) = AT
(Ax − b) = AT
Ax − AT
b.
Algorithm (4.1)
An algorithm to minimize f(x) = 1
2||Ax − b||2
2 with respect to x using
gradient descent.
—————————————————————————————
Set the step size (ε) and tolerance (δ) to small, positive numbers.
while ||ATAx − ATb||2 > δ do
x ← x − ε(ATAx − ATb)
end while
JIN HO LEE Chapter 4 Numerical Computation 2018-9-17 17 / 18
18. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4.5 Example: Linear Least Squares
xTx ≤ 1 인 영역에서 f(x) 의 최소화 문제를 생각해 보자. Lagrangian 은
아래와 같다:
L(x, λ) = f(x) + λ(xT
x − 1).
이제 minx maxλ,λ≥0 L(x, λ) 를 풀어보자. KKT condition 을 이용하여
다음을 얻을 수 있다:
∂
∂x
L(x, λ) = AT
Ax − AT
b + 2λx = 0.
위의 식을 정리하면 다음을 얻을 수 있다.
x = (AT
A + 2λI)−1
AT
b.
L 을 λ 로 미분하면 아래를 얻을 수 있다:
∂
∂λ
L(x, λ) = xT
x − 1.
따라서 ||x|| > 1 이면 derivative 가 양수이므로 L 은 증가한다.
JIN HO LEE Chapter 4 Numerical Computation 2018-9-17 18 / 18