Skip to main content

pswarm A clean, simplified implementation of the Particle Swarm Optimization algorithm for parameter optimization problems. Installation pip install pso-optimizer Features • Simple, well-documented implementation of PSO • Customizable inertia weight decay • Parameter-specific boundary handling • Built-in early stopping • Optimization history tracking • Utility functions for visualization and result saving Quick Start import numpy as np from pso_optimizer import PSOOptimizer, plot_convergence, save_results

Define objective function (example: minimize a simple quadratic function)

def objective_function(x): return -np.sum(x**2) # Negative because PSO maximizes by default

Define parameter bounds

param_min = np.array([-5.0, -5.0, -5.0]) param_max = np.array([5.0, 5.0, 5.0])

Create optimizer

optimizer = PSOOptimizer( objective_function=objective_function, param_min=param_min, param_max=param_max, swarm_size=30, max_iterations=100, maximize=False, # We're minimizing save_history=True )

Run optimization

best_params, best_fitness, history = optimizer.optimize()

Print results

print(f"Best parameters: {best_params}") print(f"Best fitness: {best_fitness}")

Plot convergence

plot_convergence(history, "convergence.png")

Save results

save_results(best_params, best_fitness, ['x', 'y', 'z'], "results.txt") Advanced Usage Special Boundary Handling You can specify special boundary handling for certain parameters:

Define parameter with wrapping boundary (like an angle)

special_boundaries = { 2: {'type': 'wrap'} # Parameter at index 2 will wrap around its bounds }

optimizer = PSOOptimizer( # ... other parameters ... special_boundary_handling=special_boundaries ) Loading Parameters from Configuration from pso_optimizer import load_parameter_bounds_from_config

Load parameter bounds from YAML config

param_min, param_max = load_parameter_bounds_from_config('config.yaml')

optimizer = PSOOptimizer( # ... other parameters ... param_min=param_min, param_max=param_max ) License This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for pswarm 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pswarm 0.1.1
File Size Uploaded Provenance Actions
pswarm-0.1.1.tar.gz 7.5 kB Without provenance Details for pswarm-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pswarm 0.1.1
File Interpreter ABI Platform Actions
pswarm-0.1.1-py3-none-any.whl Python 3 none any Details for pswarm-0.1.1-py3-none-any.whl

Total release size: 15.3 kB

Release files / pswarm-0.1.1.tar.gz

Download URL pswarm-0.1.1.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6a4bf8400a232052b63a3d6fd20b27ba25137343d9e77ce85198c81467becc87
BLAKE2b-256 checksum
How to use checksums
cde32fe5c06f3c15327208c130ae856f40a35d88460bf098d5de09a53230f05a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

Release files / pswarm-0.1.1-py3-none-any.whl

Download URL pswarm-0.1.1-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3e491816621de4fdf724bfaf728d59d9470206cb39e1a8b277a2c727c847c63b
BLAKE2b-256 checksum
How to use checksums
46ce4becceb8b810f341623fde5d04861ee89255a85b3ca88340a8140a6c1278
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

Security for pswarm 0.1.1

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page