Multidimensional Minimization

Similar documents
Today. Golden section, discussion of error Newton s method. Newton s method, steepest descent, conjugate gradient

Simplex of Nelder & Mead Algorithm

Modern Methods of Data Analysis - WS 07/08

Lecture 3: Linear Classification

An Evolutionary Algorithm for Minimizing Multimodal Functions

PARALLELIZATION OF THE NELDER-MEAD SIMPLEX ALGORITHM

Geometry: Angle Relationships

Methods of Optimization for Numerical Algorithms

Basics of Computational Geometry

Introduction. Optimization

KINEMATICS FOR ANIMATION. Rémi Ronfard, Animation, M2R MOSIG

A Multiple-Line Fitting Algorithm Without Initialization Yan Guo

Algoritmi di Ottimizzazione: Parte A Aspetti generali e algoritmi classici

2. Linear Regression and Gradient Descent

Numerical Optimization

Feature Detectors and Descriptors: Corners, Lines, etc.

1.2 Adding Integers. Contents: Numbers on the Number Lines Adding Signed Numbers on the Number Line

A Function of Two Variables A function of two variables is a function that is, to each input is associated exactly one output.

An introduction to plotting data

10.4 Downhill Simplex Method in Multidimensions

Section 18-1: Graphical Representation of Linear Equations and Functions

Introduction to Quadratic Functions

of Iterative Closest Point ICP algorithm to

Administrivia. Next Monday is Thanksgiving holiday. Tuesday and Wednesday the lab will be open for make-up labs. Lecture as usual on Thursday.

Chapter 3 Path Optimization

Chapter 14 Global Search Algorithms

Nelder-Mead Enhanced Extreme Learning Machine

EL2310 Scientific Programming

Experimental Design and Graphical Analysis of Data

UNIT 8: SOLVING AND GRAPHING QUADRATICS. 8-1 Factoring to Solve Quadratic Equations. Solve each equation:

Grade 6 Math Circles November 6 & Relations, Functions, and Morphisms

Functions and Graphs. The METRIC Project, Imperial College. Imperial College of Science Technology and Medicine, 1996.

Optimizing the TracePro Optimization Process

Unit 1, Lesson 1: Moving in the Plane

Markov chain Monte Carlo sampling

3.9 LINEAR APPROXIMATION AND THE DERIVATIVE

Making Science Graphs and Interpreting Data

Revision Topic 11: Straight Line Graphs


Visualizing Change with Colour Gradient Approximations

Practice Test (page 391) 1. For each line, count squares on the grid to determine the rise and the run. Use slope = rise

Multivariate Numerical Optimization

ES-2 Lecture: Fitting models to data

Constrained Optimization with Calculus. Background Three Big Problems Setup and Vocabulary

1. Assumptions. 1. Introduction. 2. Terminology

Using Excel for Graphical Analysis of Data

Practice Reading for Loops

Lecture 8. Divided Differences,Least-Squares Approximations. Ceng375 Numerical Computations at December 9, 2010

Getting started with simulating data in R: some helpful functions and how to use them Ariel Muldoon August 28, 2018

Lecture 4. Convexity Robust cost functions Optimizing non-convex functions. 3B1B Optimization Michaelmas 2017 A. Zisserman

CPSC 340: Machine Learning and Data Mining. Robust Regression Fall 2015

PV211: Introduction to Information Retrieval

Finite Element Analysis Prof. Dr. B. N. Rao Department of Civil Engineering Indian Institute of Technology, Madras. Lecture - 36

Programming Exercise 1: Linear Regression

Handout 2 - Root Finding using MATLAB

Chapter 3 - Displaying and Summarizing Quantitative Data

Using Excel for Graphical Analysis of Data

n! = 1 * 2 * 3 * 4 * * (n-1) * n

Graphing Techniques. Domain (, ) Range (, ) Squaring Function f(x) = x 2 Domain (, ) Range [, ) f( x) = x 2

Mathematics of Data. INFO-4604, Applied Machine Learning University of Colorado Boulder. September 5, 2017 Prof. Michael Paul

Integrated Math I. IM1.1.3 Understand and use the distributive, associative, and commutative properties.

An evolutionary annealing-simplex algorithm for global optimisation of water resource systems

Graphical Analysis of Data using Microsoft Excel [2016 Version]

Solving for dynamic user equilibrium

ADVANCED IMAGE PROCESSING METHODS FOR ULTRASONIC NDE RESEARCH C. H. Chen, University of Massachusetts Dartmouth, N.

