-
Notifications
You must be signed in to change notification settings - Fork 2
/
gridTest.m
51 lines (38 loc) · 1.5 KB
/
gridTest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function gridTest()
% Robin Deits <robin.deits@gmail.com>
% August, 2010
% This function takes two input parameters for the simulation and
% tests them at all points of a (numSteps x numSteps) grid of values for those variables,
% allowing a 3D plot of cost values to be generated. It is meant to be run with no input
% parameters; rather, the parameters should be set directly within the file. This makes it
% easier to see what parameters were used in a give set of tests.
% gridTest also calls makeContourPlot.m, which creates 3D and contour plots
% summarizing its results.
%% Parameters to be set by user:
varNames = {'a','b'};
% The center of the range
x0 = [0,0];
% The width of the range for each variable
widths = [3,5];
% The number of steps for each variable
numSteps = 11;
extraMessage = 'hello world';
fitnessFunc = @(x) costFunction(x,varNames,extraMessage);
%% Generate the variable ranges
xValues = linspace(x0(1)-widths(1)/2,x0(1)+widths(1)/2,numSteps);
yValues = linspace(x0(2)-widths(2)/2,x0(2)+widths(2)/2,numSteps);
if exist('summary.txt') == 2
disp('Optimization results already detected in this folder.')
disp('Previous results and MATLAB files must be deleted before running a new optimization')
return
end
backupMFiles('gridTest.m');
createSummary(varNames);
%% Perform grid testing
for i = 1:numSteps
for j = 1:numSteps
x = [xValues(i),yValues(j)];
fitness = fitnessFunc(x);
end
end
makeContourPlot(varNames);