Code covered by the BSD License  

Highlights from
State-machine simplex minimizer

4.5

4.5 | 2 ratings Rate this file 6 Downloads (last 30 days) File Size: 3.04 KB File ID: #4317

State-machine simplex minimizer

by Fred Sigworth

 

30 Dec 2003 (Updated 09 Jun 2009)

A simple minimizer of in-line coded functions, for teaching and experimentation.

| Watch this File

File Information
Description

This is a single M-file that implements a Nelder-Mead simplex minimizer. It makes use of MATLAB's persistent variables to create a "state machine" implementation. This allows entire minimization programs to be written as MATLAB scripts, as it does not require a function to be defined and passed to the minimization routine. In my opinion, this makes the fitting of functions to data much more fun and educational!

The traditional approach to optimization is to pass a function to an optimizer, which then takes control of the program until it is done. For example, the function 'fun' is minimized by a call to
x = fminsearch(fun,x0,options).
The disadvantage of this approach is that 'fun' must be defined in an M-file, and inserting code to observe the progress of the minimization is made difficult by the different scopes of the calling program and 'fun'.

Simplex.m does not take control of the program, but instead provides a new vector of parameters to "try" with each iteration. Here is a simple example, that minimizes the sixth power of the difference between two vectors:

% Example of use: minimize (p-q).^6

p=[2 2 1.5 2]'; % inital guess
q=[1 1 1 1]'; % true values

p=Simplex('init',p);

for i=1:200
    y=sum((p-q).^6); % Evaluation of the function
    p=Simplex(y); % Simplex provides a new vector p

    if ~mod(i, 10) % every 10 iterations print out the fitted value
  p'
    end;

end;

p=Simplex('centroid'); % get the final best value.
 
The first call to Simplex is an initialization, where the starting guess of the parameter vector is supplied. The function sum(p-q).^6 is evaluated in-line, and its result is given to Simplex; in turn, a new parameter vector p is returned. The progress of the minimization is easily monitored because the function evaluation remains in the scope of the main program.

MATLAB release MATLAB 6.5 (R13)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
27 Jul 2006 Chris Foster

This is an incredibly useful algorithm that is very easy to use. It is quite ready for deployment in design applications.

19 Oct 2006 Nguyen Hang

I want to known that how many status in your status machine? i want a 5 status machine in matlab,please tell me how to create it? Thank for your help!

24 Sep 2007 Rodrigo Pereira  
Please login to add a comment or rating.
Updates
09 Jun 2009

Simplified the example code in the description.

Tag Activity for this File
Tag Applied By Date/Time
optimization Fred Sigworth 22 Oct 2008 07:12:09
neldermead Fred Sigworth 22 Oct 2008 07:12:09
persistent variable Fred Sigworth 22 Oct 2008 07:12:09
minimizer Fred Sigworth 22 Oct 2008 07:12:09
state machine Fred Sigworth 22 Oct 2008 07:12:09
code Fred Sigworth 22 Oct 2008 07:12:09

Contact us at files@mathworks.com