How I Am Using Genetic Programing To Grow Shapes

December 15, 2016

This post is back-filled from my website blog. This explains how the simulation works and how genetic-programming is being used.

The Simulation

Today I got the simplest use of the genetic programming package woking: generating random trees of functions, to make a sort of ‘processor.’ I took the randomly generated processor and plugged it into the plant/coral simulation I have been developing. In this simulation a bunch of spherical particles jitter downwards, roughly simulating the diffusion of nutrients in water or light in a forest. A point, or collection of points, acts as a ‘seed.’ When a sphere collides with the seed, it creates a new point and an edge. I will refer to the points as ‘nodes.’ Each node decides where to put the child node. For the moment this decision is based on the position of the collided sphere, and it’s relative position to its parent node.

sim_drawing

The decision of where to put the new node is where the randomly generated processor comes in. Normally I would write the program or sub-routine that decides where to put the next node. Indeed I have been doing that for a bit. But I am interested in making generative shapes that evolve! Presumably many of the plant, algae and coral shapes that we observe in the real world have growth rules that have evolved and been subjected to natural selection. Seeing all of that variation makes me want to experiment with virtual growth systems and simulated evolution. This is the first step in that direction.

How Genetic Programming Works in this Project, for the time being

There are a set of ‘primitive functions’ that are sampled randomly to create a nested series of function calls. There is also a set of ‘terminals’ which are constants and variables that act as inputs to the innermost functions. Here is an example of a randomly generated processor:

mean_vec(mean_vec(rotate_vec_np(y, y, c1), rotate_vec_np(y, y, c1)), scale(rotate_vec_np(y, y, c1), dot(x, y)))

The primitive set included mean_vec, rotate_vec_np, scale and dot. The terminal set consists of the 3d vectors x,y and the constant scalar c1.

This is most easily visualized as a tree (I did not make the code to generate processor trees or visualize them. It is all from the python package deap):

p_tree

This processor tree takes in two 3d vectors and outputs a new vector. This is intentionally designed to act as the ‘decision maker’ of the node! the vector x is the relative position of the sphere to the collided node. The vector y is the vector from the parent node to the collided node.

inputs_to_p_tree

Clearly the functions available in the primitive set, and any constants in the terminal set, are going to have an important role in constraining the possible growth behaviors. So I have been playing around with different primitive sets.

Some Randomly Generated Processor Trees and the shapes that resulted:

Below are some pleasing shapes that resulted (on the left), with their associated processing tree on the right.

You might notice some terminals are numbers with alot of decimals. Those are ‘ephemeral constants,’ constants that are randomly picked, in some range, when the processor was generated. Also, some of the structures are a bit lopsided. I accidentally had a setting where particles were being spawned at a side plane of the box as well as the top. In all of these cases the ‘seed’ is a line segment. This way the top most node has a non-zero vector from the parent node. If there was only one node, the y vector would be zero, and more processor trees would result in no visible structure.

randa

randb


An Aesthetic Hypothesis and a Road-Map

October 06, 2016

Aesthetic Hypothesis

When I look at natural systems like a tree, a cat, a city, a grassy field, I imagine that all that harmony actually comes from relationships full of tension and struggle. Of course the connotations associated with tension and struggle tend to be negative, but in the non-designed systems they are the ingredients of balance and peace. (see end-note 1)

I have an aesthetic hypothesis: Intruiging forms arise from the interaction of competing forces.

For example, according to the hypothesis, the tree is beautiful in part because there is tension between the impetus to grow taller and bigger, and the need to exchange liquid, sugars, and nutrients between the foliage and the roots. Of course many more factors influence a tree’s development, but these are a few simplified examples that I may try to encode into a simulated creature.

I intend for this project to be an exploration of a few things:

Project Lineage

This project is an offshoot of the meshDLA or Coral Simulation project I did in college in Golan Levin’s class centered on programing and art/design.

In that project I created a simulation system where a mesh “grew” according to rules based on biological stony corals. The simulation worked like this: a set of spheres moved in a pseudo random walk, biased down. When any particle intersected a node of the mesh (the “coral”) that node moved outward along the vertex normal, thus “growing”. The result were vaguely branched, coral-like forms. The ideas for this simulation were simplified versions of methods described in this book: The Algorithmic Beauty of Seaweeds, Sponges and Corals.

The most interesting part of the experience was exploring the range of possible forms afforded by the simulation system. What would happen if the particle size was relatively much bigger than the mesh-edge size? Or what would happen after a very long run of the simulation? I hardly explored these questions because at the time the project was mostly about getting the damn thing to work, and then printing the shape. At the time I also thought the project might be useful for generating heat-sink forms, but since then I feel it is more about exploring growth systems and form.

I also realized that, in the abstract, the project consisted of an environment wich contains a nutrient or energy source, and a structure which interacts with this environment. These ideas were clarified and vocabulary was added by the this paper: Visual Models of Plants interacting with Their Environment. Even more abstract: an environment that provides information to a structure, which in turn affects the environment. This abstraction opened up a whole new set of possible growth behaviors: Stick-like bushes that grow up into the particle-cloud, nutrients that behave like rays of light, shifting across the sky, dual nutrients, which move in different ways. The hope, then, is to explore more than to engineer.

A Proposed Road-Map

Exploration of interesting shapes [B]:

DECISION: Blender

TODO:

Exploration of tension [A]:

Structures:

Nutrients:

End Notes (2017-05-09)

(1) Since writing this I read the Selfish Gene and a few chapeter of the Extended Phenotype. This has much clarified my notions of harmony and discord in the context of organisms.