
Show HN: Genetic Hello World - sacert
https://github.com/sacert/Genetic-Hello-World
======
hcarvalhoalves
Up-voting because even though genetic algorithms seem inefficient compared to
back-propagation with gradient descent, it still is an elegant optimization
heuristic for many classes of practical problems, and often easier to
implement compared to NNs if you're trying to apply on a novel domain.

~~~
sacert
Very true - I had some time at work and remembered how big genetic algorithms
were a couple years ago so I decided to get my feet wet in the subject.

~~~
hcarvalhoalves
A common use case is solving design constraints:

[https://www.google.com/?q=genetic+algorithm+placement+format...](https://www.google.com/?q=genetic+algorithm+placement+format:pdf)

------
TeMPOraL
Cool!

A minor nitpick about the README - genetic algorithm is not the same thing as
genetic _programming_. The former is what you're doing here, the latter refers
to building _a program_ using genetic algorithms.

See:
[https://en.wikipedia.org/wiki/Genetic_programming](https://en.wikipedia.org/wiki/Genetic_programming).

~~~
eternalban
It is not a minor nit & good to point out.

------
nk1tz
I've long been a fan of the GA optimization technique. I created this little
tool to explore the genetic algorithm. You can tweak parameters on the fly and
watch the effect it has on the current set of top solutions.
[https://github.com/nk1tz/explore-genetic-
algorithm](https://github.com/nk1tz/explore-genetic-algorithm)

------
natosaichek
The cost function just looks like difference squared, but I'm not sure how
that yields results like this:

    
    
      Hglmo,wosmd! (8)
      Gflln* wosle! (9)
      Hello, wosld! (9999)
      Hello, world (9999)
    

The bottom two seem to be much closer to the desired result, but the top two
score lower cost? Seems weird to me. :-/

~~~
vanderZwan
I wonder how using Levenshtein distance as a fitness metric would affect the
speed of progress:

[https://en.wikipedia.org/wiki/Levenshtein_distance](https://en.wikipedia.org/wiki/Levenshtein_distance)

OP, if you want to experiment, here's a gist with a JS implementation that I
found after some googling:

[https://gist.github.com/andrei-m/982927](https://gist.github.com/andrei-m/982927)

How the cost function compares to how you mutate probably also matters here.

~~~
TomNomNom
I used Levenshtein distance for a similar thing some years ago:

[https://tomnomnom.com/posts/methinks-it-is-like-an-
incestuou...](https://tomnomnom.com/posts/methinks-it-is-like-an-incestuous-
weasel)

It worked very well!

~~~
vanderZwan
Very nice and simple example!

> _The phrase METHINKS IT IS LIKE A WEASEL is 28 characters long, and has 27
> possibities for each character, making for 27^28 (about 10^40) possible
> combinations. To put that into perspective: it 's reckoned that there's
> about 10^80 atoms in the visible universe. Even if the monkey could try
> millions of combinations per second, he would almost certainly never get
> there - and that's assuming he never repeated a combination._

> _So it would take a very long time for the monkey to hit the right keys at
> random, but what about if it weren 't completely random? Dawkins suggests a
> computer program to simulate the monkey, only using something akin to
> evolution to form the phrase instead of complete randomness. That is:
> randomness would still be involved, but in a slightly more predictable
> capacity than the virtual equivilent of a monkey bashing its head against a
> keyboard._

Funny you should mention that, because one of the unsolved questions for the
theory of Evolution is that _even with_ our current understanding of
evolution, life evolves _faster_ than one would expect based purely on DNA
mutations alone. A few issues back Nautilus had a excellent article on the
problem, and the current work being done to solve this problem:

[http://nautil.us/issue/20/creativity/the-strange-
inevitabili...](http://nautil.us/issue/20/creativity/the-strange-
inevitability-of-evolution)

------
gvx
Genetic algorithms are always neat. I made something similar as a greeting
card in 2015:

[https://card.robinwell.net/f47f6d670450fad68df8ce45d0fa846d....](https://card.robinwell.net/f47f6d670450fad68df8ce45d0fa846d.html)

It uses tournament selection for each next generation.

------
david90
I find it interesting - but it would be nice if there is a better README for
visitor to grab the concept quick.

------
sjmulder
Thanks for sharing. Concise and easy to follow.

I ported it to C to try it out for myself. Turning off console output makes it
finish almost instantly!

------
greenpizza13
This is a really fun demonstration.

