Particle Swarm Optimization in Python | Interactive PSO

Поделиться
HTML-код
  • Опубликовано: 15 янв 2025

Комментарии • 37

  • @menghuitan1628
    @menghuitan1628 Год назад

    Hi, I have 2 questions
    1.) How do you handle discrete variables(integer coordinates in the position) ?
    2.) How do you update the positions to satisfy the constraints if they exist?

  • @jeyachristy5334
    @jeyachristy5334 Год назад

    Can you tell why fitness values is suddenly increasing in case of feature optimization on the image in some case ? Madam

  • @harshanavada2908
    @harshanavada2908 3 года назад +1

    Hi, I am getting black screen while executing Draggable file.

    • @pyshine_official
      @pyshine_official  3 года назад +1

      Hi, is there any error or traceback appearing in the powershell window? Which version of Matplotlib is used?

    • @harshanavada2908
      @harshanavada2908 3 года назад

      @@pyshine_official I used cmd .No error.and also used latest version ....I am getting x axis ,and y axis coordinates but inside that I am not getting target point instead getting full black ...........

    • @pyshine_official
      @pyshine_official  3 года назад +1

      @@harshanavada2908 Alright, please use Python 3.6.5 and Matplotlib version 2.2.4, you can install it via pip3.6 install matplotlib==2.2.4

    • @pyshine_official
      @pyshine_official  3 года назад

      @الامبراطورية العلمية Please use Python 3.6.5 and Matplotlib 2.2.4

    • @showersville
      @showersville 3 года назад +7

      I had the same problem. Solved it by adding "ax1 = fig.add_subplot(111)" after the 6th line of the code and then I modified the 9th line to "ax = fig.add_subplot(111, sharex=ax1, sharey=ax1)". The black screen apparently has something to do with the new version of Matpotlib. I'm using Python 3.8.5 and Matplotlib 3.4.2

  • @gustavorizzoalbuquerque5834
    @gustavorizzoalbuquerque5834 4 года назад +1

    I'm so glad! thank you!
    Your little experiment gave me the base knowledge to go on, and try a lot of things I study in
    my
    engineering graduation.
    Could I try do a colab version of this code?

    • @pyshine_official
      @pyshine_official  4 года назад

      Hi you're welcome. Yes it would be nice to try on colab.

  • @themoonkiddo
    @themoonkiddo Год назад

    hi please help i'm getting the black screen and the target and particles dont move :(

  • @captainwhitebeard5326
    @captainwhitebeard5326 4 года назад +1

    Can we work together to improve this method?

    • @pyshine_official
      @pyshine_official  4 года назад +1

      We appreciate your concern and motivation to work on PSO research. AI algorithms always have a room of improvement. Please enlighten us about your suggestions

    • @captainwhitebeard5326
      @captainwhitebeard5326 4 года назад +1

      @@pyshine_official Done, thanks

  • @priyankajoshi3855
    @priyankajoshi3855 3 года назад

    Can we use this for solving travelling salesman problem?

    • @pyshine_official
      @pyshine_official  3 года назад

      Hi, yes PSO is effective for solving TSP. Try github.com/marcoscastro/tsp_pso/blob/master/tsp_pso.py

  • @mutiuadegboye3827
    @mutiuadegboye3827 4 года назад

    I tried it on my computer. Its showing this error: FileNotFoundError: [Errno 2] No such file or directory: 'target.csv'

    • @pyshine_official
      @pyshine_official  4 года назад +1

      Hi, this file will be generated by the draggable.py. Please run it alone to check if is generating the file?

  • @vigneshwarrajraj3150
    @vigneshwarrajraj3150 3 года назад

    can i use latitude and longitude points and find out the least distant path with this code?

    • @pyshine_official
      @pyshine_official  3 года назад +1

      Yes you can keep it floating point

    • @vigneshwarrajraj3150
      @vigneshwarrajraj3150 3 года назад

      @@pyshine_official okay so i just have to input the latitude and longitudes with data type as floats? thanks a lot, a lot!!!

    • @pyshine_official
      @pyshine_official  3 года назад

      @@vigneshwarrajraj3150 Exactly, also note that the bounding region in lat long case will be in their standard max limits according to your requirements

  • @basharhamid2847
    @basharhamid2847 4 года назад

    I have this error when running
    File "/home/pradeepkumar/Desktop/PSO2020/Draggable.py", line 51
    print(str(self.point.center[0])+','+str( self.point.center[1]),file = open('target.csv','w'))
    ^
    SyntaxError: invalid syntax

    • @pyshine_official
      @pyshine_official  4 года назад +1

      Hi, Please tell me which Python version you are using? The code runs well under Python 3.6.5

  • @tareqbinahammed4047
    @tareqbinahammed4047 4 года назад

    hi !!
    How can I add more target in the draggable.py file?
    Could you share the code snippet?

    • @pyshine_official
      @pyshine_official  4 года назад +2

      Yes, in the list of circles you can add more targets as follows:
      circles = [patches.Circle( (10, -10), 20, label='Click to drag the Target', fc = 'k',color = 'k', alpha=1),patches.Circle( (10, -50), 20, label='Click to drag the Target', fc = 'r',color = 'r', alpha=1)]

    • @tareqbinahammed4047
      @tareqbinahammed4047 4 года назад +1

      @@pyshine_official Thanks a lot. I am very much helpful.
      Thanks again

    • @dibyasanjanasahu738
      @dibyasanjanasahu738 4 года назад

      Hi... actually am doing literature review in this PSO can you help me pl. Am in very primitive stage.

    • @pyshine_official
      @pyshine_official  4 года назад

      @@dibyasanjanasahu738 Hello! You can use the tutorial here pyshine.com/Make-an-Interactive-Particle-Swarm-Optimization-algorithm/
      As a startup, try changing the local and global values and then proceed to change the cost function, the number of dimensions in it. Generate the csv file that will give the plot of cost function using the method in here for real time plot pyshine.com/How-to-plot-real-time-frame-rate-in-opencv-and-matplotlib/
      Additonal readings: www.mdpi.com/2227-9717/7/10/733

  • @gauravverma365
    @gauravverma365 4 года назад

    Hi...
    I am here to know that does PSO facilitate the predicting equation as well?

    • @pyshine_official
      @pyshine_official  4 года назад

      Hi ! PSO is good at maximizing or minimizing the cost function, which is itself an equation. For example if its a distance equation, then of course minimum value of distance is 0, which PSO tend to find. In real life problems the PSO can be applied by modeling an equation of the problem and the use it as a cost function. Now if by predicting equation your meaning is curve fitting based on the dataset, then the search dimensions of PSO will increase. Because in that case PSO will be applied to find the values of the possible cofficients of the polynomial equation. In that case yes PSO can be applied, however also consider narrow down the problem by using Deep neural networks in combination with PSO.

    • @gauravverma365
      @gauravverma365 4 года назад

      Do you mean that we need to give an equation with some input variables (I think these variables are called particles?) then PSO identifies which input has to remove from the equation and providing the best solution?
      OR
      You mean to say that we only provide the input variables as per their varying parameters, and PSO develops the prediction equation?
      OR
      Does PSO facilitate both of the above statements?

    • @pyshine_official
      @pyshine_official  4 года назад

      @@gauravverma365 Yes the second one, for example to find the solution for func(x) = x1^2 + x2^2+x3^2, the particle can be set as (x1, x2, x3), and fitness function is func(x). After that we can use the standard procedure to find the optimum. Its about minimizing the loss or difference between a guess and current true value. Each particle has a random guess as a part in its current velocity. Once the guess is under a satisfaction creteria; either max number of iterations reached or error below a given threshold, the search process is complete. So yes its about giving the parameters.

    • @gauravverma365
      @gauravverma365 4 года назад

      @@pyshine_official thanks for the brief information 👍

    • @pyshine_official
      @pyshine_official  4 года назад

      @@gauravverma365 You’re welcome.