Thursday 23 February 2012

Particle Swarm Optimization ( PSO ) - Introduction and Java Program


Particle Swarm Optimization is a metaheuristic optimization technique which generates a population of particles which adjusts its particle position and velocity in the search space, according to a set of mathematical formulas, so as to locate the best solution.

PSO belongs to the broad class of Swarm Intelligence Methods for solving Global Optimization problems. It was developed by James Kennedy and Russel.C.Eberhart, inspired by social behavior of bird flocking or fish schooling.



Simulation of Bird Flocking

Consider a flock of birds searching for food in an area. There is only one piece of food in that area and all the birds are searching for it. In each iteration the birds are only aware of how far the food is.
So the best approach to get the food is to follow the bird which is nearest to it.


How it Works

In PSO,
The birds are the solutions which are termed as particles
1
  1. Each particle has a fitness value. Our aim is to optimize this fitness value as evaluated by the fitness function.
  2. Each particle has its own position and velocity calculated by the position and velocity function respectively.
  3. Initially, the PSO is initialized with group of particles whose parameters are altered during each iteration.
  4. In each iteration, every particle updates its fitness value and its pbest (personal best value)
  5. Meanwhile during each iteration the PSO reviews the gbest (i.e. the best pbest value obtained by any of the particle to that point.)



Characteristics of PSO
  1. PSO does not guarantee that an optimal solution is ever found.
  2. It is a metaheuristic computational method (i.e.  it optimizes the problem by  trying to improve the candidate solution with regard to a given measure of quality. )
  3. It’s similar to Genetic Algorithms.
  4. It’s easier to implement
  5. There are only a few parameters to be adjusted



General Pseudocode

For each particle 
          Initialize particle
End

Do
    For each particle 
                   Calculate fitness value
                   If (fitness value is better than the pBest )
                                                set current value as the new pBest
    End

    gBest = particle with the best fitness value of all the particles

    For each particle 
                   Calculate particle velocity according equation (a)
                   Update particle position according equation (b)
    End 
End 



 PSO Example:

Function Optimization (Java Program)

The following is a Sample Code  for the Java implementation of a simple PSO for function optimization of one dimensional quadratic equation.

In order to perform function optimization using PSO, some of the classes that we require are:

1.     Location -  To represent the position of the particle
2.     Velocity -   To represent the velocity of the particle
3.     Particle   -  To represent the particle
4.     PSOController – performs the PSO operation.

Position class
 Velocity class:
 Particle class:

 Here the function is evaluated by the calculateFitness() function.

InitializeAbc gets the quadratic equation from the user.


Here’s the code(partial code):

 Some of the constants used:
 Finally, a sample java implementation :

 Input:  (x2 +6x+9)
 Output:  (x = -3)



Prepared by:  Archana Devi
   Amrita School of Engineering,  Coimbatore



Mentored by:    Prof T.Senthil.Kumar
  Dept of Computer Science &  Engineering
  Amrita School of Engineering, Coimbatore
  Email id: sapne21@yahoo.com
                  senthan1@yahoo.co.in



