Code covered by the BSD License  

Highlights from
Simple example of PSO algorithm

4.66667

4.7 | 3 ratings Rate this file 128 Downloads (last 30 days) File Size: 1.74 KB File ID: #30660

Simple example of PSO algorithm

by Andrea Cirillo

 

07 Mar 2011

Matlab function to find the minimum of a objective function with the PSO Algorithm

| Watch this File

File Information
Description

It finds the minimum of a n variables function with the Particle Swarm Optimization Algorithm.

% The input parameters are:
% -func: it's the objective function's handle to minimize
% -numInd: it's the number of the swarm's elements
% -range: it's the range in which the elements must be created
% -n_var: it's the number of function's variables
% -tolerance: it's the tolerance for the stop criterion on the swarm's
% radius
% -numIter: it's the max iterations' number
% -pesoStoc: it's the swarm's movability
%
% The output parameters are:
% -p_min: the minimum point find
% -f_min: the minimum value of the function
% -iter: the number of iterations processed

MATLAB release MATLAB 7.11 (2010b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (9)
24 Oct 2011 Ahmed Hany

Hello Andrea ;

Pleass tell me the format used for input func ( objective function ) .

24 Oct 2011 Andrea Cirillo

The objective function have to be a matlab function (you can create a .m function) with its input and output parameters. After you created the function, you can obtain the function handler with the @ symbol. A simple example: if c = sum(a) is my function, I will create the follow matlab function.

function c=sum(a)
c=a(1)+a(2);

where 'a' is a vector that contain the input parameters. After I can define the function handle:
f_vett=@(x) sum(x)
where f_vett is a multivariable function and x is the vector that contains the variables of the function.

Now, if f_vett is a objective function, you can use the pso algorithm as follow:

[p_min, f_min, iter]=pso(f_vett, 5000, [0 20], 10, 0.0001, 200, 0.7)

14 Nov 2011 Ahmet Ahmet  
13 Dec 2011 Akbar

I am trying to solve Skew correction problem with PSO. I have a prob with defining the objective function.

This is a simple example given above. The problem I am facing is that I have to maximize the difference of maxima and minima of the projection profile of the image. Given as,

F(theta)=PP(maxima)-PP(minima);

theta here is swarm particle (1D)

How should i be using this 'theta' in my function to maximize the objective function given as above.

Thanks

19 Dec 2011 Giacomo

It works fine!!!

08 Mar 2012 Michael Bernard

Why does the example fail to run in matlab? I got this message when I ran the file.The message reads :"??? Input argument "range" is undefined.
Error in ==> pso at 19
range_min=range(1); % Range for initial swarm's elements "

I have never used partical swarm.Am new to it

15 Mar 2012 SANI LAWAL

Hello Michael, it do run but u need to define the range and other input parameters as given by Mr Andrea, it runs perfectly,but my only doubt is the minimal value because i got 1.0e+006,so i want be sure is it the minimum value?
Thank you so much

12 May 2012 KT

hi!!!! i am trying to understand the concept of PSO but the code is giving me the following error:
??? Index exceeds matrix dimensions.

can some one please tell where i am wrong???

12 May 2012 Andrea Cirillo

Of course the error is on the input variables that you use for PSO function. You can follow the simple example of the previous comment.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
optimization Andrea Cirillo 07 Mar 2011 09:48:08
mathematics Andrea Cirillo 07 Mar 2011 09:48:08
swarm Andrea Cirillo 07 Mar 2011 09:48:09
pso Andrea Cirillo 07 Mar 2011 09:48:09
minimum Andrea Cirillo 07 Mar 2011 09:48:09
function Andrea Cirillo 07 Mar 2011 09:48:09
particle Andrea Cirillo 07 Mar 2011 09:48:09
pso Ali Nejati 16 Jun 2011 01:04:02
function Daniel 09 Apr 2012 21:28:13

Contact us at files@mathworks.com