license: mit
language:
- en
tags:
- Distriuted application
- Swarm Visualization
- Particle Swarm Optimization
- Swarm Intelligence
- Swarm
Introduction
The Particle Swarm Optimization (PSO) algorithm is an approximation algorithm that finds the best solution from all the explored feasible solutions for any problem that can be formulated into a mathematical equation. In the field of algorithms and theoretical computer science, optimization problems are known by the name "approximation" algorithms. In this project, we built a web application that hosts a PSO algorithm with interactive features such that any person trying to solve a problem with PSO can leverage our distributed application with Ray to solve it.
Description
A web application for visualizing the Particle Swarm Optimization algorithm is implemented with Ray for scalability in this project. The computing process sent to Ray worker nodes has effectively progressed. In our experimental analysis, the system architecture has met all desired distributed challenges. Similarly, the effectiveness of swarm intelligence behavior is now simple to understand with this application. For future research, we would like to adapt this framework to other optimization problems and evaluate their performance. Also, enable users to input their mathematical function in the dashboard for particles to swarm and give an error plot of their function with PSO.
- Developed by: Karthik Reddy Kanjula, Sai Meghana Kolla
- School: School of Computing and Information, West Chester University of Pennsylvania; School of Mathematics and Computer Science, Pennsylvania State University
- Email:
- Karthik Reddy Kanjula: [email protected]
- Sai Meghana Kolla: [email protected]
- Model type: Distributed Application
- License: MIT
Sources
- Repository: https://huggingface.co/kkr5155/DistributedSwarmIntelligence
- Paper : https://arxiv.org/abs/2301.13276
- Demo : https://huggingface.co/spaces/kkr5155/DistributedSwarmIntelligence
Uses
📈 Visualization:
- ✨ Use the
start_hunting_button
to start finding the target for plot 2. - ✨ Use the
start_finding_button
to start computation for plot 1. - ✨
update_num_particles_button
updates the number of particles.
- ✨ Use the
🎯 Target Visualization:
- ✨ Click on the plot to set a new target for the swarm.
📊 Table:
- ✨ Displays the continuous global best position of the swarm for plot 1.
⚙️ Settings:
- ✨ Use the slider to adjust the number of particles.
- ✨ Select a mathematical function from the dropdown list.
How to Get Started with the Application:
Building and Running the Docker Image
Build the Docker Image:
- Ensure you have Docker installed on your system.
- Navigate to the directory containing the Dockerfile and your project files.
- Build the Docker image by running the following command:
Replacedocker build -t my-app .
my-app
with a desired name for your Docker image.
Run the Docker Container:
- After the Docker image is built, you can run the container with the following command:
This command maps the host's port 8000 to the container's port 8000, allowing you to access the web application from your local machine atdocker run -p 8000:8000 my-app
http://localhost:8000
.
- After the Docker image is built, you can run the container with the following command:
Connect Worker Nodes (Optional):
- If you want to connect worker nodes to the head node, you can start additional containers and connect them to the head node.
- Open a new terminal window for each worker node you want to connect.
- Run the following command to start a new container and connect it as a worker node:
Replacedocker run -it --network=host my-app ray start --node-ip-address=<head-node-ip>:6379 --redis-password=<password>
<head-node-ip>
with the IP address of the head node container, and<password>
with the desired Redis password.
Access the Web Application:
- Once the container is running, you can access the web application by opening your web browser and navigating to
http://localhost:8000
.
- Once the container is running, you can access the web application by opening your web browser and navigating to
Access the Ray Dashboard (Optional):
- To access the Ray dashboard, open your web browser and navigate to
http://127.0.0.1:8265
. - In the experimental dashboard, click on "Alive" on the left side, then click on "Raylet".
- Scroll down and note the value of the
--gcs-address
flag, which will include a port number.
- To access the Ray dashboard, open your web browser and navigate to
Stop and Remove the Container:
- To stop and remove the running container, use the following command:
Replacedocker stop <container-id> docker rm <container-id>
<container-id>
with the ID of the running container.
- To stop and remove the running container, use the following command:
Algorithm
Particle Swarm Optimization algorithm is implemented using the Python programming language. In Algorithm 1 below, the pseudocode for the PSO algorithm is written. In the algorithm, we first declare the swarm using Particle class which has the following properties:
- pBest: Best position of the particle where the particle is fittest.
- particlePosition: Particle present position.
- particleError: Particle present error determined by the fitness function.
p = Particle();
swarm = [p] _numberOfParticles;
while Error approximates to minimum possible value do
for p in swarm do
fp = fitness(particlePosition);
if fp is better than fitness(pBest) then
pBest = p
particleError = fp
end
end
gBest = best particlePosition in swarm;
gError = best particleError in swarm;
for particle in swarm do
v = v + c1_rand*(pBest - particlePosition) + c2*rand*(gBest - particlePosition);
end
end
Motivation
The wide-range availability of models based on neural networks and machine learning algorithms explain future of AI development in today’s technology-driven environment. Swarm Intelligence is a branch of AI which is adapted from the nature to solve the problems faced by humans. Swarm Intelligence (S.I.) was first proposed in 1989 by Gerardo Beni and Jing Wang, as the name implies S.I. is collective intelligence. To explain, consider a flock of birds that travel together, every individual bird can make a decision and all the birds in a flock communicate and come up with a decision to migrate to a particular place in a particular pattern depending upon the season. There are many such examples in our ecosystem that represent Swarm Intelligence like ant colonies, bee colonies, and schools of fish. The basic idea is to bring in a set of agents or particles which have an intelligence of their own and these intelligent systems communicate with each other and reach a common and near-optimal solution for a given problem [1]. As mentioned above, the flock of birds inspired developers to develop Particle Swarm Optimization algorithm. In this algorithm, we will have a certain number of particles that will be working together by communicating continuously to achieve a common goal. The applications of PSO in the real world are limitless [2]. In the next generation of AI applications, the algorithm behavior is understandable to the end-user when interacting. These interactive applications create new and complex problems like high processing and adaptability. With Ray, a distributed computing framework, new and complex system requirements such as performance and scalability can be addressed. Ray provides a unified interface for expressing task-parallel computation, which is powered by a single dynamic execution engine [3]. The framework we suggested for this project helps in solving problems such as energy storage optimization, NP-hard problems, and others. Any such optimization problem that forms a mathematical equation is solvable by reducing to this algorithm, using our framework makes it a scalable, distributed Python application. The main motivation of our project is to introduce people to what swarm intelligence is and how it can be achieved through PSO by providing them with a visualization of how the algorithm works.
Citation
[1] Gupta, Sahil. Introduction to swarm intelligence. GeeksforGeeks, (2021, May 15). Retrieved March 5, 2022, from https://www.geeksforgeeks.org/introduction-to-swarm-intelligence/.
[2] Kennedy, J.; Eberhart, R. Particle swarm optimization. Proceedings of ICNN’95 - International Conference on Neural Networks (1995), 4(0), 1942−1948, doi:10.1109/icnn.1995.488968.
[3] Moritz, Philipp, et al. Ray: A Distributed Framework for Emerging AI Applications. ArXiv.org, ArXiv, 16 Dec 2017, arXiv:1712.05889v2.
[4] Lindfield, G.; Penny, J. Particle swarm optimization algorithms. Introduction to Nature-Inspired Optimization, 18 August 2017, Retrieved from https://www.sciencedirect.com/science/article/pii/B9780128036365000037.
[5] Rudiger, P. Panel: A high-level app and dashboarding solution for the PyData ecosystem. Medium, (2019, June 3)., https://medium.com/@philipp.jfr/panel-announcement-2107c2b15f52.
[6] Shirako, J., Hayashi, A., Paul, S. R., Tumanov, A., & Sarkar, V. Automatic parallelization of python programs for distributed heterogeneous computing. arXiv.org, arXiv, 11 March 2022, from https://doi.org/10.48550/arXiv.2203.06233.
[7] Philipp Moritz and Robert Nishihara and Stephanie Wang and Alexey Tumanov and Richard Liaw and Eric Liang and Melih Elibol and Zongheng Yang and William Paul and Michael I. Jordan and Ion Stoica Ray: A Distributed Framework for Emerging AI Applications. inproceedings of 13th USENIX Symposium on Operating Systems Design and Implementation (OSDI 18), October 2018, isbn 978-1-939133-08-3, Carlsbad, CA, pages 561–577, USENIX Association.
[8] Slovik, Adam. Swarm Intelligence Algorithms: A Tutorial. 1st ed., CRC PRESS, 2020.
[9] Rooy, N. (n.d.). Particle swarm optimization from scratch with python. nathanrooy.github.io. Retrieved from https://nathanrooy.github.io/posts/2016-08-17/simple-particle-swarm-optimization-with-python/