Sie sind auf Seite 1von 2

%The DeJong (Sphere) function for use with the psotoolbox % % Function Description: % Equation -> sum ( x(i)^2

) % xmin = [0, 0, 0.....0] (all zeroes) % fxmin = 0 (zero) function Dejed = DeJong(Swarm) [SwarmSize, Dim] = size(Swarm); Dejed = sum((Swarm .^2)')'; %The Griewank function for use with the psotoolbox % % Function Description: % Equation -> sum(((x(i).^2) / 4000)')' - prod(cos(x(i) ./ sqrt(i))')' + 1 % xmin = [0, 0, 0.....0] (all zeroes) % fxmin = 0 (zero) function Gred = Griewank(Swarm); [SwarmSize, Dim] = size(Swarm); indices = repmat(1:Dim, SwarmSize, 1); Gred = sum(((Swarm.^2) / 4000)')' - prod(cos(Swarm ./ sqrt(indices))')' + 1; %The Rastrigrin function for use with the psotoolbox % % Function Description: % Equation -> sum (x(i)^2 - 10 * cos(2 * pi * x(i)) + 10) % xmin = [0, 0, 0.....0] (all zeoes) % fxmin = 0 (zero) function Rastred = Rastrigrin(Swarm) [SwarmSize, Dim] = size(Swarm); Rastred = Dim * 10 + sum(((Swarm .^2) - 10 * cos(2 * pi * Swarm))')';

%The Rosenbrock function for use with the psotoolbox % % Function Description: % Equation -> sum ( 100 * (x(i+1) - x(i)^2)^2 + (1-x(i))^2 ) % xmin = [1, 1, 1.....1] (all ones) % fxmin = 0 (zero) function Rosened = Rosenbrock(Swarm) [SwarmSize, Dim] = size(Swarm); Swarm1 = Swarm(:, 1:(Dim-1)); Swarm2 = Swarm(:, 2:Dim); if Dim == 2 Rosened = 100 * (Swarm2 - Swarm1.^2).^2 + (1 - Swarm1).^2; else Rosened = sum((100 * (Swarm2 - Swarm1.^2).^2 + (1 - Swarm1).^2)')'; end DrawSwarm >> Internal function of psotoolbox. % Purpose: To draw a visual display of the Swarm. % % You shouldn't need to mess around with this fn. if u don't wanna change the visualization. % % see also: pso.m % function DrawSwarm(Swarm, SwarmSize, Generation, Dimensions, GBest, vizAxes) X = Swarm'; if Dimensions >= 3 set(vizAxes,'XData',X(1, :),'YData', X(2,:), 'ZData', X(3,:)); elseif Dimensions == 2

set(vizAxes,'XData',X(1, :),'YData', X(2,:)); end GenDiv = 100; xAx = GBest(1); yAx = GBest(2); zAx = GBest(2); zf = 100 * 50/Generation; %zoom factor if rem(Generation, GenDiv) == 0 axis([xAx-zf xAx+100 yAx-zf yAx+zf zAx-zf zAx+zf]); end title(Generation); drawnow; %show_psoOptions >> A function to read and display the psoOptions structure. % % Usage : strOptions = show_psoOptions( psoOptions ) % Arguments : A structure containing various options for PSO % Return Values : A string containing the information abt the elements of the provided structure. % % History : Author : JAG (Jagatpreet Singh) % Created on : 06252003 (Wednesday. 25th June, 2003) % Comments : A nice utility function. % % see also: get_psoOptions % function strOptions = show_psoOptions(IndentLevel, Variable) if nargin < 1 disp(sprintf('\n\t:::No Options Structure provided:::\n')); return; elseif nargin == 1 Variable = IndentLevel; IndentLevel = 1; end; if IndentLevel < 1 IndentLevel = 1; end subHeads = char(fieldnames(Variable)); indentTab = [sprintf('\t')]; strOptions = ''; for i=1:size(subHeads, 1) thisField = getfield(Variable, subHeads(i,:)); %assign the contents of the current structure element to thisField strOptions = [strOptions repmat(indentTab, 1, IndentLevel) subHeads(i,:)]; %Display upto the field name if isstruct(thisField) strOptions = [strOptions sprintf('\n') show_psoOptions(IndentLevel+1, thisField)]; %Write contents of the structure in next line else if ischar(thisField) strField = sprintf('%s', thisField); elseif isnumeric(thisField) strField = sprintf('%4.5g', thisField); else strField = sprintf(':::Can''t display item:::'); end strOptions = [strOptions sprintf(' :') indentTab strField sprintf('\n')]; end end

Das könnte Ihnen auch gefallen