128 comments:

  1. From variable swarm ?
    And fitnessList ?

    ReplyDelete
  2. Hai,
    I've mailed the code to you. If you have any furthur clarifications feel free to mail me anytime.
    Thank you

    ReplyDelete
    Replies
    1. hi,
      pls send the full code of PSO.It will be useful for me a lot.

      Delete
    2. Hi

      I hope you are doing well.

      I am working on a variant of PSO and I need the full working code that you have mentioned above.

      Kindly email me the full code on rashid.omer3@gmail.com


      Thanks and Best Regards

      Delete
    3. Hello, I need to do a similar project that optimizes using PSO, can you send me the source.here is my email: mails4morris@gmail.com

      Delete
    4. Hello, I will do a similar project that optimizes using PSO, can you send me the source.here is my email: djwdjj.520@gmail.com

      Delete
  3. hi Devi, nice article and very detailed explanation. Would you mind sending full code to softtech88@gmail.com.

    Thank in advance

    ReplyDelete
    Replies
    1. Hai..
      I hv sent it to your mail.

      Delete
    2. Please send the code to my email id sachchit.bansal@gmail.com.
      I need it for my study. Please Help.

      Delete
  4. hi dis s nice and i wana fll code ll u pls send it to me at arivuazhagan001@gmail.com

    ReplyDelete
    Replies
    1. I have sent it to your mail

      Delete

    2. Please send the code to my email id sachchit.bansal@gmail.com.
      I need it for my study. Please Help.

      Delete
    3. This comment has been removed by the author.

      Delete
    4. Hello, I will do a similar project that optimizes using PSO, can you send me the source.here is my email: djwdjj.520@gmail.com

      Delete
  5. hi Devi, think you for this very nice article . Would you mind sending full code to landoulsi_marwen@hotmail.com

    Thank in advance

    ReplyDelete
  6. Hai
    I have send the code to your mail. Hope it would be helpful.
    Thanks...

    ReplyDelete
    Replies
    1. Hi

      I hope you are doing well.

      I am working on a variant of PSO and I need the full working code that you have mentioned above.

      Kindly email me the full code on a.abdulwahab.a@gmail.com


      Thanks and Best Regards

      Delete
  7. Hi devi can u send me the code ..to my id avinashgujju@gmail.com

    ReplyDelete
  8. Please its v urgent ..can u do it today itself...
    Thanks in Advance

    ReplyDelete
    Replies
    1. Hai I have the send the code. Hope it would be of help to your work...

      Delete
  9. hi Devi, thank you for this very nice article. It was very helpfull but i still got some questions. Would you mind sending full code to macioss@plusnet.pl ?

    Thank in advance

    ReplyDelete
    Replies
    1. Hai ... I've sent the code to your mail..Thank you..

      Delete
    2. Can you send me the full code

      Delete
  10. Hi!
    I'm from Poland and I myself is working on PSO right now.
    I think, your work is really great and aprreciable and I want see your source code, because it would be of great help for me.
    It's possible to have all your source code?
    My e-mail: witek1902@gmail.com

    ReplyDelete
    Replies
    1. Hai I've sent the code to your mail. Hope it would be helpful..Thank you

      Delete
  11. Hi devi its a good explanation,can you please send the full source code my email:v.goutham@gmail.com

    ReplyDelete
  12. Hi Devi,
    Can you send the the full source code its very urgent,can you please send it today itself
    my mail-id: v.goutham@gmail.com

    ReplyDelete
  13. Hi Devi, thank you for the nice article. you mind sending the full code to my email:

    192.16b.0.1@gmail.com

    thank you,

    ReplyDelete
  14. Hi devi, nice article.
    Would you mind sending full code to brkkpt@gmail.com?

    Thank you in advance

    ReplyDelete
  15. Hi, Devi. good work.

    Can u send the source code to fbpost2@gmail.com

    Thanking You.

    ReplyDelete
  16. Hi Devi,
    good work
    could you send the source code to uni.group2012@yahoo.com
    many thanks

    ReplyDelete
  17. can u send source code?
    my email sf.shahril@gmail.com
    thnkz =)

    ReplyDelete
  18. Hi Devi,
    great work
    could you send the source code to bendo01@gmail.com
    thank you very much

    ReplyDelete
  19. Hi Devi,
    I´m working in project about PSO
    and your code is insteresting for me.
    Can you send me the source code at pabloselect@gmail.com
    Thank you!

    ReplyDelete
  20. hi.. can you please mail the code to you85arun@gmail.com?
    Thanks in advance.

    ReplyDelete
  21. Hello mam...
    Can u pls mail me the code to sathyathamizhmani@gmail.com????
    Thanks in advance...

    ReplyDelete
  22. hello mam,
    Could u plz send the complete code to m??
    as m working on pso..so plz plz send it as early as possible...or the people who got the complete source code can mail m it on
    krishnagkwd11@gmail.com

    ReplyDelete
  23. Hi, Devi.

    Can u send the source code to suge86@gmail.com.


    Thanks You.

    ReplyDelete
  24. plz send me the code at abhigupta1993@rediffmail.com

    ReplyDelete
  25. Cara, você pode me enviar o código completo? Agradeço
    cavalcante.junior@live.com

    ReplyDelete
  26. This comment has been removed by the author.

    ReplyDelete
  27. Hello Devi, I will really appreciate if you could please send your code to dextrewinton@gmail.com. Thanks!!...:)

    ReplyDelete
  28. Hi devi, many thans to You if you could send me Ur full code about PSO to ringorbnsrg@gmail.com

    ReplyDelete
  29. hi mam now am doing research on data mining so i need to know about PSO concept and example code could u plz send me that java code my mail id is ibrahimias90@gmail.com

    ReplyDelete
  30. Nice code devi garu.. I am doing Project on PSO. can u give some idea about Travelling Sales person using PSO.. no idea where to start.. Looking for your replay.. Thank you..
    rajashekarcse33@gmail.com... this is my email id..

    ReplyDelete
  31. hi devi this article is verymuch useful can u pls mail ful code to srini169ms@yahoo.com
    thanks in advance

    ReplyDelete
  32. hi sir,
    can u pls mail me the source code for this article? markgodfrey.torres@gmail.com thank you so much in advance sir.

    ReplyDelete
  33. hello mam , i am doing a project on PSO, can u please send me the code on my id ashagautam021@gmail.com.
    i wiil be greatly obliged thanking u

    ReplyDelete
  34. Could i have source code on ttuannguyenn@gmail.com. Thanks for your share.

    ReplyDelete
  35. Hello, thank you very much for this help. Can you please send me the full code at enyonamval@gmail.com. Thank you very much, in advance, for this great help.

    ReplyDelete
  36. Hi,
    I like to have the full coding, so can you mail me
    kandanmani070@gmail.com

    ReplyDelete
  37. HI madam., i am having an objective fucntion with 3 variable and with 3 levels.,

    can u pl get send code for that to

    shunmugesh@gmail.com

    waiting for ur reply
    thanking you

    ReplyDelete
  38. hi mam, please send me the fulll coding of PSO to me. I am doing research on it and i need it urgently. Could u please send the full coding of PSO to amuldarling22@gmail.com?

    ReplyDelete
  39. plz send me the full code my id is: rani_alvin@yahoo.com

    ReplyDelete
  40. Hello Mr.Devi, would you please send me the source code to jihensalma@gmail.com
    thanks a lot .

    ReplyDelete
  41. Hai mam,
    Iam doing project in Datamining in matlab.. I already implemented PSO.. But i donot have knowledge about Heirarchical clustering... Can u please send me the code for that...
    my mail id: rekha.sree88@gmail.com

    ReplyDelete
  42. Hi Devi
    thank you for this very nice article. Would you mind sending full code to train7730@gmail.com.
    Thank's a lot :)

    ReplyDelete
  43. i need codin and materials related to this .. devi ji can u help me out..

    ReplyDelete
  44. Hi archana,

    Will you send me the full code to ganasundaram@gmail.com

    ReplyDelete
  45. hey,
    can you send me the full source code at mindajalaj@yahoo.com

    ReplyDelete
  46. nice article, I'm in experiment about datamining especially PSO and hierarchical clustering, Would yo like to send your code to my email? tsabbitaqdami@gmail.com
    thank you

    ReplyDelete
  47. Hello, can you give me the full code ? My email is mtzatzarov@gmail.com Thank you.

    ReplyDelete
  48. hi Devi, thank you. Your article was very helpfull. Would you mind sending full code to annagomes2012@gmail.com? merci

    ReplyDelete
  49. Hi Devi,
    This is very good Explanation, can u mail me source code of it on kharche.deepali@gmail.com

    Deepali

    ReplyDelete
  50. Thanks for the explanation. Kindly email the source code to me on chineduazubuike11@gmail.com

    ReplyDelete
  51. plz send me the full code my email:aboudinoura89@gmail.com

    ReplyDelete
  52. Hi Devi. Thanks for the explanation. Kindly email me the source code at nehaverma.connect@gmail.com

    ReplyDelete
  53. H i dave. Congratulations for your work. Would you mind sending me the full source code to my email:dimpant90@gmail.com. Thanks in advance!

    ReplyDelete
  54. hi devi. this article is really very useful. it make me easy to understand PSO.
    i need ful source code to go ahead in my project. will you please mail me ful soure code to email: mahaveer.sancheti@gmail.com
    Thanks

    ReplyDelete
  55. Hi,

    I'm in need of comparing the PSO algorithm with 3 different algorithms for my MS coursework. It would be really helpful for me to look at your full source code. If possible pls send me your full source code to kayal.alagu@gmail.com.

    Your help is highly appreciated.

    Thanks,
    Kayal.

    ReplyDelete
  56. Hello Devi, would you please send me the source code to jajangjayuz87@gmail.com
    thanks a lot

    ReplyDelete
  57. send me code, devi send to this my email, ekosuhartono01gmail.com

    :-( i very need

    ReplyDelete
  58. Hi Devi,

    This is very nice article. It really helped me in understanding PSO algorithm. Could you please send source code at piyush043@gmail.com.

    Thanks,
    Piyush

    ReplyDelete
  59. hi
    good work.plz could send me the code at ardh20@yahoo.com

    ReplyDelete
  60. hi Devi, think you for this very nice article . Would you mind sending full code to sangeetakalitajec@gmail.com

    ReplyDelete
  61. Hi Devi,

    This is very nice article. It really helped me in understanding PSO algorithm. Could you please send source code at praveenmandloi2007@gmail.com.

    Thanks,
    praveenmandloi2007@gmail.com

    ReplyDelete
  62. Hi Devi,

    Your article is very impressive. Can you send me the Java source code for PSO algorithm at atbhatti@aggies.ncat.edu

    Thanks,
    Ali Tariq Bhatti

    ReplyDelete
  63. hi Devi,
    nice article and very detailed explanation.
    Would you mind sending full code to rima.zarrouk@gmail.com.

    ReplyDelete
  64. send me code at ali_tariq302hotmail.com

    ReplyDelete
  65. Hiii Devi...
    Please send the code to my email id sachchit.bansal@gmail.com.
    I need it for my study. Please Help.

    ReplyDelete
  66. hi Devi, nice article and very detailed explanation. Would you mind sending full code to nazihhenie@gmail.com

    thanks in advance

    ReplyDelete
  67. hi devi. your article is really very useful for my research work. it make me easy to understand PSO.i need full source code for further study. could you please mail me full soure code to suchipatel258@gmail.com

    thank in advance

    ReplyDelete
  68. Please mail me the code to vaibhavr4@gmail.com.
    Thanks in advance

    ReplyDelete
  69. Hi, Im working on PSO and your article is really helpful to understand PSO. If I get the code it will be easier to understand. Could you please send me the code by email? Here is my email: kaihansen1001@gmail.com
    Thanks in advance

    ReplyDelete
  70. Hello mam i am trying to use PSO into svm so please give me code so i can use it id: komalsedani5@gmail.com

    ReplyDelete
  71. hi Devi, nice article and very detailed explanation. Would you mind sending full code to robotic301@gmail.com

    Thank in advance

    ReplyDelete
  72. hi Devi, nice article and very detailed explanation. Would you mind sending full code to robotic301@gmail.com

    Thank in advance

    ReplyDelete
  73. This comment has been removed by the author.

    ReplyDelete
  74. Madam,

    I am doing project on matrix optimization using PSO,i have gone through your article i understood some basic errors which i did with my project,if possible can you send your source code,it will be helpful for me at ananth.pm89@gmail.com

    Thanks in advance
    Ananth

    ReplyDelete
  75. can you mail me the full code
    mail id: bpavithra17@gmail.com

    ReplyDelete
  76. Hi, can you send me the full source code to nor.ashikin79@gmail.com. Thanks in advance.

    ReplyDelete
  77. Hi, can you send me the full source code to nor.ashikin79@gmail.com. Thanks in advance.

    ReplyDelete
  78. Hi, can you send me the full source code to nor.ashikin79@gmail.com. Thanks in advance.

    ReplyDelete
  79. Hi, can you send me the full source code to nor.ashikin79@gmail.com. Thanks in advance.

    ReplyDelete
  80. Hi, can you send me the full source code to nor.ashikin79@gmail.com. Thanks in advance.

    ReplyDelete
  81. Hi, can you send me the full source code to nor.ashikin79@gmail.com. Thanks in advance.

    ReplyDelete
  82. What is the use of Velocity Class ?
    It is not used in any calculation then why we need this ?

    ReplyDelete
  83. It is a good work. Kindly forward the complete code to my mail chimalab@gmail.com

    ReplyDelete
  84. Hello mam! I'm currently working on PSO! Your work is really great! If you dont mind can you able to send the full code to my mail ID? It s jmjmargretkanimozhi@gmail.com

    ReplyDelete
  85. Plz do mail me the code asap @ var.prateek@gmail.com
    Thanx in advance

    ReplyDelete
  86. Plz do mail me the code asap @ var.prateek@gmail.com
    Thanx in advance

    ReplyDelete
  87. Plz do mail me the code asap @ var.prateek@gmail.com
    Thanx in advance

    ReplyDelete
  88. can u plzzz send me the code on abhishek.gupta102223cse@gmail.com

    ReplyDelete
  89. Hi

    I hope you are doing well.

    I am working on a variant of PSO and I need the full working code that you have mentioned above.

    Kindly email me the full code on madnesh@gmail.com


    Thanks and Best Regards

    ReplyDelete
  90. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. I am working on a variant of PSO and I need the full working code that you have mentioned above on noonzh1@gmail.com

      Delete
  91. hi Devi
    can YOU SEND FULL SOURCE CODE TO
    noonzh1@gmail.com

    ReplyDelete
  92. hi
    I need full source code of pso
    my email noonzh1@gmail.com

    ReplyDelete
  93. pls i need the full code pls my mail is nouzmech@gmail.com

    ReplyDelete
  94. I am doing my project using PSO so Kindly email me the source full code plz at papu00170@gmail.com

    ReplyDelete
  95. Hi Devi, would you mind, please send full code to didisuruhan@gmail.com ?
    when i follow your code, the program can't run maybe i have some problem, but i can't fix it.

    Thank you.

    ReplyDelete
  96. Hey can I get the full code for a study? My mail id is rachellt.m@gmail.com
    Would be very useful. Thanks in advance

    ReplyDelete
  97. Hello,
    As part of comparative study of flocking based and pso I need pso code can you please share it in vikrant.udapurkar@gmail.com

    Thanks for your kind help !! :)

    ReplyDelete
  98. hi devi , kindly please could you send me the PSO code.

    Kind Regards

    ReplyDelete
  99. can I get the full code for a study? My mail id is 0228bulldog@gmail.com
    Thank you!

    ReplyDelete
  100. This comment has been removed by the author.

    ReplyDelete
  101. I need the Particle Swarm Optimization program code using scala. please send me the code to my id kaarthicknatarajan@gmail.com

    ReplyDelete
  102. Hi, could you send to my email, please?

    ReplyDelete
  103. Hello, I will do a similar project that optimizes using PSO, can you send me the source.here is my email: djwdjj.520@gmail.com. Thank you very much!

    ReplyDelete
  104. Hi, could you send to my email, please? eurismarpires@gmail.com

    ReplyDelete
  105. Hi, could you send to my email, please? hamidirifwan@gmail.com

    ReplyDelete
  106. hi I want to learn about pso ,,,
    can you send to me source code ,,,

    here my email : mkbx01@yahoo.com

    ReplyDelete
  107. This comment has been removed by the author.

    ReplyDelete
  108. Hi mam
    I'm a pg student doing a project in pso can you please send me the full code... Shir.keren@gmail.com
    Thank you in advance

    ReplyDelete
  109. Hi, could you send to my email, please? sametkeles@hotmail.com

    ReplyDelete
  110. Hello, please am a pg student and I will love to learn more about this. Kindly help me with your the full code. hizyyusuf@gmail.com

    ReplyDelete