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

species

v0.1.0

Published

Asynchronous genetic programming framework in Node

Downloads

8

Readme

Species

Asynchronous genetic programming framework for Node.

Species allows you to quickly run simple evolutionary computation problems by defining a set of delegate functions which describe the properties of your chromosomes and how they interact.

asciicast

Install

npm install species

Usage

First, you must define 5 async functions which describe how your Chromosomes interact. These functions are:

  • shouldStopSimulation - Tells species if/when the simulation should stop
  • createRandomChromosome - The seed function to create a random initial chromosome
  • crossoverChromosomes - Given 2 parent chromosomes, produce a new child chromosome (mating)
  • mutateChromosome - Given a chromosome, produce a new, mutated chromosome
  • getFitnessOfChromosome - Given a chromosome, calculate its fitness score

After these functions are defined, simply initialize and run a Species experiment:

var Species = require('species');

var chromosomeFunctions = {
  shouldStopSimulation: function(population, callback) { ... },
  createRandomChromosome: function(callback) { ... },
  crossoverChromosome: function(parent1, parent2, callback) { ... },
  mutateChromosome: function(chromosome, callback) { ... },
  shouldStopSimulation: function(population, callback) { ... }
};

// Create a new population
var population = new Species.Population({
  populationSize: 100
});

// Define experiment options
var experimentOptions = {
  mutationProbability: 0.1
};

// Create and run experiment
var experiment = new Species.Experiment(experimentOptions, population, chromosomeFunctions);

experiment.init()
  .then(experiment.run.bind(experiment))
  .then(function checkResults() {
    console.log(population.getFittestChromosome(), population.generation);
  });

For examples of sets of chromosome functions, please see the test folder or the species-examples pacakge (TODO).

Options

Aside from specifiying your chromosome functions, you can also tweak some other settings such as the probabilities of mutation occuring. These are the currently supported properties, their types, default values and descriptions:

mutationProbability: Number (0.1) - Chance of mutating each chromosome per generation,
crossoverProbability: Number (0.5) - Chance of breeding 2 chromosomes per generation (NOT IMPLEMENTED)

Likewise, you can set properties of the population:

populationSize: Number (100), - Number of chromosomes per population
cullPercentage: Number (10), - What percentage of low performers to kill each generation
minimizeFitness: Boolean (false) - Is lower fitness better?

To run a mimimizing experienment (where target fitness is 0, set minimizeFitness to true).

Discussion

Species provides the framework for running evolutionary computation problems. This means it is concerned only with the generational aspects of a simulation rather than any knowledge of the data. Many people re-invent these complex interactions for each experiment, leading to code that is bloated and not reusable. Species decouples the experimentation from the framework, allowing you to focus on the interactions between your chromosomes.

Each EA is slightly different. Species currently follows a method which calcuates fitnesses, culls low performers, fills population by breeding then mutates at random:

self.population.incrementGeneration();
return self.population.calculateFitness(fitnessFunc)
  .then(cull)
  .then(breed)
  .then(mutate)
  .then(runLoop);
});

The selection method for breeding is purely random, and each child which is created is instantly fed back into the pool for potential parents.

Development/Contributing

There is still a lot to do, but it works as a proof of concept. More probability flags are needed to tweak experiements, along with different selection methods for breeding.

There are also significant performance issues in the current implementation. However, a trivial string matching example is able to run at about 500 generations per second in a node environment (but significantly less in the browser) on my "Intel® Core™ i7-3517U CPU @ 1.90GHz × 4" which is not an especially powerful machine.

npm test

Please keep coverage at 100%