Scott Foresman Investigations in Number, Data, and Space Content Scope & Sequence Correlated to Academic Language Notebooks The Language of Math

Computer Vision. Image Segmentation. 10. Segmentation. Computer Engineering, Sejong University. Dongil Han

In this chapter, we will discuss several general algorithms that find a solution of the following canonical equation. f(x) = 0 (1.

MATH3016: OPTIMIZATION

Programs. Introduction

Quadratic Functions In Standard Form In Factored Form In Vertex Form Transforming Graphs. Math Background

MAT 003 Brian Killough s Instructor Notes Saint Leo University

Engineering Effects of Boundary Conditions (Fixtures and Temperatures) J.E. Akin, Rice University, Mechanical Engineering

Introduction to Information Retrieval

1.1. Parent Functions and Transformations Essential Question What are the characteristics of some of the basic parent functions?

CS103 Handout 29 Winter 2018 February 9, 2018 Inductive Proofwriting Checklist

Introduction to unconstrained optimization - derivative-free methods

COMP 161 Lecture Notes 16 Analyzing Search and Sort

This research aims to present a new way of visualizing multi-dimensional data using generalized scatterplots by sensitivity coefficients to highlight

Generic descent algorithm Generalization to multiple dimensions Problems of descent methods, possible improvements Fixes Local minima

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

11.4. Imagine that you are, right now, facing a clock and reading the time on that. Spin to Win. Volume of Cones and Pyramids

User s Guide to Climb High. (A Numerical Optimization Routine) Introduction

Image and Video Quality Assessment Using Neural Network and SVM

Section 7 Mixture Design Tutorials

College Algebra. Gregg Waterman Oregon Institute of Technology

AWM 11 UNIT 4 TRIGONOMETRY OF RIGHT TRIANGLES

MAT 343 Laboratory 4 Plotting and computer animation in MATLAB

Revision of the SolidWorks Variable Pressure Simulation Tutorial J.E. Akin, Rice University, Mechanical Engineering. Introduction

Lecture 5 - Control Structure Applications

To Measure a Constant Velocity. Enter.

(Creating Arrays & Matrices) Applied Linear Algebra in Geoscience Using MATLAB

Geometry R. Unit 12 Coordinate Geometry. Day Classwork Day Homework Wednesday 3/7 Thursday 3/8 Friday 3/9

CPSC 340: Machine Learning and Data Mining. More Linear Classifiers Fall 2017

APPM 2460: Week Three For, While and If s

Computer Animation INF2050

8.NS.1 8.NS.2. 8.EE.7.a 8.EE.4 8.EE.5 8.EE.6

I. Function Characteristics

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

Excel Primer CH141 Fall, 2017

Transcription:

C. C. Kankelborg, 1999-11-18 (rev. 2009-Mar-24) I. INTRODUCTION Multidimensional Minimization This lecture is devoted to the task of minimization in N dimensions, which may be stated as follows: For a scalar function f(x), where x = [x1, x2,..., xn], find x that minimizes f(x). Many challenging problems in physics, engineering, operations research, economics, etc. require carefully choosing the values of a set of parameters (x) to achieve some optimal result. If what is meant by optimal can be quantified reduced to a mere number via some function f(x) then this N- dimensional optimization problem may be reduced to minimization as defined above. Applications of this technique range from experimental tests of scientific theories to practical design problems to questions of international trade policy. Minimization is difficult. In 2 or more dimensions, it is not possible to bracket a minimum. Convergence cannot be guaranteed. It is impossible to guarantee that a minimum, once found, is the global minimum of the function. The design of minimization algorithms is part deduction and part intuition. The programs used for minimizing t to be finicky about which problems they will solve. In this handout I ll describe the downhill simplex method ( amoeba ) which is the basis of MATLAB s fminsearch. My own amoeba implementation is also included with an example. II. THE AMOEBA METHOD Nelder and Meade in 1965 invented one of the simplest and most robust minimization methods. It is called the downhill simplex, or simply the amoeba. Not all problems are susceptible to the amoeba, but surprisingly many are. A simplex, or amoeba, is like a little animal with N+1 feet crawling around in a hot world, looking for a cool, comfortable spot. The feet move around in response to the local temperature, f(x). Whether N is large or small, the amoeba utilizes the value of f at only three of its feet at any one time: the hottest (P), the second hottest (Q), and

the coolest (R). The basic moves used by the amoeba are summarized in figure 1, which is simplified by assuming a two-dimensional space (N = 2, so the amoeba has 3 feet). The main loop of the program always begins by reflecting point P through the opposite face of the amoeba, as in [a]. The remaining moves are chosen (or not) deping on how f(p) has changed as compared to f(q) and f(r). Figure 2 is a flowchart summarizing the tactics that lead from one move to the next. The choice of which points are called P, Q, and R is revised after each cycle through the main loop. [Note: the flowchart includes a convergence criterion, a decision box that points to END when satisfied. The idea here is that if the highest and lowest points are close enough to one another, then the amoeba has located the minimum to reasonable precision. I don t use a convergence criterion for the examples. It is often sufficient to just run through the main loop a fixed number of times and examine the results visually.] Fig. 1. The basic moves of the amoeba.

For a two-dimensional problem, the amoeba s feet consist of three points forming a triangle. The three feet are then just P, Q, and R. Figure 3 shows two example sequences of moves in two dimensions. These are best followed while looking at the flowchart. Following is a short description of each sequence moves, identified by the letters [a], [b], [c], or [d] of Figure 1. Sequence A. A straightforward example. A1:[a],[b]. The [b] move is risky, but it s a good way of capitalizing on a reflection that turned out very well. A2: [a]. A3:[a],[c]. Note how the last move pulls back from an excursion that almost left the page. The amoeba doesn t have eyes, only feet to feel with, and so it can be fooled for a little while. But overall, it ts to make progress toward a minimum. Sequence B. This is a situation contrived to fool the amoeba, but only for a little while. B1: [a],[c]. This first panel is like A3, a move that turned out to be a bad idea. But after pulling point P closer to the center, the value of f gets even higher! You can see how I had to draw distorted contour lines to make this possible. Real minimization problems are full of such cruel tricks. B2:[d]. In the d-type move, the amoeba moves N of its feet at once (instead of just one, as in a, b, c-type moves); the amoeba shrinks around the coolest foot as a last resort, because every other stratagem has gone bad.

Fig. 2. Amoeba flowchart.

Fig. 3. Sketched examples showing the behavior of the amoeba. III. SAMPLE PROGRAMS I will put the.m files on the web in case you want to play with them: http://solar.physics.montana.edu/kankel/phys567/examples/octave/mi nimization/amoeba 3.1 Amoeba code Here is amoeba.m. The idea is simple: you give it an initial guess for x, and the name of funk, a program that returns f(x). You also tell the amoeba how many iterations to go through the main loop. The result is what amoeba

thinks is the value of x that minimizes funk. Note that the source code is divided into four modules: the main program (amoeba), a sorter to choose P, Q, and R (pickpqr), an implementation of moves [a, b, c] (reflect_foot), and an implementation of move [d] (ndcontract). function bestfit=amoeba(funk,xguess,iterations) % A simple implementation of the downhill simplex method of % Nelder & Meade (1963), a.k.a. "amoeba". The function funk % should be a scalar, real-valued function of a vector argument % of the same size as xguess. %Standard scale values for the reflect function reflect = 1; expand = -0.5; contract = 0.25; [M,N] = size(xguess); %N will be the number of dimensions. if M~=1 error('xguess is not a row vector!') %Define the N+1 'feet' of the amoeba basis = eye(n); feet = [xguess;ones(n,1)*xguess+basis]; %Evaluate funk at each of the 'feet' f=zeros(1,n+1); for i=1:n+1 f(i)=feval(funk,feet(i,:)); for persistence=1:iterations %The main loop [P,Q,R] = pickpqr(f); %Identify highest, second highest, lowest feet [feet,f]=reflect_foot(funk,feet,f,p,reflect); %Reflect if f(p) < f(r) [feet,f]=reflect_foot(funk,feet,f,p,expand); %Expand elseif f(p) > f(q) w = f(p); %Keep track of the current worst value of f [feet,f]=reflect_foot(funk,feet,f,p,contract); %1-dim Contract if f(p) < w [feet,f]=ndcontract(funk,feet,f,r); %N-dim contract

[P,Q,R] = pickpqr(f); %Identify highest, second highest, lowest feet bestfit = feet(r,:); %Use lowest foot as best fit. % amoeba %-------------------------------------------------------------------- function [P,Q,R]=pickPQR(f) % Identify indices of highest (P), second highest (Q), % and lowest (R) feet. [foo,nfeet]=size(f); if foo ~=1 error('f has wrong dimensions!') P=1; Q=2; R=1; % Initial guess, certainly wrong if f(q) > f(p) % Correct the P/Q order for first 2 feet P=2; Q=1; for i=1:nfeet % Loop thru feet, finding P,Q,R if f(i) > f(p) Q=P; P=i; elseif (f(i) > f(q)) & (i ~= P) Q=i; if f(i) < f(r) R=i; % pickpqr %-------------------------------------------------------------------- function [feet,f]=reflect_foot(funk,feet,f,j,scale) % Reflect the jth foot through the centroid of the other % feet of the amoeba. The displacement may be scaled by % using scale, whose default value of 1 results in a % reflection that preserves the volume of the amoeba. % A scale of 0.5 should never be used, as this would result % in a degenerate simplex. Typical scale values: % 1... reflect through amoeba's opposite face % -0.5... stretch the foot outward, doubling amoeba size % 0.25... shrink inward, halving amoeba size % The following variables get updated: % feet(j,:) -- location of the jth foot % f(j) -- value of funk at the jth foot if nargin ~= 5 scale=1; %default

if scale == 0.5 error('oops, you squashed the amoeba!') [Nfeet,N]=size(feet); %Get amoeba dimensions if Nfeet ~= N+1 error('not an amoeba: wrong number of feet!') % Calculate displacement vector cent = ( sum(feet,1) - feet(j,:) )/N; %centroid of the feet, except the jth foot. disp = 2*(cent - feet(j,:)); % Move the foot, and update f feet(j,:) = feet(j,:) + (scale*disp); %scaled displacement f(j) = feval(funk,feet(j,:)); %evaluate funk % reflection %--------------------------------------------------------------------- function [feet,f]=ndcontract(funk,feet,f,j) % Contract all feet, except jth, toward the jth foot. % The following variables get updated: % feet -- location of each foot % f -- value of funk at each foot [Nfeet,N]=size(feet); %Get amoeba dimensions if Nfeet ~= N+1 error('not an amoeba: wrong number of feet!') for i=1:nfeet if i ~= j feet(i,:) = ( feet(i,:) + feet(j,:) )/2; f(i) = feval(funk,feet(i,:)); % ndcontract 3.2 Application example: least squares fitting Fitting a line (or a polynomimal) to data can be done most efficiently by the traditional linear least squares technique, but you could use the strategy

below to fit any sort of complicated, nonlinear multi-parameter model. It would be easy to modify this code for alternate fit criteria, such as minimum absolute deviation, which is more robust against outliers than least squares. The first module is just a main program that picks a random slope and a y- intercept, creates some pseudo-random noisy data that fluctuates about the mean of that line, and then tries to find a best fit line by looking only at the noisy data. The program compares the initial line, the noisy data, and the best-fit line by plotting all three on a single graph. Note that the number of data points (20) is much larger than the number of parameters used for the minimization (N=2, just a slope and a y-intercept). function no_result=least_squares() % least_squares.m % Least Squares Curve Fitting Demonstration hold off slope=4*(rand(1)-0.5) yintercept=2*(rand(1)-0.5) %Make some data, complete with 'noise' global datax datay %share these with the badness function (below) datax = 0:0.05:1.0; datay = (slope*datax)+yintercept; plot(datax,datay,'r--'); %Plot the theory used to generate the data hold; %save current display for overplotting [M,N] = size(datax); error = 0.5*(rand(M,N)-0.5).*(max(datay)-min(datay)); %create noise datay = datay + error; %add noise to data plot(datax,datay,'ro'); %Overlay more realistic noised data %Find best fit slope and yintercept from noised data result = amoeba('badness',[0,0],20); slope=result(1) yintercept=result(2) result = amoeba('badness',result,20); slope=result(1) yintercept=result(2) %Generate best fit curve, plot for comparison fit_y = (slope*datax)+yintercept; plot(datax,fit_y,'b-'); %Plot the theory hold off % of main program

Below is the function f(x), which I call badness a measure of how bad the fit is. This is where least-squares comes in: the badness is the sum of the squares of the differences between the real data points and a trial fit. The trial fit is derived from slopint, a 2-vector containing a guess for slope and y-intercept. The best fit therefore minimizes badness. function sum_squares=badness(slopint) global datax datay [M,N] = size(datax); theory_y = slopint(1)*datax + slopint(2); sum_squares = sum((theory_y - datay).^2); % badness