Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable...

21
Numerical Analysis 2015 Fall Optimization

Transcript of Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable...

Page 1: Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable function is defined and differentiable in a neighborhood of a point, ... Newton-Raphson

Numerical Analysis

2015 Fall

Optimization

Page 2: Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable function is defined and differentiable in a neighborhood of a point, ... Newton-Raphson

Optimization • Optimization is the process of creating

something that is as effective as possible.

• From a mathematical perspective, optimization deals with finding the maxima and minima of a function that depends on one or more variables.

Page 3: Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable function is defined and differentiable in a neighborhood of a point, ... Newton-Raphson

Optimization • Numerically, guessing and searching a point

on the function (similar to root finding methods)

Root finding in f(x)’

Page 4: Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable function is defined and differentiable in a neighborhood of a point, ... Newton-Raphson

Multidimensional Optimization • One-dimensional problems involve functions that

depend on a single dependent variable -for example, f(x).

• Multidimensional problems involve functions that depend on two or more dependent variables - for example, f(x,y)

Page 5: Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable function is defined and differentiable in a neighborhood of a point, ... Newton-Raphson

Multidimensional Optimization • Face detection

Face Model

5 variables

Page 6: Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable function is defined and differentiable in a neighborhood of a point, ... Newton-Raphson

Global vs. Local • A global optimum represents the very best

solution while a local optimum is better than its immediate neighbors.

• Cases that include local optima are called multimodal.

• Generally desire to find the global optimum.

Page 7: Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable function is defined and differentiable in a neighborhood of a point, ... Newton-Raphson

Golden Ratio • Two quantities are in the golden ratio if their

ratio is the same as the ratio of their sum to the larger of the two quantities.

Page 8: Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable function is defined and differentiable in a neighborhood of a point, ... Newton-Raphson

Golden Ratio

Page 9: Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable function is defined and differentiable in a neighborhood of a point, ... Newton-Raphson

Bisection

• The bisection method is a variation of the incremental search method in which the interval is always divided in half.

• If a function changes sign over an interval, the function value at the midpoint is evaluated.

• The location of the root is then determined as lying within the subinterval where the sign change occurs.

• The absolute error is reduced by a factor of 2 for each iteration.

Page 10: Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable function is defined and differentiable in a neighborhood of a point, ... Newton-Raphson

Golden-Section Search • Search algorithm for finding a minimum on an

interval [xl xu] with a single minimum (unimodal interval)

• Uses the golden ratio =1.6180… to determine location of two interior points x1 and x2

• By using the golden ratio, one of the interior points can be re-used in the next iteration.

Page 11: Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable function is defined and differentiable in a neighborhood of a point, ... Newton-Raphson

Golden-Section Search (cont)

• If f(x1)<f(x2), x2 becomes the new lower limit and x1 becomes the new x2 (as in figure).

• If f(x2)<f(x1), x1 becomes the new upper limit and x2 becomes the new x1.

• In either case, only one new interior point is needed and the function is only evaluated one more time.

d ( 1)(xu x l )

x1 x l d

x2 xu d

Golden ratio…

Page 12: Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable function is defined and differentiable in a neighborhood of a point, ... Newton-Raphson

Example

Page 13: Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable function is defined and differentiable in a neighborhood of a point, ... Newton-Raphson

Error

Max error

Page 14: Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable function is defined and differentiable in a neighborhood of a point, ... Newton-Raphson

Code for Golden-Section Homework

Page 15: Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable function is defined and differentiable in a neighborhood of a point, ... Newton-Raphson

Parabolic Interpolation • It uses parabolic interpolation of three points to

estimate optimum location.

• The location of the maximum/minimum of a parabola defined as the interpolation of three points (x1, x2, and x3) is:

• The new point x4 and the two surrounding it (either x1 andx2 or x2 and x3) are used for the next iteration of the algorithm.

x4 x2 1

2

x2 x1 2f x2 f x3 x2 x3

2f x2 f x1

x2 x1 f x2 f x3 x2 x3 f x2 f x1

Page 16: Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable function is defined and differentiable in a neighborhood of a point, ... Newton-Raphson

fminbnd Function

• MATLAB has a built-in function, fminbnd, which combines the golden-section search and the parabolic interpolation. – [xmin, fval] = fminbnd(function, x1, x2)

• Options may be passed through a fourth argument using optimset, similar to fzero.

Homework

Page 17: Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable function is defined and differentiable in a neighborhood of a point, ... Newton-Raphson

Multidimensional Visualization • Functions of two-dimensions may be

visualized using contour or surface/mesh plots.

Page 18: Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable function is defined and differentiable in a neighborhood of a point, ... Newton-Raphson

Gradient Descent • Gradient descent is based on the observation that if

the multivariable function is defined and differentiable in a neighborhood of a point, then decreases fastest if one goes in the direction of the negative gradient.

• Gradient descent is a first-order optimization algorithm.

Page 19: Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable function is defined and differentiable in a neighborhood of a point, ... Newton-Raphson

Newton-Raphson • Based on forming the tangent line to the first

derivative of g(x) curve at some guess x, then following the tangent line to where it crosses the x-axis.

)('

)(

)(''

)('1

i

ii

i

iii

xf

xfx

xg

xgxx

Page 20: Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable function is defined and differentiable in a neighborhood of a point, ... Newton-Raphson

fminsearch Function • MATLAB has a built-in function, fminsearch,

that can be used to determine the minimum of a multidimensional function. – [xmin, fval] = fminsearch(function, x0)

– xmin in this case will be a row vector containing the location of the minimum, while x0 is an initial guess. Note that x0 must contain as many entries as the function expects of it.

• The function must be written in terms of a single variable, where different dimensions are represented by different indices of that variable.

Homework

Page 21: Numerical Analysis - khu.ac.krcvlab.khu.ac.kr/NALecture8.pdf · 2015-10-05 · the multivariable function is defined and differentiable in a neighborhood of a point, ... Newton-Raphson

fminsearch Function

• To minimize f(x,y)=2+x-y+2x2+2xy+y2 rewrite as f(x1, x2)=2+x1-x2+2(x1)

2+2x1x2+(x2)2

• f=@(x) 2+x(1)-x(2)+2*x(1)^2+2*x(1)*x(2)+x(2)^2 [x, fval] = fminsearch(f, [-0.5, 0.5])

• Note that x0 has two entries - f is expecting it to contain two values.

• MATLAB reports the minimum value is 0.7500 at a location of [-1.000 1.5000]

Homework