% % Computes the global minium by explicit enumeration for the various test functions % found on Epage 250 of the book Practical Genetic Algorithms % by Haupt & Haupt. % disp('performing global brute force search'); switch funnum case 1, x = linspace( -20, +20, 1000000 ); f = testfunction(x,funnum); [mf,mind] = min( f ); xmin = x(mind); xmin, mf case 2, x = linspace( -20, +20, 1000000 ); f = testfunction(x,funnum); [mf,mind] = min( f ); xmin = x(mind); xmin, mf case 3, N=10000; xs = linspace(-5,5,N); ys = linspace(-5,5,N); [X,Y] = meshgrid( xs, ys ); x = [ X(:), Y(:) ]; f = testfunction(x,funnum); [mf,mind] = min( f ); xmin = x(mind,:) mf case 4, N=10000; xs = linspace(-3,3,N); ys = linspace(-3,3,N); [X,Y] = meshgrid( xs, ys ); x = [ X(:), Y(:) ]; f = testfunction(x,funnum); [mf,mind] = min( f ); xmin = x(mind,:) mf case 5, N=10000; xs = linspace(-10,10,N); ys = linspace(-10,10,N); [X,Y] = meshgrid( xs, ys ); x = [ X(:), Y(:) ]; f = testfunction(x,funnum); [mf,mind] = min( f ); xmin = x(mind,:) mf case 6, N=10000; x = linspace( -10, +10, N ); f = testfunction(x,funnum); [mf,mind] = min( f ); xmin = x(mind) mf case 7, N=10000; xs = linspace(0,10,N); ys = linspace(0,10,N); [X,Y] = meshgrid( xs, ys ); x = [ X(:), Y(:) ]; f = testfunction(x,funnum); [mf,mind] = min( f ); xmin = x(mind,:) mf case 8, N=10000; xs = linspace(0,10,N); ys = linspace(0,10,N); [X,Y] = meshgrid( xs, ys ); x = [ X(:), Y(:) ]; f = testfunction(x,funnum); [mf,mind] = min( f ); xmin = x(mind,:) mf case 10, N=10000; xs = linspace(-4,4,N); ys = linspace(-4,4,N); [X,Y] = meshgrid( xs, ys ); x = [ X(:), Y(:) ]; f = testfunction(x,funnum); [mf,mind] = min( f ); xmin = x(mind,:) mf case 11, N=10000; xs = linspace(-10,10,N); ys = linspace(-10,10,N); [X,Y] = meshgrid( xs, ys ); x = [ X(:), Y(:) ]; f = testfunction(x,funnum); [mf,mind] = min( f ); xmin = x(mind,:) mf case 12, N=10000; xs = linspace(-5,5,N); ys = linspace(-5,5,N); [X,Y] = meshgrid( xs, ys ); x = [ X(:), Y(:) ]; f = testfunction(x,funnum); [mf,mind] = min( f ); xmin = x(mind,:) mf case 13, N=10000; xs = linspace(-10,10,N); ys = linspace(-10,10,N); [X,Y] = meshgrid( xs, ys ); x = [ X(:), Y(:) ]; f = testfunction(x,funnum); [mf,mind] = min( f ); xmin = x(mind,:) mf case 14, N=10000; xs = linspace(-5,5,N); ys = linspace(-5,5,N); [X,Y] = meshgrid( xs, ys ); x = [ X(:), Y(:) ]; f = testfunction(x,funnum); [mf,mind] = min( f ); xmin = x(mind,:) mf case 15, N=10000; xs = linspace(-5,5,N); ys = linspace(-5,5,N); [X,Y] = meshgrid( xs, ys ); x = [ X(:), Y(:) ]; f = testfunction(x,funnum); [mf,mind] = min( f ); xmin = x(mind,:) mf case 16, N=10000; xs = linspace(-20,20,N); ys = linspace(-20,20,N); [X,Y] = meshgrid( xs, ys ); x = [ X(:), Y(:) ]; f = testfunction(x,funnum); [mf,mind] = min( f ); xmin = x(mind,:) mf otherwise error( 'unknown test function or not implemented yet' ); end % % We now run a local optimization method now to refine our search using the above as a starting point: % wfn = @(x) fn_wrap(x,funnum); addpath('../SHIP'); fprintf('performing local optimization search with nelder mead\n'); x0 = repmat(xmin(:),[1,3]) + 0.1 * [ -1, +1; +1, +1; 0, -1 ]'; nm = nelder( x0, wfn, 1.e-6 ); nm = mean( nm', 1 ) wfn( nm ) fprintf('performing local optimization search with BFGS\n'); bfgs_1 = bfgswopt( nm(:), wfn, 1.e-6 ) wfn( bfgs_1 )