GithubHelp home page GithubHelp logo

muliyul / microverse Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 0.0 42 KB

A tiny library for quickly prototyping genetic algorithms.

JavaScript 100.00%
javascript genetic-algorithm genetic-programming nodejs

microverse's Introduction

microverse

microverse is a tiny library for quickly prototyping genetic algorithms. currently only compatible with node.

Install

npm i -S microverse

Breaking Changes (v1.1.0):
  • Chromosomes are now instances of Array.
Usage (TL;DR):
    let {Algorithm, Operators} = require('microverse');
    let {Crossovers, Selectors} = Operators;
    
    let population = [];
    
    //Generate a random population somehow
    for (let i = 0; i < 5; i++) {
        let chromosome = [...];
        population.push(chromosome);
    }
    
    let opts = {...};
    let alg = new Algorithm(opts);
    
    //Subscribe to events
    alg.on('evaluation', info => {...});
    alg.on('selection', info => {...});
    alg.on('crossover', info => {...});
    alg.on('generation', info => {...});
    alg.on('end', info => {...});
    
    //Run the algorithm indefinitely or until the criteria has met
    alg.run().then(info => {...});
    
    //Run the algorithm for 100 iterations or until the criteria has met
    alg.run(100).then(info => {...});
    
    //Pipe the progress (will stream json string 'generation' events)
    alg.pipe(process.stdout); 
Options:
  • lazyEval: Boolean (optional, default: false) - will evaluate each solution only once.
  • population: Array (required) - an array of chromosomes.
  • crossover: function (parents, done) (required) - errback accepts the offspring created.
  • selector: function (population, done) (required) - errback accepts the selected parents from the population created.
  • mutator: function (chromosome, done) (optional, default: (chromosome, done) => done()). errback accepts the mutated chromosome (falsely for unchanged).
  • fitnessFn: function (chromosome, done) (required) - errback accepts the fitness value for this chromosome. Lowest fitness -Infinity, highest fitness Infinity. To reverse this effect (in case of Error measurements like RMS) just prepend the negative sign done(null, -fitness)
  • stopCriteria: function (leader, population) (optional, default: (leader, population) => false) - A synchronous stop criteria to evaluate for each generation (truthy or falsely).
  • steadyState: (optional, default: false) - will determine if the algorithm should use the steady-state concept.

Factories:

    let {Crossovers, Selectors} = require('microverse').Operators;
    let {SinglePoint, DoublePoint, Uniform, Arithmetic} = Crossovers;
    let {Elitism, Roulette, Rank} = Selectors;
    
    //Returns a selector function that selects 
    //2 parents based on the Roulette Wheel algorithm.
    let rws = Roulette(2);
    
    //Returns a crossover function that spreads
    //parents traits evenly across a new offspring
    let uxo = Uniform;

Note: Read more about crossovers and selectors.

TODO

  • Stream / Generator support as population output.
  • Add more crossover functions (Single Point, Double Point, Arithmetic).
  • Add more selector functions (Roulette Wheel, Rank, Steady-State).
  • Proper object stream output.
  • Add genetic programming example.
  • Make it available to browsers.
  • Benchmarks.

Development

Install dependencies: npm i

Run tests: npm test

microverse's People

Contributors

muliyul avatar de314 avatar

Stargazers

 avatar  avatar monz avatar  avatar Tako Seijin avatar Rafał Lindemann avatar Victor Andritoiu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.