Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: My first Genetic Algorithm program
19 points by dragonbonheur on June 24, 2015 | hide | past | favorite | 14 comments
Wrote a program in FreeBASIC to try and find out how Genetic Algorithms work. It's a quick hack that I wrote to try some theories with because the Wikipedia Article on GAs reads like greek to me. So I built it from the general principles i knew at the time.

The "genome" per individual is an array of 9000 integers but I used only monochrome pictures with either black or white; An individual also has a fitness score.

There are 1000 individuals in the population and only two are selected to reproduce. So that makes 9 million (yes, MEELION as El Reg would write) data points and the scoring information being processed every time.

There's a 0.002% mutation rate just to keep things going because things tend to stall with monochrome data. A higher mutation rate and the algorithm will never approach maximum potential fitness, apparently.

The code is wildly unoptimized and it's my first draft. I could have used memory pointers to manipulate image data faster but this gets the job done so far. Processing color data takes a lot more time and this program wasn't written for that.

Runs on Windows. The source code needs to be cleaned up, so I didn't include or upload it. As far as i know, this may be sadly the only Genetic Algorithm program so far from the island of Mauritius. Download it here: https://sites.google.com/site/bryanbottebell/bryan-bottebell-s-projects/Imolver.zip




Let me remind everyone that downloading and running unknown executables is borderline insane.

@OP Where is the source?, if you want to share, distribute the source not the exe.


Dude, if you saw the source, you'd faint.

About it being unknown, may I remind you that much of Apple OS X or Microsoft Office are just as "unknown"? Have you read the source of LibreOffice recently?

EDIT: I've included the source in the .zip now. Maybe i should have put an EULA like the "trusted" companies but anyway, you wanted it, you got it. In BASIC.


> About it being unknown, may I remind you that much of Apple OS X or Microsoft Office are just as "unknown"? Have you read the source of LibreOffice recently?

To the sentiment of the parent; Apple, Microsoft and the Document Foundation are all large entities with years of good faith trust building relationships, where you are "just some guy" on the internet asking people to execute arbitrary code.

I understand you not wanting to release source, but I also understand the parent's hesitation to run your binary.


I see where you are coming from on this. The difference is that people know and roughly trust MS and Apple. And hundreds of devs have worked on LibreOffice.


Apple and Microsoft have much to lose if they are found distributing malware. You on the other hand have just written your first GA program and have admitted that the source is ugly. What is the last time you were OK about running an executable from a shady site?


Let's not beat up on the OP too much for not releasing source. It's a very complex program and in an initial state is surely messy code (we've all been there).

Good work OP.


Just in case it came out the wrong way, kudos to the OP for getting the job done. I just found his argument that the source-code isn't needed because Microsoft doesn't release its sources way off mark.


We need to see the source so we know your code isn't malicious.


>> That downloading and running unknown executables is borderline insane

That's what VMs are for :p


One way you can use a higher mutation rate is to only mutate children, but keep the parents without mutation (as the first two children of the next generation). That way you can always remember the 'best of previous generations.

Or, you can vary the mutation rate with a normal curve -- so say most of the population gets a small rate, but a small percentage gets a wildly higher rate and wildy lower rate.


>remember the 'best of previous generations

In nature, immortality doesn't seem to lead to much evolution. remember that immortal jellyfish some japanese scientist discovered a while ago that went back to its polyp phase once it got mature? Besides, sometimes species devolve too in nature. I just accept mortality and obsolescence as they are.


hehe. That's fine. It all depends on the nature of the experiment. Typically you want to optimize a solution in a given deterministic domain. If you wish to, instead, create an open-ended evolutionary system for novelty in a non-deterministic solution space, go for it!

Although, to be fair, in nature you're also not dealing with a static fitness function, a high mutation rate, and there's a wide myriad of other variables that affect the overall dynamics of a population (like sexual vs asexual reproduction, migration, recessive genes, sexual selection, etc)


You're absolutely right. I've been wondering what results i would get if I seeded all of the population with the reference image data, slightly mutated but let the GA look for variations with a 10 or 20% variation tolerance.


Thanks! I wanted to start learning GAs and this looks like a great intro.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: