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

evo-js

v0.2.5

Published

Evolutionary Algorithm Tool wrapped with ANN

Downloads

37

Readme

evoJS

evoJS is a genetic and evolutionary algorithm tool, making it easy to incorporate evolutionary algorithms in your JavaScript.

Installation

To install run npm install evo-js.

To run on a browser, include evo.min.js in your scripts.

Basic Usage

The tool is used through a population object. Here is a simple example

    // Instantiate a population object
    var population = evo.population();

    var evaluateGenes = function (genes) {
      /* Use genes to return a score */
    }

    // Define a method to evaluate genes and return the fitness
    // 'genes' is an array of floats
    population.on('run', function(genes){
        return evaluateGenes(genes); // Supply this method to evaluate the genes
    });

    // Run with a stopping criteria
    population.run({generations: 10});

    // Get the best genes
    var result = population.bestGenes();

Pool Configuration

As an argument to evo.population a configuration object can be passed to override the defaults. Here are the defaults.

    var config = {
        genes: 200, // Number of genes for each member
        size: 100, //  Number of members in the gene population
        cross_rate: 0.05, // The frequency of gene "twists" in two parents genes
        mutate_rate: 0.05, // The frequency of mutations in a parent gene
        mutate_amount: 1.0, // The amount a mutated gene can deviate

        // Each generation is made from a mix of different breeding strategies
        // Ratios defines the ratio of each in the next generation
        ratios: {
            top:    0.25,    // Survivors from last generation
            mutate: 0.25,    // Created by randomly altering genes
            cross:  0.25,    // Created from crossing parents
            random: 0.10,    // Random survivors from last generation
            average:0.05,    // Created by averaging parents together
            fresh:  0.10     // new, totally random gene sets
        }
    });

    var population = evo.population(config);

Stopping conditions

As an argument to population.run a configuration object can be passed to defined the stopping conditions

    var config = {
        iterations: 1000, // How many times run will be called
        generations: 100, // How many generations will be run
        score: 10.0,      // Minimum score to be reached (higher score is better)
        // A while function can be supplied
        // when false is returned sim stops
        while: function(){
            return true;
        }

        // If true, a method will be attempted to stop when the score
        // stops changing across generations
        auto_run: false
    });

    population.run(config);

'Manual' simulations

While population provides the run method to run simulations, the gene population can be accessed manually for custom simulations.

    population = evo.population()

    while(population.generation < 100) {
        // Grab next genes
        var genes = population.nextGenes();

        //Evaluate genes
        var score = evaluateGenes(genes);

        //Report genes back to population
        population.report(genes, score);
    }

When the gene population is empty, a new generation will be created.

Member construction

You may provide a member constructor to automate gene evaluation, and use a more object oriented approach

    population = evo.population()

    // Supply a 'constructor' to use the genes
    population.on('member', function(genes){
        var member = {
            height: genes[0],
            width: genes[1]
        };
        return member;
    });

    // Run will now give your constructed member instead of a gene list
    population.on('run', function(member){
        return member.height + member.width;
    });