pypsoa
A simple, zero-dependency Particle Swarm Optimization (PSO) library for Python.
pypsoa is a lightweight implementation of the Particle Swarm Optimization algorithm, designed for educational purposes and simple optimization tasks. It provides a clean, object-oriented interface with no external dependencies beyond Python's standard library.
Features
- Zero Dependencies: Only requires Python standard library
- Simple API: Easy-to-use classes for Vector, Particle, and Swarm
- Educational: Clear implementation perfect for learning PSO concepts
- Flexible: Customizable parameters for different optimization scenarios
- 2D Optimization: Optimized for 2-dimensional search spaces
Installation
pip install pypsoa
Or install from source:
git clone https://github.com/atasoglu/pypsoa.git
cd pypsoa
pip install .
Quick Start
import math
from pypsoa import Vector, Swarm
# Define a fitness function (minimize distance to target)
target = Vector(50, 50)
def fitness_function(pos):
return math.sqrt((pos.x - target.x)**2 + (pos.y - target.y)**2)
# Create a swarm with 50 particles
swarm = Swarm.from_bounds(
num_particles=50,
x_bounds=(0, 100),
y_bounds=(0, 100),
w=0.5, # inertia weight
c1=1.0, # cognitive coefficient
c2=2.0 # social coefficient
)
# Run optimization for 20 iterations
for _ in range(20):
swarm.step() # Update particle positions
swarm.eval(fitness_function) # Evaluate fitness
# Get best solution
best_position, best_fitness = swarm.g_best
print(f"Best position: {best_position}")
print(f"Best fitness: {best_fitness}")
See API Reference for more details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE file for details.
Metadata
Release files for pypsoa 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pypsoa-0.1.0.tar.gz | 4.9 kB | Without provenance | Details for pypsoa-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pypsoa-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for pypsoa-0.1.0-py3-none-any.whl |
Total release size: 10.1 kB
Release files / pypsoa-0.1.0.tar.gz
| Download URL | pypsoa-0.1.0.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0788cbd8fdbd4aca547be0f3119a572b3dfb1a4421e7f1cc67665d3addffb133
|
|
BLAKE2b-256 checksum How to use checksums |
2a6e85a55624073253dc42e412fef62b187e2eb0098f3d6db29a6f869b87acb6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.7
|
Release files / pypsoa-0.1.0-py3-none-any.whl
| Download URL | pypsoa-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
840cf3b7a73bd8f35b8ccbdc384e4ef665c791331ce28869f5f58c1f9fc41f19
|
|
BLAKE2b-256 checksum How to use checksums |
2cd85683d780662201be327888e4f5c18957031e8e6b7351f9e3da67128d925d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.7
|
Security for pypsoa 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.