LAB 5 - Simulated Annealing 214 Introduction. In this lab you will write a program for simulated annealing. You will test the program on a one-dimensional fitness surface with multiple local maxima. In addition you will use this surface to study the effects of various annealing parameters on search efficiency. You will then adapt the code to optimize a neural network to oscillate. EXERCISE 1 Download the procedure file Student-sim-anneal-214.ipf and adopt the code, which contains the function sas(). On the left is the flow chart I presented in lecture. It is an Initialize network or neuron (X = X1, X2, X3 ) Make N noisy copies of X Compute performance of each copy Move to point X oversimplification. For example, the code doesn t make and store N copies of the parent network before testing. Rather, each of the copies is created and tested before the next one is made.make a more accurate and detailed flow-chart of the program an include it in your lab report. Where possible, use variable names as specified in the code. Concentrate on the initialization and for-loops. Omit variable declarations. Don t worry too much about the format of the diagram. The purpose of this exercise is to encourage you to understand the code before using it (always a good practice). EXERCISE 2 The goal of simulated annealing is to maximize the performance of a model relative to a fitness function defined over the model parameters you are seeking to optimize. In Exercise 3, you will apply sas() to a one-dimensional problem in which you seek the value of X that
maximizes the output of a function called fitnessfunction(). But first you must write code that implements the function, which is the product of m and n: m = 1+ cos(.4v) 2 n = exp( v 2 /(2)) Paste your function into your lab report. EXERCISE 3 Display the fitness surface. To do this, make the wave fitness with 1 points starting at x = -5 and ing at x = 5 (using Data > Change Wave Scaling). Set the y-values in fitness to the corresponding value of the fitnessfunction(). Display fitness and include the graph in your lab report. It should look like this: 2. 1.5 Fitness 1..5. -4-2 X value EXERCISE 4 Run the sas() with an initial X value of 25 and an initial temperature of 1. To see the trajectory of the annealing algorithm along the fitness surface, apptograph to the fitness graph a trace of "fithistory vs testxvaluehistory. Double click this trace to get to the Modify Trace appearance Dialog. Select Set as f(z), Color as f(z), and choose the wave called mycolor. You should see the simulation stuck on the local maximum that is second from the right. Include the graph in your lab report. Report the probability of finding the peak of the fitness curve sas(25, 1). Slowly increase the temperature until you find the peak about 9% of the time. Report this value and explain its significance in terms of the relationship between the search radius and the dimensions of the width of the fitness curve. 2 4 2. 1.5 Fitness 1..5. -4-2 X value 2 4
EXERCISE 5 Another informative graph is the plot of all the intermediate best fitnesses versus iteration number. Make this plot simply by displaying maxfithistory. Include the graph in your lab report. EXERCISE 6 [Optional 214] Complete the table below by running simulation 2 times with each of 1 different values of temp shown. Plot number of failures vs temperature and number of iterations to reach the peak vs temperature. Describe and explain any trs you find. Initial temperature Number of failures Mean number of iteration to reach the peak* 1 5 1 5 1 5 1 5 1 5 * Successful runs only. EXERCISE 7 Use your annealer to search for values of the synaptic threshold parameter and the weight parameter in the neural network of Exercise 7 in the lab Dynamical Neurons (Week 7 214). A working version of this code is provided in the file Student-sim-anneal-214.ipf. The goal
of this exercise is to search parameter space defined by weight and parameter using simulated annealing in an attempt to get the network to oscillate. To do this: (1) Modify the sas() function so that it searches so that it searches for weight and threshold rather than Xvalue. For assistance in this process, repair the // FIXME // statements in the function sas7() contained in this lab s Igor procedure file (see above). (2) Write a function that operates on the voltage time series of one of the neurons in your network and returns a numerical value that represents the extent to which the network is oscillating. Insert this code into the body of the function netfit(), found in the Igor procedure file. You might the Igor function wavestats() useful in this regard (look it up in Help > Command Help). It computes wave averages, standard deviations, max and min values, etc. Here are some examples of how to use the wavestats() function: Function sd() // Compute standard deviation from 5 to 1 ms return V_sdev Function av() //Compute average from 5 to 1 ms return V_avg Function mn() // Find minimum from 5 to 1 ms return V_min Function mx() // Find maximum from 5 to 1 ms return V_max Include your netfit() function in your lab report. Any oscillation will do, but strive for one that occurs in the range -1 to -7 mv, as shown in the figure. If you get an oscillation, report the weight and threshold values you found and include a graph. [[ 215: Draw a circuit diagram ]]. 1-1 -2 V V1 V2 mv -3-4 -5-6 2 4 t (ms) 6 8 1
Appix Example of flow chart: