Most of my work to date has been reactive, that is there is a 1-1 connection between what the user does and what the application does.
Recently for a class project I decided to use Genetic Algorithms to enhance the user experience and potentially augment some of the creative processes of working with a tool.
I always stayed away from this type of coding because it didn’t match the types of applications I was interested in making.
Additionally GA has always shrouded in mystery for most coders since the concepts are described using genetic metaphors and binary crossover operations.
I took a somewhat different tact for this assignment and I’m posting this for the benefit of anyone who is interested in a simple GA implementation for creative coding.
This assumes the user makes an input that can be mapped directly or indirectly to a property of your system.
Here are the steps:
- Make user input your fitness value (user did x, x = fitness)
- For all objects in your system measure distance from fitness value to matching object property
- Sort results
- Collect top 10% – 25% of the objects with closest property values to the fitness value
- For all objects, select 2 or more candidate objects randomly and average their property assigning it to the current object
- Optionally add in the fitness value itself (weighted by a learning factor)
- Optionally add in a random value (weighted)
My application maps user gestures to motion properties such as: linear angle, linear speed, wave amplitude, wave speed, curve speed and so on…
By employing the use of this simple GA, the user’s actions are not mapped 1-1 to a specific resulting motion type. Instead the system appears to “learn” the desired motion by virtue of the selection and mutation processes outlined in the steps above.
Here are some initial results (does not really show the GA part, but until the app is released assume the experience is amazing):