Let's Make Robots!

Darwin is a hacker

How many monkeys on type writers does it take to write the collected works of Shakespeare? Or Asimov for that matter? It has been claimed, but never tested, that a limited amount of monkeys will indeed produce such a work.

Given enough time...

I think I can emulate a finite amount of monkeys hitting random keys. I just did so. It's a perl program of about 300 lines that produces Picaxe Basic. Or rather, it produces absolute nonsense, and then feeds it to the picaxe compiler for a quick syntax check.

Every bit of gibberish that makes it through the test is relabelled as "viable" picaxe code. It is stored somewhere safe for future retrieval. And this is where my monkeys get a bit smarter. They copy pieces of existing picaxe code. The better the code, the more likely they are to reuse it. And add to it. Or delete parts from it. Or paste it into their own. But most of all, they will combine it with other pieces of existing code. And thus produce new code to be tested by the compiler.

Now, admittedly, I am a cheater. I gave my army of idiot programmers a few snippets of code. The very minimum lines like "b0=0" and "pause 1". And it shows. These snippets are reappearing all over the place. In about an hour, my collection of viable programs has grown from 5 to 500. One combination for example now reads "pause b0".

This is not enough to me. I want a real picaxe to start using this code. And I want some way of telling the monkeys which pieces did something really cool while uploaded to the micro controller. I am still without such a feedback system. It could be all kinds of stuff, but most of all, it needs to be dead simple. The feedback system is taking shape.

And it need to be something visible, so I can broadcast the experiments on live internet TV.

So, my monkeys.... What kind of ideas will you copy and paste together for this cool experiment?



# 201005121529 rik (1069) letsmakerobots.com
# artificial evolution of micro controller code
#  Picaxe Basic in my case
#  Warning: this code is highly experimental - might just be mental

# 201005121611 let's introduce point mutations
# 201005121611 let's introduce rudimentary evaluation functions
# 201005121809 let's introduce sort by_fitness into select_creature
# 201005121950 let's introduce specific picaxe basic genome cleaners
# 201005131258 let's cleanup not-dead code upon loading
# 201005131818 let's cleanup code before determining id (plus other major improvements in quality)
# 201005131819 let's prevent two identical pieces of code to exist in the db
# 201005132025 let's try and rate the quality of a compilation
# 201005141604 let's remove some non lethal bugs
# 201005141607 let's reuse make_creature in the main loop
# 201005141621 let's cleanup accolades (curly braces) and reduce labels to one alpha char
# 201005141717 let's not shorten labels, it destroys potentially interesting dna
# 201005141723 let's dump all genomes in one huge logfile for online monitoring
# 201005141738 let's expand the fitness range for dead genome: 1-9 depending on location of syntax error in the code
# 201005141756 let's give small viable programs a small advantage when memused is just over 4 bytes
# 201005141856 let's compile code with newlines replaced by spaces so that we know the exact length of the code
# 201005141948 let's no longer compile code with newlines replaced by spaces, it's another bad idea, the code appears to be functionally different in some cases
# 201005142036 let's cleanup backslash-doublequote combo's
# 201006011238 let's allow for father and mother to be the same creature (!)
# 201006011441 let's rename "retired" into "buried"
# 201006011824 let's stop replacing empty genome by an arbitrary string (a:) and start evaluating it as fitness = 1
# 201006011929 let's move all the sorting and counting of %creature to the top of the script, saving tons of CPU cycles
# 201006022235 let's cleanup trailing newlines
# 201006032139 let's push any new ids to the array @ids, without bothering with expensive sorts
# 201006032154 let's no longer worry about genomes shorter than 2 chars, they too have a purpose in the gene pool

Continue reading here.

3evolve.pl_.txt12.35 KB
4evolve.pl_.txt13.31 KB
5evolve.pl_.txt14.66 KB
6evolve.pl_.txt17.05 KB
7evolve.pl_.txt17.23 KB
8evolve.pl_.txt19.5 KB
1population_management.pl_.txt5.67 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

My population manager is killing creature by the millions, but the project won't die. The physical habitat for the viable creatures is underway! Stay tuned.

[image intentionally obscured - dum dum dummmm!!]

Rik, are you familiar at all with the halting theorem?

I get the feeling that if not, you're going to encounter it pretty soon. Have fun with that.

The other thing is that I can see a flaw in your test: that is, the code you produce (if executed on a picaxe) could actually result in a large number of different outcomes, depending on how the chip is wired up and what to. The same program could potentially perform many different tasks, all dependent on the hardware the chip is plugged into.

Also, I'm not sure how many keywords there are in picaxe code, but even if you were to start with a language of only valid keywords, there are billions of possible combinations, and only a very few of them will actually do anything interesting.

I never intended my experimental robot to run the program until the program decided for itself to halt. I planned on giving it like 60 seconds of running time before I (automatically) upload the next code for testing.

This is the beauty about my kind of experimenting. It's just for fun and glory (thanks TinHead).

However, the problem of the astronomical odds is very real. I have yet to find a way to circumvent it. I already learned that the evolution algorithm needs to be able to recognize even the smallest advances in fitness. And I am not sure how I will implement that once I am ready (if ever) to start uploading genomes into my arbitrary robot.

