This homework uses four files for use with MATLAB. The four files are:
For all of the questions below, hand in (on the due date) the
relevant print-outs from MATLAB, such as command-window output or
graphical output or M-file code.
- Explore the behavior of the optimization
algorithms.
Run the ModelErrorGraph.m program with
various values of parInit and parInc, as specified below. This is a
script, not a function, so go to the file in the Editor
window and press F5 to run it.
The goal of this exercise is for you to notice that the best
fit found by the program depends on (a) the initial values of the
parameters, (b) the increments used in the search, and (c) the type of
search algorithm used.
- Effect of parameter increments. Set parInit = [ 1 -2 ]. Now run
it using parInc = [ 0.1 0.1 ] versus parInc = [ 0.2 0.2 ]. Does
SimpleHillClimb end up at the same minimum for both increments? Why
not? Do the the three search algorithms end up in the same minima as
each other? Do they find one of the three local minima of the
function or do they get stuck on a boundary of the allowed space?
- Effect of initial parameters. Set parInc = [ 0.1 0.1 ]. Run it
using parInit = [ -2 0 ] versus parInit = [ -2 0.5 ]. Do
SimpleHillClimb and fminsearch and fmincon end up at the same minimum
for both initial positions? Do they end up in the same minimum as each
other? Do they find one of the three local minima of the function or
do they get stuck on a boundary of the allowed space?
- Try a different model.
Modify the ModelError.m
file so that
error = 10 * -cos( 2*
(paramVals(1)^2+paramVals(2)^2)^0.5 ) ...
* exp( -0.5 *
((paramVals(1)+1)^2+(paramVals(2)-1)^2)^0.5 ) + 5.1 ;
(The "..." is part of the MatLab code; it means that the command
continues on the next line.) The purpose of this exercise is to
emphasize that the model program is separate from the fitting
algorithm. Changing the function being optimized is like changing the
model.
- Run this new model function using three different initial
values, all with parInc = [ 0.1 0.1 ]: parInit = [ 0 -1.5 ], parInit =
[ 0 -1.6 ] and parInit = [ 1.6 -1.6 ]. Do SimpleHillClimb and
fminsearch and fmincon end up at the same minimum for both initial
positions? Do they end up in the same minimum as each other? Do they
find one of the two local minima of the function or do they get stuck
on a boundary of the allowed space?
- Why does SimpleHillClimb sometimes get stuck at points where
there is clearly a "downhill" slope? (Hint: It tests only X and Y
increments, not diagonal increments.)
- Modify the program code to make it more
elegant.
As it is now, SimpleHillClimb.m has two copies of
the code that increments and decrements parameters - one copy for each
parameter. Modify the code so that there is only one
increment-decrement section, embedded in a loop that is executed once
for each parameter. The loop would probably look like this:
for parIndex = 1 : length( parInit )
% insert here: code for increment-decrement corresponding
parameter
end
The purposes of this exercise
are (a) to make sure you really understand what the hill-climbing
program is doing, and (b) to get you to really start programming in
MATLAB (even though loops are not MATLAB's strong suit).