Random functions from processing API for genetic algorithm?

Hi! I want to build a program in which a class is constructed and then randomly adds, to itself, one of the various functions available in processing’s API. The result would be drawn to the screen (if in fact it calls a function that draws anything at all, and is filled with the proper variables…), and then some fitness algorithm (maybe based on pixel contrast or something) would decide if that class is mutated (by again adding a new function, or switching values in its current function, etc), or if it dies. The idea would be that, over time, /something/, however boring, would develop on screen based on the contingent mutation of the class.

So, my question- is there a way, on each draw loop, to randomly integrate a function in the Processing API into a class ? I’m very much a beginner when it comes to genetic stuff, so forgive me if I’m not using any language properly. I’m certainly not fully aware of how API’s are structured, so even some conceptual help on how to approach this would get me well on my way.

I’m surely the last person that should say this, as i planned to do the exact same thing some months ago, but i can tell you that it is quite… complicated… especially if you just started out. Though not impossible… But you would need many things.

First of all, you need to make sure that the resulting code does not cause any errors that would cause the program to freeze. This can be done by testing the result in a thread. (Though there still might be problems…)

Next, you need to add a method to your Base class… which i just looked up some days ago. Here’s a link : https://stackoverflow.com/questions/1011443/extending-or-adding-new-classes-at-runtime-in-java

And after that… well, start with even getting a class to run a foreign method…

On the other hand, if you don’t want something fancy, you could just create some base Methods for your class and let them be executed in a random order/manner. Thats a lot easier and shouldn’t cause too many problems.

Hi Hankg,

If you are a beginner, you might want to start by something simpler. Genetic algorithm by itself is quite a challenging topic to master.

The fitness function is probably the most important thing to work on and right now it is not clear what you really want to do with your program.

The gene that codes the behavior is also important and in most cases, not that obvious to construct.

On top of that you want the behavior to be complicated using random call to functions.

My advice would be to start with common exercice on the topic with a bunch of fish trying to eat food for example.

He’s basically trying to create a Class, composed of random functions… And then execute the class inside draw with some of its methods. If then something is drawn on the canvas, the fitness function would increase and the class is better than one without a drawn output. And then the better class gets additional methods and removes the ones unused, and also changes a bit which methods are drawn. Like you would expect from a generic algorithm… at least, thats what i understood…

Exactly. I think your suggestion of just constructing some methods at first might be the best way to feel out the project. Funny that we both arrived at the same idea- I was thinking of it in terms of processing being a ‘universe’ itself, and allowing it to randomly assemble as it will, over time.

The issue of crashing and the need to test in threads is what I imagined a more complex version of this might get into…yikes.

If the fitness function is simply how many pixels are draw onto the screen I seriously doubt the end result will be interesting. Better use call to random() in a for loop to get the same result…

Yup, there are already some who try to create such self developing programs. Some time ago i came across a program that constructs a game on its own… But i don’t remember the name.

Well, that sure is better to get the same result, but the underlying program and setup is more important than the result in this case. Like an AI that recognises if a number is 0 or 1 and a handwritten program that just selects which one is written is basically the same, but the approach is different. (might not be the best example, but you get the point^^)

I saw the one that makes it’s own game, it’s really cool stuff.
Do you know any others off the top of your head in this vein?

You might wanna take a look at this wikipedia page. It talks about the concept itself of self-modifying code. Which can then be used to make such things as self improving games/codes in general.