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

jsga-feklee

v1.1.1

Published

A genetic algorithm implementation written in JavaScript.

Downloads

3

Readme

JSGA

JavaScript Genetic Algorithm

JSGA is an ES6 genetic algorithm library.

Installation

  • Bower: bower install jsga-feklee

  • Yarn: yarn add jsga-feklee

Or you can download jsga.js from the GitHub repo.

Usage

JSGA operates on chromosomes --- lists of numbers. It generates successive generations of chromosomes by mixing the chromosomes of randomly selected parents, and by randomly mutating chromosomes. It evaluates each individual by using a user-provided fitness function. Only the fittest individuals from each generation are carried over to the next.

Start by creating a JSGA object:

let algorithm = JSGA({
    length: 10,
    radix: 10,
    fitness: function(individual) {
        return individual.reduce((p, c) => p + c); // the fitness is the sum of all the values
    },
    size: 100,
    children: 4,
    mutationRate: 0.05,
    crossovers: 1
});

Notes on the parameters:

  • length is the length of the chromosome.
  • radix is the 'base' used to encode the data. Each number in the chromosome will have a range from 0 to radix.
  • fitness is the fitness function used to evaluate individuals. It is passed a chromosome (array of numbers) and expects a number to be returned. JSGA will try to maximize the fitness function.
  • size is the number of individuals in the population. This must be an even number.
  • seed is used to fill the first individuals of the initial population. The remaining individuals are random.
  • children is the number of offsping each pair of parents will produce. The default is 4.
  • mutationRate is the rate of random mutations, in mutations/number. That is, for the default mutation rate of 0.05, around one in every twenty numbers in each chromosome will be randomly mutated.
  • crossovers is the number of times to randomly cross over the parents chromosomes. This is the primary source of variation. The default is 1.

To run the algorithm, simply call the run method with the number of generations to run the algorithm. Pass -1 to make the algorithm run forever. run is a generator which yields an object containing information about the current generation.

for (let generation of algorithm.run(50)) {
    console.log(`Generation ${generation.generation}`);
    console.log(`Array of individuals: ${generation.population}`);
    console.log(`Best individual: ${generation.best.params}`);
    console.log(`Best individual's fitness: ${generation.best.fitness}`);
}