Giter Site home page Giter Site logo

acupy / genetic-algorithm-es6 Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 1.0 10 KB

๐Ÿ”ฌ This package provides a framework for building applications where genetic algorithm (GA) is used for solving optimization problems based on a natural selection process that mimics biological evolution. The algorithm repeatedly modifies a population of individual solutions.

Home Page: https://www.npmjs.com/package/genetic-algorithm-fw

License: MIT License

JavaScript 100.00%
genetic-algorithm population ai framework es6

genetic-algorithm-es6's Introduction

Genetic algorithm framework built with JavaScript ES6

Build Status

NPM

This package provides a framework for building applications where genetic algorithms (GA) are used for solving optimization problems based on a natural selection process that mimics biological evolution.

The algorithm repeatedly modifies a population of individual solutions.

Installation

npm install genetic-algorithm-fw

Functions to define

mutation

function mutation(oldPhenotype){
  // return a new phenotype
}

crossover

function crossover (phenoTypeA, phenoTypeB) {
    // using phenoTypeA and phenotypeB create a new list of two phenoTypes
    // return [phenotype1, phenotype2]
}

fitness

function fitness(phenotype) {
  // return the fitness number
  // the higher the value the fitter it is
}

competition

function competition(phenoTypeA, phenoTypeB) {
    // return true when the fitness value is higher for phenoTypeA
    // otherwise return false
}

Initialize GA object with the previously defined functions

var GeneticAlgorithm = require('genetic-algorithm-fw');

var geneticalgorithm = new GeneticAlgorithm(
  mutation, // if not specified, no mutation happens
  crossover, // if not specified, the initial phenoTypes are returned
  fitness, // if not specified, 0 is returned
  competition, // if not specified, no competition happens
  [], // initial list of phenoTypes
  populationSize, // by defualt it is 100
  chanceOfMutation); // by defautlt it is 50

Evolve our population

// we can run as many iterations as we like
geneticalgorithm.evolve();

Get the best result

// we can check the best phenotype in our current population
var theBestPhenotype = geneticalgorithm.best();

genetic-algorithm-es6's People

Contributors

acupy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

nitin42

genetic-algorithm-es6's Issues

Add more selection strategies

Extend the framework with more selection strategies:

  • Tournament selection (default and currently used)
  • Fitness proportionate selection
  • Stochastic universal sampling
  • Reward-based selection

More about the selection operator: here

Writing tests

Testing the whole framework with common use cases.

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.