Forum

Genetic Algorithm, working but ugly

Hi there,

The thing is i wanted to realize some genetic algorithms in vvvv. In essence, i wanted to start out by implementing Shiffman’s Nature of Code (Processing) ideas in v4, purely in patch. I wanted to make a fully fledged contribution (would make a great 1st one) with these examples. Think of the possibilities: path finding particles, astroboys who learn to walk themselves, self-patching patches…

It would have been nice to see someone jump in with compute shaders etc. too.
(really excited about node15 btw!)

In the attached patch there’s the first example, working, but not really cool.

The idea is to start with a random population of strings, evalute the ones that are best matching to a certain phrase, cross them, mutate them, repeat from evalutation.

I was surprised how easily you could patch a GA in v4, but then i ran into problem. I have difficulties with the mating process (yeah i know, pun not intended). The patched solution is too messy (big stallones and getSlices), to the point were you can’t really make this for bigger gene sequences. Every extra gene would require some patching; so very unmodular.

Can you help me out? The key would be to get rid of 2 stallones and make this thing (the genes in fact) spreadable.

I already looked into the combinatorics nodes by bjo:rn but couldn’t really implement them. Should i learn c# to write my own node? Is there a way to figure this out in patch? Should i wait for node15 to bug you in person? :)

in excitement to your replies,
Gorg

GA_string02.v4p (99.5 kB)

had a quick look at your patch. it looks very clean and understandable, nice work!

so the problem comes down to creating the right list indices. everything that happens between the two SwapDim nodes (even including them) can be done by just one single GetSlice node with the correct list of indices.

i’d start with a simple example of just two or three parents and a very short phrase and write it down on paper. it should not be too hard to see the logic behind it and expanding it to more parents with arbitrary phrase length.

but in the end you just want to have datatypes, this would solve the index mayhem at once.

thx for the response!
yeah, i figured that it it should be just one getslice. But the correct list of indices… i tried to figure it out for weeks (nearly months!), but i guess i’m too involved by now :D

well, for those who don’t know what this is about:
http://natureofcode.com/book/chapter-9-the-evolution-of-code/

cheers

I got that book. I would love to see those examples in v4 :-)