dorkrawk / darwinning Goto Github PK
View Code? Open in Web Editor NEWA Ruby gem for genetic algorithms.
A Ruby gem for genetic algorithms.
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
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)
hi, thanks for sharing your code. How could I run your exemples?
Hi!
I'm just trying to run examples and see this error.
Hey,
Thanks for this project.
However, it is lacking a license which means I am currently unable to use it.
Could you please add a license?
https://choosealicense.com/no-permission
https://help.github.com/articles/adding-a-license-to-a-repository/
Thanks
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
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
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
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?
Is there any way to specify arguments to be passed in to the organism's initialize
?
E.g: Consider the example in the README, how could I modify this so I can pass in the target number, instead of having it hard coded to 100
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.