Unit 4 (Optimization)
Unit 4 (Optimization)
Unit-4
(Optimization)
Dr. Muhammad Majid Gulzar (CIE-KFUPM)
Contents (Unit-4):
1) One-dimensional Unconstrained Optimization
Golden-Section Search (Sec 13.1)
50
If so, the max/min value of 𝑓𝑓(𝑥𝑥) is 𝑓𝑓 𝑚𝑚 . 𝒇𝒇(𝒙𝒙)= 𝒇𝒇(𝒎𝒎)
40
Having only one peak/dip and there is no other
local maxima/minima.
30
20
10
0
0 5 10 15 20 25 30
Rather than using only 2 function values (which are sufficient to detect a sign change
and hence a zero), we would need 3 function values to detect whether a
maximum/minimum occurred.
The initial step of the golden-section search algorithm involves choosing two interior
points according to the golden ratio.
𝑙𝑙1 𝑙𝑙2
=
𝑙𝑙1 + 𝑙𝑙2 𝑙𝑙1
𝑙𝑙2 𝑙𝑙1
1+ =
𝑙𝑙1 𝑙𝑙2
𝑅𝑅2 + 𝑅𝑅 − 1 =0
−𝑏𝑏 ± 𝑏𝑏 2 − 4𝑎𝑎𝑎𝑎
𝑥𝑥 =
2𝑎𝑎
−1 + 1 − 4(−1) 5−1
𝑥𝑥 = = = 𝟎𝟎. 𝟔𝟔𝟔𝟔𝟔𝟔𝟔𝟔𝟔𝟔
2 2
Golden Ratio
𝑥𝑥1 = 𝑥𝑥𝑙𝑙 + 𝑑𝑑
𝑥𝑥2 = 𝑥𝑥𝑢𝑢 − 𝑑𝑑
2.4722
𝑓𝑓 𝑥𝑥1 = 𝑓𝑓 2.472 = 2 sin(2.472) − = 𝟎𝟎. 𝟔𝟔𝟔𝟔
10
1.5282
𝑓𝑓 𝑥𝑥2 = 𝑓𝑓 1.528 = 2 sin(1.528) − = 𝟏𝟏. 𝟕𝟕𝟕𝟕𝟕𝟕
10
1.5282
𝑓𝑓 𝑥𝑥1 = 𝑓𝑓 1.528 = 2 sin(1.528) − = 𝟏𝟏. 𝟕𝟕𝟕𝟕𝟕𝟕
10
0.9442
𝑓𝑓 𝑥𝑥2 = 𝑓𝑓 0.944 = 2 sin(0.944) − = 𝟏𝟏. 𝟓𝟓𝟓𝟓𝟓𝟓
10
Dr. Muhammad Majid Gulzar (CIE-KFUPM)
Golden-Section Search (Example):
𝑓𝑓 𝑥𝑥1 > 𝑓𝑓 𝑥𝑥2 −−→ 𝑥𝑥2 = 𝑥𝑥𝑙𝑙 0 −− −0.944 −− −1.528 −− −2.472
1.8882
𝑓𝑓 𝑥𝑥1 = 𝑓𝑓 1.888 = 2 sin(1.888) − = 𝟏𝟏. 𝟓𝟓𝟓𝟓𝟓𝟓
10
1.5282
𝑓𝑓 𝑥𝑥2 = 𝑓𝑓 1.528 = 2 sin(1.528) − = 𝟏𝟏. 𝟕𝟕𝟕𝟕𝟕𝟕
10
Dr. Muhammad Majid Gulzar (CIE-KFUPM)
Golden-Section Search (Example):
′
𝑓𝑓(𝑥𝑥𝑖𝑖 )
𝑥𝑥𝑖𝑖+1 = 𝑥𝑥𝑖𝑖 − ′′
𝑓𝑓(𝑥𝑥 𝑖𝑖 )
𝑥𝑥 1
′
𝑓𝑓(𝑥𝑥) = 2 cos(𝑥𝑥) − , 𝑓𝑓 ′′𝑥𝑥 = −2 sin(𝑥𝑥) −
5 5
′ 𝑥𝑥𝑖𝑖
𝑓𝑓(𝑥𝑥 2 cos(𝑥𝑥𝑖𝑖 ) −
𝑥𝑥𝑖𝑖+1 = 𝑥𝑥𝑖𝑖 − 𝑖𝑖 )
= 𝑥𝑥𝑖𝑖 − 5
′′ 1
𝑓𝑓(𝑥𝑥𝑖𝑖 ) −2 sin(𝑥𝑥𝑖𝑖 ) −
5
0.9952
𝑓𝑓 𝑥𝑥1 = 𝑓𝑓(0.995) = 2 sin 0.995 − = 𝟏𝟏. 𝟓𝟓𝟓𝟓𝟓𝟓
10
′ 0.995
𝑓𝑓(𝑥𝑥 2 cos 0.995 −
𝐹𝐹𝐹𝐹𝐹𝐹 𝑖𝑖 = 1, 𝑥𝑥2 = 𝑥𝑥1 − 1)
= 0.995 − 5 = 𝟏𝟏. 𝟒𝟒𝟒𝟒𝟒𝟒
′′ 1
𝑓𝑓(𝑥𝑥 1) −2 sin 0.995 −
5
1.4692
𝑓𝑓 𝑥𝑥2 = 𝑓𝑓(1.469) = 2 sin 1.469 − = 𝟏𝟏. 𝟕𝟕𝟕𝟕𝟕𝟕
10
Dr. Muhammad Majid Gulzar (CIE-KFUPM)
Newton’s Method (Example):
𝒇𝒇(𝒙𝒙)
50
Most of the real life optimization problems are
40
multimodal.
30
20
10
0
0 5 10 15 20 25 30
50
There can be multiple local optima solutions.
40
Smallest function value in the feasible region.
30
If the function is convex, only global optima
20
exists (There will be no local optima).
For multimodal functions, most algorithms fail
10
to determine the global optima.
0
0 5 10 15 20 25 30
Its major shortcoming is that as the number of independent variables grows, the
implementation effort required can become onerous.
𝑥𝑥 = −2 + 2 + 2 𝑟𝑟 𝑦𝑦 = 1 + 3 − 1 𝑟𝑟
𝑥𝑥 = −2 + 4𝑟𝑟 𝑦𝑦 = 1 + 2𝑟𝑟
Dr. Muhammad Majid Gulzar (CIE-KFUPM)
Random Search (Example):
maxf = −1E9
For j = 1 To n
x = −2 + 4 * Rnd
y = 1 + 2 * Rnd
fn = y − x − 2 * x ^ 2 − 2 * x * y − y ^ 2
If fn > maxf Then
maxf = fn
maxx = x
maxy = y
End If
Next j
The first derivative may tell us when we have reached an optimal value since this is the
point that the derivative goes to zero.
Further, the sign of the second derivative can tell us whether we have reached a
minimum (positive second derivative) or a maximum (negative second derivative).
𝑓𝑓 2,2 = 2 22 = 8
𝜕𝜕𝑓𝑓
= 𝑦𝑦 2 = 22 = 4
𝜕𝜕𝑥𝑥
𝜕𝜕𝜕𝜕
= 2𝑥𝑥𝑥𝑥 = 2(2)(2) = 8
𝜕𝜕𝑦𝑦
−1
8
𝜃𝜃 = tan = 𝟏𝟏. 𝟏𝟏𝟏𝟏𝟏𝟏 𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓 (= 𝟔𝟔𝟔𝟔. 𝟒𝟒𝒐𝒐 )
4
2
𝜕𝜕 2 𝑓𝑓 𝜕𝜕 2 𝑓𝑓 𝜕𝜕 2 𝑓𝑓
𝐻𝐻 = 2 2 −
𝜕𝜕𝑥𝑥 𝜕𝜕𝑦𝑦 𝜕𝜕𝜕𝜕𝜕𝜕𝑦𝑦
𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬 𝒕𝒕𝒕𝒕 𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬𝑬 𝒕𝒕𝒕𝒕 𝑯𝑯 > 𝟎𝟎 & 𝝏𝝏𝟐𝟐 𝒇𝒇⁄𝝏𝝏𝝏𝝏𝟐𝟐 < 𝟎𝟎 𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴
𝑮𝑮𝑮𝑮𝑮𝑮 𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺
𝑱𝑱𝑱𝑱𝑱𝑱𝑱𝑱𝑱𝑱𝑱𝑱𝑱𝑱𝑱𝑱 𝑯𝑯𝑯𝑯𝑯𝑯𝑯𝑯𝑯𝑯𝑯𝑯𝑯𝑯 𝑯𝑯 > 𝟎𝟎 & 𝝏𝝏𝟐𝟐 𝒇𝒇⁄𝝏𝝏𝝏𝝏𝟐𝟐 > 𝟎𝟎 𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴
𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷
𝑱𝑱 = 𝟎𝟎 𝑯𝑯 = 𝟎𝟎 𝑯𝑯 < 𝟎𝟎 𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺𝑺 𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷
𝑑𝑑𝑑𝑑
Jacobian = 𝐽𝐽 = = 3𝑥𝑥 2 + 6𝑥𝑥 − 6
𝑑𝑑𝑑𝑑
3𝑥𝑥 2 + 6𝑥𝑥 − 6 = 0
𝑥𝑥 = 0.732, −2.732
𝑑𝑑𝑑𝑑
Jacobian = 𝐽𝐽 = = 3𝑥𝑥 2 + 6𝑥𝑥 − 6
𝑑𝑑𝑑𝑑
𝑑𝑑 2 𝑓𝑓
Hessian = 𝐻𝐻 = 𝑓𝑓 ′′ = = 6𝑥𝑥 + 6
𝑑𝑑𝑑𝑑 2
𝑥𝑥 𝑓𝑓 ′′ 𝑓𝑓 Extremum Maxima
Minima
0.732 10.392 −2.39 Minimum
𝜕𝜕𝑓𝑓 𝜕𝜕𝑓𝑓
= 2𝑦𝑦 + 2 − 2𝑥𝑥
𝜕𝜕𝑥𝑥 𝜕𝜕𝑥𝑥
Jacobian = 𝐽𝐽 = 𝜕𝜕𝑓𝑓 → 𝜕𝜕𝑓𝑓
= 2𝑥𝑥 − 4𝑦𝑦
𝜕𝜕𝑦𝑦 𝜕𝜕𝑦𝑦
2𝑦𝑦 + 2 − 2𝑥𝑥 = 0
𝐽𝐽 = 0 →
2𝑥𝑥 − 4𝑦𝑦 = 0
2𝑦𝑦 + 2 = 2𝑥𝑥
2𝑥𝑥 = 4𝑦𝑦
𝑦𝑦 = 1 𝑥𝑥 = 2
2
𝐻𝐻 = −2 −4 − 2 =4
𝒇𝒇 𝟐𝟐, 𝟏𝟏 = 𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴
Dr. Muhammad Majid Gulzar (CIE-KFUPM)
Maxima/Minima/Saddle Point:
Maximum or minimum is located at the stationary point.
1) Stationary point can be determined by equating the gradient (Jacobian of the function to zero)
Saddle Point
0 Indefinite
(Not possible to decide)
Dr. Muhammad Majid Gulzar (CIE-KFUPM)
Maxima/Minima/Saddle Point:
Maximum or minimum is located at the stationary point.
1) Stationary point can be determined by equating the gradient (Jacobian of the function to zero)
Positive Definite A matrix is positive definite if determinants of all upper-left sub-matrices are positive.
Negative Definite A matrix is negative definite if determinants 𝐷𝐷𝑖𝑖 < 0 for odd 𝑖𝑖 and 𝐷𝐷𝑖𝑖 > 0 for even 𝑖𝑖 .
Indefinite Determinate of the matrix is not zero and neither it is positive definite nor negative definite.
𝜕𝜕𝑓𝑓 𝜕𝜕𝑓𝑓
= 6𝑥𝑥1 − 2𝑥𝑥2 − 2𝑥𝑥3 − 6
𝜕𝜕𝑥𝑥1 𝜕𝜕𝑥𝑥1
6𝑥𝑥1 − 2𝑥𝑥2 − 2𝑥𝑥3 − 6
𝜕𝜕𝑓𝑓 𝜕𝜕𝑓𝑓
Jacobian = 𝐽𝐽 = → = −2𝑥𝑥1 + 4𝑥𝑥2 + 2𝑥𝑥3 − 4 → 𝐽𝐽 = −2𝑥𝑥1 + 4𝑥𝑥2 + 2𝑥𝑥3 − 4
𝜕𝜕𝑥𝑥2 𝜕𝜕𝑥𝑥2 −2𝑥𝑥1 + 2𝑥𝑥2 + 2𝑥𝑥3 − 2
𝜕𝜕𝑓𝑓 𝜕𝜕𝑓𝑓
= −2𝑥𝑥1 + 2𝑥𝑥2 + 2𝑥𝑥3 − 2
𝜕𝜕𝑥𝑥3 𝜕𝜕𝑥𝑥3
6 −2 −2 𝑥𝑥1 6
𝐽𝐽 = 0 → −2 4 2 𝑥𝑥2 = 4
−2 2 2 𝑥𝑥3 2
𝐴𝐴𝐴𝐴 = 𝑏𝑏
Dr. Muhammad Majid Gulzar (CIE-KFUPM)
Multi Variable Functions (Example):
𝐴𝐴𝐴𝐴 = 𝑏𝑏 → 𝑥𝑥 = 𝐴𝐴−1 𝑏𝑏
6 −2 −2
𝐴𝐴 = −2 4 2
−2 2 2
6 −2 −2 ⋮ 1 0 0
𝐴𝐴−1 = −2 4 2 ⋮ 0 1 0
−2 2 2 ⋮ 0 0 1
𝑅𝑅2
1 0 −1⁄5 ⋮ 1⁄5 1⁄10 0 𝑅𝑅1 +
𝐴𝐴−1 = 0 1 2⁄5 ⋮ 1⁄10 3⁄10 0 → 3
4𝑅𝑅2
0 0 4⁄5 ⋮ 1⁄5 −2⁄5 1 𝑅𝑅3 −
3
1𝑅𝑅3
1 0 0 ⋮ 1⁄4 0 1⁄4 𝑅𝑅1 +
𝐴𝐴−1 = 0 1 0 ⋮ 0 1⁄2 −1⁄2 → 5
2𝑅𝑅3
0 0 1 ⋮ 1⁄4 −1⁄2 5⁄4 𝑅𝑅2 −
5
Dr. Muhammad Majid Gulzar (CIE-KFUPM)
Multi Variable Functions (Example):
1⁄4 0 1⁄4
𝐴𝐴−1 = 0 1⁄2 −1⁄2
1⁄4 −1⁄2 5⁄4
𝐴𝐴𝐴𝐴 = 𝑏𝑏 → 𝑥𝑥 = 𝐴𝐴−1 𝑏𝑏
1⁄4 0 1⁄4 6 2
𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆 𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃 = 𝑥𝑥 = 0 1⁄2 −1⁄2 4 = 1
1⁄4 −1⁄2 5⁄4 2 2
𝜕𝜕𝑓𝑓 𝜕𝜕𝑓𝑓
= 6𝑥𝑥1 − 2𝑥𝑥2 − 2𝑥𝑥3 − 6
𝜕𝜕𝑥𝑥1 𝜕𝜕𝑥𝑥1
6𝑥𝑥1 − 2𝑥𝑥2 − 2𝑥𝑥3 − 6
𝜕𝜕𝑓𝑓 𝜕𝜕𝑓𝑓
Jacobian = 𝐽𝐽 = → = −2𝑥𝑥1 + 4𝑥𝑥2 + 2𝑥𝑥3 − 4 → 𝐽𝐽 = −2𝑥𝑥1 + 4𝑥𝑥2 + 2𝑥𝑥3 − 4
𝜕𝜕𝑥𝑥2 𝜕𝜕𝑥𝑥2 −2𝑥𝑥1 + 2𝑥𝑥2 + 2𝑥𝑥3 − 2
𝜕𝜕𝑓𝑓 𝜕𝜕𝑓𝑓
= −2𝑥𝑥1 + 2𝑥𝑥2 + 2𝑥𝑥3 − 2
𝜕𝜕𝑥𝑥3 𝜕𝜕𝑥𝑥3
𝜕𝜕 2 𝑓𝑓 𝜕𝜕 2 𝑓𝑓 𝜕𝜕 2 𝑓𝑓
𝜕𝜕𝑥𝑥1 2 𝜕𝜕𝜕𝜕1 𝑥𝑥2 𝜕𝜕𝜕𝜕1 𝑥𝑥3
𝜕𝜕 2 𝑓𝑓 𝜕𝜕 2 𝑓𝑓 𝜕𝜕 2 𝑓𝑓 6 −2 −2
Hessian = 𝐻𝐻 = = −2 4 2
𝜕𝜕𝜕𝜕2 𝑥𝑥1 𝜕𝜕𝑥𝑥2 2 𝜕𝜕𝜕𝜕2 𝑥𝑥3
−2 2 2
𝜕𝜕 2 𝑓𝑓 𝜕𝜕 2 𝑓𝑓 2
𝜕𝜕 𝑓𝑓
𝜕𝜕𝜕𝜕3 𝑥𝑥1 𝜕𝜕𝜕𝜕3 𝑥𝑥2 𝜕𝜕𝑥𝑥3 2
Dr. Muhammad Majid Gulzar (CIE-KFUPM)
Multi Variable Functions (Example):
6 −2 −2
𝐻𝐻 = −2 4 2
−2 2 2
6 −2 −2
6 −2
𝐻𝐻1 = 6 > 0 𝐻𝐻2 = = 20 > 0 𝐻𝐻3 = −2 4 2 = 16 > 0
−2 4
−2 2 2
As all 3 principle determinants are positive, so 𝐻𝐻 is positive definite matrix and the
stationary points (𝑥𝑥 = 2,1,2) corresponds to minima.
𝜕𝜕𝑓𝑓 𝜕𝜕𝑓𝑓
= 4𝑥𝑥13 + 2𝑥𝑥1 − 4𝑥𝑥1 𝑥𝑥2 − 2𝑥𝑥2 + 4.5
𝜕𝜕𝑥𝑥1 𝜕𝜕𝑥𝑥1
Jacobian = 𝐽𝐽 = →
𝜕𝜕𝑓𝑓 𝜕𝜕𝑓𝑓
= −2𝑥𝑥12 + 4𝑥𝑥2 − 2𝑥𝑥1 − 4
𝜕𝜕𝑥𝑥2 𝜕𝜕𝑥𝑥2
𝑆𝑆1 = −1.05,1.03
𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆 𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃𝑃 = (𝑥𝑥1 , 𝑥𝑥2 ) = 𝑆𝑆2 = 0.61,1.49
𝑆𝑆3 = 1.94,3.85