npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

particle-swarm

v1.0.7

Published

Fully informed particle swarm optimization library

Downloads

22

Readme

Particle-swarm.js

Particle-swarm.js is JavaScript implementation of a fully-informed particle swarm optimization algorithm. Image

Installing

With npm:

npm install --save particle-swarm

With yarn:

yarn add particle-swarm

Basic usage (with default parameters)

var createOptimizer = require('particle-swarm').default;

var optimizer = createOptimizer({
    maxVelocity:[4.05],
    minVelocity: [-4.05],
    maxPosition: [10.],
    minPosition: [-10.],
    populationSize: 30,
    numberOfDimensions: 1,
    maxIterations: 50,
    fitnessFunction: (x) => x*x,
});

var solution = optimizer.start();

Complex usage (with all parameters)

import createOptimizer from 'particle-swarm';

const optimizer = createOptimizer({
    useConstrictionFactor: true,
    maxVelocity:[4.05],
    minVelocity: [-4.05],
    maxPosition: [10.],
    minPosition: [-10.],
    populationSize: 30,
    numberOfDimensions: 1,
    maxIterations: 50,
    desiredFitness: 0,
    desiredPrecision: 1E-5,
    fitnessFunction: (x) => x*x,
    socialFactor: (iteration) => 2.05,
    individualFactor: (iteration) => 2.05,
    inertiaFactor: (iteration) => 1.,
    callbackFn: (meta) => console.log(meta.globalBestFitness),
});

const solution = optimizer.start();

Parameters

Required parameters

  • maxVelocity - max velocity of particle for each dimension
  • minVelocity - min velocity of particle for each dimension
  • maxPosition - max position of particle for each dimension
  • maxPosition - min position of particle for each dimension
  • populationSize - size of population, must be greater than zero
  • numberOfDimensions - number of dimensions, must be greater than zero
  • maxIterations - max number of iterations, must be greater than zero
  • fitnessFunction - function that evaluates each particle, algorithm is searching for position that gives smallest value of this function

Optional parameters

  • useConstrictionFactor - constriction factor prevents divergence of algorithm, false by default
  • randomFunction - function that returns random number from interval [0, 1], Math.random by default
  • desiredFitness - desired fitness algorithm should achieve, 0 by default
  • desiredPrecision - desired precision when comparing desired fitness and global best fitness, 1E-5 by default
  • socialFactor - function that calculates social factor for each iteration, 2.05 by default
  • individualFactor - function that calculates individual factor for each iteration, 2.05 by default
  • inertiaFactor - function that calculates individual factor for each iteration, 1 by default
  • callbackFn - function that is called after each iteration, can be used as a observer

Tips

  • Parameters maxVelocity, minVelocity, maxPosition and maxPosition must be arrays of length numberOfDimensions
  • Parameters socialFactor and individualFactor should return value of 2.05
  • Parameter inertiaFactor should have value of 1 in first iteration and decline in each iteration
  • Set useConstrictionFactor to true if you want to prevent divergence of algorithm
  • Velocity should be between 10 and 20 percent of space that is searched (e.g. searched space: [-10, 10], velocity: [-4,4])

Note: Please see finding global minimum of Rastring function example in demo file.

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details