Coder Social home page Coder Social logo

darwinning's People

Contributors

brianhonohan avatar camertron avatar dorkrawk avatar druzn3k avatar geoffharcourt avatar script-old avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

darwinning's Issues

Just a question on design

  1. I am new to genetic algorithms 2) I haven't examined all the code carefully 3) I don't want to sound nitpicky - I am just learning :) but, is there a specific reason in your design for not storing #fitness inside the object rather than computing it each time it is accessed?

Old fork

Hello Dave,

last year I needed a simple/elegant genetic algorithm library in ruby for one of my student internship. I found yours to be the most adapted to what he needed to do. I still needed to change quite a bit of things in order to get it where I wanted. When I stopped I was not sure a pull request was really feasible anymore or my branch mature enough. More than 30% of the code has been rewritten.

I see that you have received contributions recently, which means that the two branches will diverge from now on. So I though maybe maybe you could be interested in the changes I did before they are irremediably unmergeable.

the fork can be found here:
https://github.com/Nanosim-LIG/darwinning

Don't hesitate if you have questions.

Best regards,

Brice

The mutation is broken

It won't mutate the last gene because of the bug.

The corresponding line in mutation.rb:33 should be:
random_index = rand(member.genotypes.length)

Run exemples

hi, thanks for sharing your code. How could I run your exemples?

Basic usage

So I am trying to use this library to do the most basic thing other than the trivial examples provided:

#!/usr/bin/env ruby

require 'darwinning'

class Vehicle < Darwinning::Organism
   @name = "Car"

   @wheels = Darwinning::Gene.new(name: "Wheels", value_range: (0..4))
   @cylinders = Darwinning::Gene.new(name: "Cylinders", value_range: (1..16))
   @tank_size = Darwinning::Gene.new(name: "Tank Size", value_range: (1..16))

   @genes = [ @wheels, @cylinders, @tank_size ]


   def fitness
       return ((@wheels.value - 4) + (@cylinders.value / @tank_size.value)).abs
   end
end

p = Darwinning::Population.new(
    organism: Vehicle, population_size: 10,
    fitness_goal: 0, generations_limit: 100
)
p.evolve!

p.best_member.nice_print

However this doesn't work because Gene.value doesn't get set (its always nil)

I had to do the following to get things to work.

#!/usr/bin/env ruby

require 'darwinning'

class Vehicle < Darwinning::Organism
   @name = "Car"

   @wheels = Darwinning::Gene.new(name: "Wheels", value_range: (0..4))
   @cylinders = Darwinning::Gene.new(name: "Cylinders", value_range: (1..16))
   @tank_size = Darwinning::Gene.new(name: "Tank Size", value_range: (1..16))

   @genes = [ @wheels, @cylinders, @tank_size ]

   def find(name)
       genotypes[self.class.genes.index{ |g| g.name == name}]
   end

   def fitness
       wheels = find("Wheels")
       cylinders = find("Cylinders")
       tank_size = find("Tank Size")

       return ((wheels - 4) + (cylinders / tank_size)).abs
   end
end

p = Darwinning::Population.new(
    organism: Vehicle, population_size: 10,
    fitness_goal: 0, generations_limit: 100
)
p.evolve!

p.best_member.nice_print

Any ability to seed the first generation?

Wonderful (and simple) tool that I've been using to try and solve a tricky problem with balancing work teams. I've been wondering if there is any way to seed the population with a few known "decent" solutions. It's taking hundreds of generations until the randomly generated solutions are anywhere near as good as the manually created solutions. So I'd like to feed in one or two of the manually created solutions.

Thanks for your great gem!

-Dave

Bug in best_each_generation

There is a bug in calculating the best_each_generation. The history for each gen is actually not sorted because the fitness is not yet calculated so the sort_members calls in initialize and in make_next_generation don't have the desired effect.

fix is to remove the sort and adding to history from initialize and for make_next_generation change to:

  def make_next_generation!
    verify_population_size_is_positive!
    sort_members   ####################### sort and add to history before generating new members
    @history << @members
    
    new_members = []

    until new_members.length >= members.length
      m1 = weighted_select
      m2 = weighted_select

      new_members += apply_pairwise_evolutions(m1, m2)
    end

    # In the case of an odd population size, we likely added one too many members.
    new_members.pop if new_members.length > members.length

    @members = apply_non_pairwise_evolutions(new_members)
    @generation += 1
  end

Variabile number of genes?

In the example directory there are examples with limited number of genes: Binary -10, Cookies -11, Fifteen - 3 and Triple - 3.

How to implement variabile number of genes or organism with one gene but variabile and unlimited size?

Intermittent population spec failures

I noticed while working on an unrelated, forthcoming pull request that two of the specs in population_spec.rb fail sometimes in master.

image

image

I may look into it if I find the time, but I figured I would at least document the issue.

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.