GithubHelp home page GithubHelp logo

micro_ga's Introduction

Micro Microbial Genetic Algorithm (MMGA)

A Microbial Genetic Algorithm written in minimal number of Ruby lines

Usage

ga = MGA.new(:generations => 1000, :gene_length => 20, :fitness => Proc.new{|genome|
  #puts fitness evaluation logic here. should return numerical value.
  #ie; simple max-ones fitness (or largest sum with mutation_type => :decimal)
  puts(genome.inspect)
  genome.inject{|i,j| i+j}
})

ga.evolve

Once run the resultant population can be accessed with

ga.population

Args can be passed as a hash. The following shows valid keys for args and their default values if not given;

:popsize => 30,
:gene_length => 10,
:cross_over_rate => 0.7,
:mutation_rate => 0.1,
:mutation_type => :decimal, #can also be :binary.  decimal mutates with small +/- value, binary flips 0->1, 1->0
:generations => 400,
:fitness =>  Proc.new{|genome| genome.inject{|i,j| i+j} }

Microbial Design

Microbial GAs are a slight twist on a typical GAs. Instead of creating a new genome via recombination of two other genomes, the microbial idea is to insert and overwrite some genes of a weaker member with genes from a fitter one. The idea is based on viral life forms which insert sections of DNA into a host, thus altering the hosts DNA.

Evolution will work with any >0 cross over rate, but a cross over rate of >0.5 (50%) greatly increases the pace.

A Note on Mutation rates

Mutation rates in GAs can be in terms of genes or genomes. The mutation rate used here is a per genome value which means you get the same per gene mutation rate regardless of gene-length.

per_gene_rate = per_genome_rate/gene_length

With a per genome rate of 0.1 the probability of mutation for each gene in a 10bit genome is 0.01. If the genome was 100 bits probability of mutation for each gene would be 0.001. If a per gene mutation rate of 0.1 is used then 1 gene in a 10 bit genome will mutate, however the same per gene rate will cause 10 mutations in a 100 bit genome.

micro_ga's People

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.