File Exchange

## Simple example of PSO algorithm

version 1.0.0.0 (1.74 KB) by Andrea Cirillo

### Andrea Cirillo (view profile)

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

Updated 07 Mar 2011

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
% -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

Ankit kanodia

wu yang

### wu yang (view profile)

Can you help me for a design IIR filter by using PSO

Shreeram Choudhury

### Shreeram Choudhury (view profile)

f_vett =@(x,y) (x.^2+5*y);

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

it is showing error
f_vett =@(x,y) (x.^2+5*y);

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

Gulay özkan

### Gulay özkan (view profile)

can you help me partical swarm optimization block for simulink blocks.
thanks

Can you use please tell me the control parameters of upfc , which are needed to be varied while its is optimally placed in the weakest bus in the bus system.

### RAVI TEJASWI GADAGAMMA (view profile)

Hi andrea, can you explain why fitness is used in pso method. It is enough to find min or max...

Leo Nog

tarafa akrame

tarafa akrame

hello
thanks M N Alam

M N Alam

M N Alam

Sharif

### Sharif (view profile)

Hi Andrea, what is the function of radius?

Andrea Cirillo

### Andrea Cirillo (view profile)

I'm sorry, but I don't know what it is.

Dear Andrea,

Can you provide me the code of Quantum behaved PSO? Do you have idea on this algorithm?

Bala Senthil

### Bala Senthil (view profile)

Hi andrea, can i use PSO as a classifier? Is it possible?

shaista

### shaista (view profile)

How we can optimize anfis structure using PSO method in GUI

Tirupal Talari

### Tirupal Talari (view profile)

hello andrea can u plz help me to find optimal block size of an image using pso technique

Hamza

### Hamza (view profile)

Hello every one .
Most of the example codes I have seen so far is that PSO tries to find a minimum or maximum of a function.
is it possible to modify this code for multi-objective optimization.

Like
fitness=utility1*w1+utility2*w2

Sajeev J

### Sajeev J (view profile)

Hi Andrea, I am doing a classification problem. I am classifying a protein as either cancerous or not with 644 features. My guide instructed me to optimize the feature vector using PSO. I am clear with your code, but I don't know how to write the objective function. My SVM classifier works well with 644 features and put in two groups (1 or 0). Hope you can help me. Thanks

sangjinlee

Andrea Cirillo

### Andrea Cirillo (view profile)

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.

KT

### KT (view profile)

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???

SANI LAWAL

### SANI LAWAL (view profile)

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

Michael Bernard

### Michael Bernard (view profile)

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

Giacomo

It works fine!!!

Akbar

### Akbar (view profile)

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

Ahmet Ahmet

Andrea Cirillo

### Andrea Cirillo (view profile)

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)

Ahmed Hany

### Ahmed Hany (view profile)

Hello Andrea ;

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

##### MATLAB Release Compatibility
Created with R2010b
Compatible with any release
##### Platform Compatibility
Windows macOS Linux