torch_pso

Particle Swarm Optimization implemented using PyTorch Optimizer API

https://github.com/qthequartermasterman/torch_pso

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 4 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.4%) to scientific vocabulary
Last synced: 6 months ago · JSON representation ·

Repository

Particle Swarm Optimization implemented using PyTorch Optimizer API

Basic Info
  • Host: GitHub
  • Owner: qthequartermasterman
  • License: mit
  • Language: Python
  • Default Branch: master
  • Size: 113 KB
Statistics
  • Stars: 17
  • Watchers: 2
  • Forks: 1
  • Open Issues: 10
  • Releases: 6
Created over 3 years ago · Last pushed over 3 years ago
Metadata Files
Readme License Citation

README.md

Torch PSO

DOI

Particle Swarm Optimization is an optimization technique that iteratively attempts to improve a list of candidate solutions. Each candidate solution is called a "particle", and collectively they are called a "swarm". In each step of the optimization, each particle moves in a random directly while simultaneously being pulled towards the other particles in the swarm. A simple introduction to the algorithm can be found on its Wikipedia article.

This package implements the Particle Swarm Optimization using the PyTorch Optimizer API, making it compatible with most pre-existing Torch training loops.

Installation

To install Torch PSO using PyPI, run the following command:

$ pip install torch-pso

Getting Started

To use the ParticleSwarmOptimizer, simply import it, and use it as with any other PyTorch Optimizer. Hyperparameters of the optimizer can also be specified. In practice, most PyTorch tutorials could be used to create a use-case, simply substituting the ParticleSwarmOptimizer for any other optimizer. A simplified use-case can be seen below, which trains a simple neural network to match its output to a target.

```python import torch from torch.nn import Sequential, Linear, MSELoss from torch_pso import ParticleSwarmOptimizer

net = Sequential(Linear(10,100), Linear(100,100), Linear(100,10)) optim = ParticleSwarmOptimizer(net.parameters(), inertialweight=0.5, numparticles=100, maxparamvalue=1, minparamvalue=-1) criterion = MSELoss() target = torch.rand((10,)).round()

x = torch.rand((10,)) for _ in range(100):

def closure():
    # Clear any grads from before the optimization step, since we will be changing the parameters
    optim.zero_grad()  
    return criterion(net(x), target)

optim.step(closure)
print('Prediciton', net(x))
print('Target    ', target)

```

Citation

To cite this work in a paper use the following citation: bibtex @software{Sansom_Torch_PSO_2022, author = {Sansom, Andrew P.}, doi = {10.5281/zenodo.6982304}, month = {8}, title = {{Torch PSO}}, url = {https://github.com/qthequartermasterman/torch_pso}, year = {2022} }

Owner

  • Name: Andrew Sansom
  • Login: qthequartermasterman
  • Kind: user
  • Company: Protopia AI

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Sansom"
  given-names: "Andrew P."
  orcid: "https://orcid.org/0000-0002-2276-7224"
title: "Torch PSO"
doi: 10.5281/zenodo.6982304
date-released: 2022-08-10
url: "https://github.com/qthequartermasterman/torch_pso"

GitHub Events

Total
  • Watch event: 2
Last Year
  • Watch event: 2

Issues and Pull Requests

Last synced: 8 months ago

All Time
  • Total issues: 21
  • Total pull requests: 11
  • Average time to close issues: 9 days
  • Average time to close pull requests: 16 minutes
  • Total issue authors: 2
  • Total pull request authors: 1
  • Average comments per issue: 0.95
  • Average comments per pull request: 0.18
  • Merged pull requests: 9
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • qthequartermasterman (10)
  • Simply-Adi (2)
Pull Request Authors
  • qthequartermasterman (9)
Top Labels
Issue Labels
enhancement (7) documentation (2) good first issue (1) wontfix (1) question (1) testing (1)
Pull Request Labels

Dependencies

requirements.txt pypi
  • torch *
.github/workflows/python-package.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v3 composite
.github/workflows/python-publish.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v3 composite
  • pypa/gh-action-pypi-publish 27b31702a0e7fc50959f5ad993c78deac1bdfc29 composite