Coder Social home page Coder Social logo

kalmyk / fox-ga Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 33 KB

fox-ga is implementation of distributed Genetic Algorithm based on message queue paradigm

License: MIT License

JavaScript 100.00%
genetic-programming queue-algorithm async genetic-algorithm genetic-engine

fox-ga's Introduction

fox-ga is implementation of parallel and distributed Genetic Algorithm based on message queue paradigm

The goal of the project is to provide ability to run time consuming fitness function of genetic algorithm simultaneously on distributed environment.

Any standard MQTT broker could be used as shared genome storage. Mosquitto & FOX-WAMP were tested.

benefits:

  • external storage is used to save population
  • ability to have as many workers to compute fitness as hosts available
  • ability to restart worker with no affect to calculation process
  • ability to calculate simultaneously fitnesses of batch of genomes
  • engine module does not limit computation process by time

install:

npm i git+https://github.com/kalmyk/fox-ga.git

usage:

Here is demo evaluation function in './demo-bin/run-mqtt.js'. The demo evaluation function use timer to show long computation time of fitness evaluation function.

create engine

const ge = new GeneticEngine({
  populationSize: <population-size>,
  seed: function () {
    ...
    return { id:<genome-identifier>, genome: <any-structure> }
  },
  mutate: function (genome) {
    ...
    return { id:<genome-identifier>, genome: <any-structure> }
  },
  crossover: function (genome, partner) {
    ...
    return { id:<genome-identifier>, genome: <any-structure> }
  }
})

! Good idea to have "genome-identifier" equal to sha1(JSON.stringify(genome)), this id must be unique for the whole cluster

connect to queue storage

  await ge.bindStorage(new BindMqtt(client, <path-to-population-store>))

get genome for fitness evaluation

  const { id, genome } = ge.getGenome()

where:

  • id: genome-identifier
  • genome: genome that is obtained from seed/mutate/crossover

apply genome fitness to population

ge.rate(id, fitness)

where:

  • id: genome-identifier obtained from getGenome function
  • fitness: Result of Genetic Fitness function

calculation loop

The calculation loop need to have free time to load events from remote storage. Usually it is enough to start next iteration by setImmediate function.

const computeStep = function () {
  const { id, genome } = ge.getGenome()
  const fitness = myEvaluationFunc(genome)
  ge.rate(id, fitness)
  if (isGood(fitness)) {
    console.log('best fitness found', id, fitness)
    return
  }
  setImmediate(computeStep)
}

client.on('connect', async () => {
  await ge.bindStorage(new BindMqtt(client, 'demo/ga'))
  setImmediate(computeStep)
})

termination function

There is no termination function. The calculation loop and it exit condition is implemented in a custom code.

island grouping variation

dedicated communication thread

Get current population state:

$ mosquitto_sub --retained-only -t '<path-to-population-store>/population/#' -v

fox-ga's People

Contributors

kalmyk avatar

Stargazers

 avatar

Watchers

 avatar  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.