" my monkeys where" .....I fed the text from your blog above into this Gibberish generator

The resulting output makes some sence and nonesence -

Why did i do this you may ask ?...........

...... it proves that even in total gibberish there are patterns and new ideas to be stumbled across. (otherwise never tried out by humans).

When this can be assimulated by computers then future Human-coders will have thier work cut out for them just trying to De-compile and understand why the code is so amazingly brilliant ........ good luck with your experiment rik....

.... i have underlined the bits that have at least some sence..........

---------- Gibberish text  using the text of riks blog above------------------------------------------------------------------

It could be dead simple.
And I want a reappearing picaxe to reuse "b0".
This is not enough on their own. But most of code, And this is while uploaded to reuse "1".

If I want it a bit smarter, every minimum lines that makes it adds to it. Or delete parts from it.

Or paste it through the monkeys get a bit of existing code they will compile.
Now, admittedly, I am a check.
Every bit of idiot program of ideas will combine for a quick system. It is while uploaded to me.

I can emulate a few snippets of existing collection of existing code. These snippets on live internet TV.

So, my monkeys get a bit of ideas will combine it through to the micro controllection of existing the monkeys.

They will without an hour, my monkeys.... What makes it to be something, I can broadcast the cool experiment?  this is stored so. It could be all, it to be something all, it through the code to the code.

And to start using code together with pieces of code. And it produce new code to start using code.

They will you copy pieces,  somewhere my army of idiots produce new code. The army of ideas will you copy pieces absolute now reads "pause 1". And it need to 500.

One combination of existing the experiment?  this is stored some way of viable" picaxe compiler for future reappearing thing visible, so I can broadcast the compiler. I just did somethink I can emulate amount of about an hour, my monkeys where..........


I dare not try re-iterating that process! There is bad karma waiting for me at the end of that tunnel, I'm sure.

Part of your problem may be the lack of true randomness in your random number generator. Try using the data from an LDR that is mounted on a wind chime to seed your random rumber generator.


I just did a quick "back of an envelope" calculation. And it turns out that the odds of finding a word (any word) that exists in the picaxe manuals through combining random characters are ASTRONOMICAL.

That will not do!

So I did some major cheating and injected the entire index of manual 2, containing some 1500 discrete words. Now it turns out my algorithm does not respect that either. It is chomping on infinite variations of the word "disconnect".


I get the hint. I'm off to bed.

Stranger even than that!

Random code can lead to new knowledge. Did you know that this:
compiles just fine?

But what is worse, near such a backslash-doublequote monstrosity, the compiler will accept all kinds of gibberish!
Compiles just fine!

Don't they understand that this is a gateway to evolutionary hell?!

I cheated and I got punished for it.

My latest algorithm further cleans up any genome that was randomly generated. One of the cleaners removes labels that:
* are longer than one character
* uses anything but an alphabetic character
So now my viable code only produces nonsense like
and the dead genomes are starting to look eerily similar. There is no chance at all in this system to ever produce anything as "complicated" as "goto k:". The word "goto" simply is too long and will get cleansed before ever finding its way into the viable gene pool.


Glad to see that you are thinking along! Here is some progress so far.

Last night, after improving the selection mechanism a lot, I started a new run. Without injecting any "artificial DNA". Not a single Picaxe word was released into the primordial soup. It ran for 12 hours and completely failed to come up with even a single "goto". The largest viable piece of code reads:

Sure it will compile, but it won't do anything. It's just labels and formatting code. I will alter my DNA repair-code to minimize these.

Until now, the nightly work is done by a repeated batch process. I run 600 iterations and then cull 10% of the dead bodies at random. Each "body" is a file on disk, so that is easy to script. The viable bodies remain. And therein lies the risk Telefox is talking about. There is no mechanism to  make any distinction between stupid and smart programs. There is no distinction whatsoever. All viable bodies (I call them genomes) are rated a fitness of "1".

I tried to change the lack of distinction in this phase of the evolution. My latest code (version 5) is now optimizing for code size after compilation. Remember this message from your Picaxe programmer:
Compiled successfully.
Memory used = 9 out of 4096 bytes.

My evaluation routine is aiming for 40% memory use. That is a very arbitrary percentage and I might change it one day. It does not really matter. Because now, the fitness rating ranges from low to high (from 1 to 99 in version 5). Any piece of code that takes up 8 bytes in RAM or more will win from smaller programs. And even larger ones will win from the 8 bytes code, etcetera. This will hopefully separate the "empty but long" genomes from the "meaningful" ones, without actually testing them one by one in a real Picaxe.

The example genome above scores "1". That is equally low as a minimalistic piece that reads "ma:" and they will both have equal chances of ever spreading their DNA through the gene pool. Without any proper competition, this means the chances are equally "high". As soon as one genome appears with a higher fitness score, all bets are off. My routine selects parents for the next generation at random, but is preferring the better ones. By far. Without forgetting the poor little stupid ones.

My next step will probably be to increase the need for survival. By randomly culling viable genomes. Starting with the stupidest ones.