⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.m

📁 本人编辑的标准PSO算法
💻 M
字号:
%RunExp >> Automation function
% Usage     : RunExp(noRuns, ExitAction) %e.g. RunExp(25, 1); -> Runs each experminet for 25 trials and Exits matlab when doen.
% Arguments : (optional) noRuns     -> Integer -> Number of trials per experiment
%             (optional) ExitAction -> Integer -> Action to perform on completion of experiments
%                                       NOTE: Argument noRuns is required if ExitAction is to be specified.
%                                       Accepted values and their meaning.
%                                       0 = Do Nothing
%                                       1 = Exit Matlab
%                                       2 = Exit Matlab and Shutdown (Windows XP only)
%                                       3 = Exit Matlab and Logoff   (Windows XP only)
%                                       4 = Exit Matlab and Shutdown (Win98 and Me)
%                                       5 = Exit Matlab and Logoff (Win98 and Me)
%
% This function is useful to automate the generation of experimental data.
%
% The default function would conduct the same experiments that were conducted by Ebenhart and Kennedy in their
% paper - Empirical Study of Particle Swarm Optimization (1999 IEEE 0-708-5536-9/99).
% You may want to change the values of parameters and the names of the functions etc. to suit u'r research
%
% The script stores the values of objective values and history for all the functions in text files for anlysis.
% The name of the function, swarm size and # of dimensions is used to name these files.
% Files starting with an f_ contain the fitness values of the trials while those that begin with an h_ contain the
% history for each trial.
%
% Set the variable numberofRuns to the number of trials needed per experiment.
%
% History        :   Author      :   JAG (Jagatpreet Singh)
%                    Created on  :   07102003 (Thursday. 10th July, 2003)
%                    Comments    :   Arghhhhh! Why don't the results match.
%                    Modified on :   07142003 (Monday. 14th July, 2003)
%                    Comments    :   Converted script into a function. Added code to automatically exit,
%                                    shutdown or logoff the computer.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Hmm.. I ran the simulations (enter RunExp to try u'rself), but ..er. the results don't match Ebenhart and Kennedy's quoted results.
% So here's somethin for u to work on.>> Answer the following :
%
% Q|What went wrong? ???
%   Your choices are -
%       a)The code of this toolbox. (if yes, plz point out the location and correction)
%       b)The random number genrator on my computer
%       c)There was some typo in the paper (try changing values of c1, c2 and w.)
%       d)Er..Code used by Ebenhart and Kennedy in their experiments!
%       e)None/All of the above
% E-mail your answers/comments/analysis to jagatpreet@users.sourceforge.net.
% The one who convinces me with his/her answer would be featured on the psotoolbox website along with the answer. :-)
% So. Get u'r analytical hats on.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;
clc;
numberofRuns = 10;          %number of trials per experiment

psoOptions = get_psoOptions;

psoOptions.Vars.ErrGoal = 1e-20 ;
% Parameters common across all functions
psoOptions.SParams.c1 = 2;
psoOptions.SParams.c2 = 2;
psoOptions.SParams.w_start = 0.9;
psoOptions.SParams.w_end = 0.4;
psoOptions.SParams.w_varyfor = 1;

psoOptions.Flags.ShowViz = 0;
psoOptions.Flags.Neighbor = 0;
psoOptions.Save.Interval = 0;
psoOptions.Disp.Interval = 0;

% Run experiments for the three complex functions
if 1
    psoOptions.Obj.fitnessfunction = 'DeJong'; 
    psoOptions.Obj.lb = -2;
    psoOptions.Obj.ub = 2;
    psoOptions.SParams.Vmax = 2;
    GenExpData(numberofRuns, psoOptions);
end
if 0
    psoOptions.Obj.fitnessfunction = 'Rastrigrin';
    psoOptions.Obj.lb = 2.56;
    psoOptions.Obj.ub = 5.12;
    psoOptions.SParams.Vmax = 10;
    GenExpData(numberofRuns, psoOptions);
end
if 0
    psoOptions.Obj.fitnessfunction = 'Griewank';
    psoOptions.Obj.lb = 300;
    psoOptions.Obj.ub = 600;
    psoOptions.SParams.Vmax = 600;
    GenExpData(numberofRuns, psoOptions);
end
if 0
    psoOptions.Obj.fitnessfunction = 'Rosenbrock';
    psoOptions.Obj.lb = 15;
    psoOptions.Obj.ub = 30;
    psoOptions.SParams.Vmax = 100;
    GenExpData(numberofRuns, psoOptions);
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -