Wiki

Clone wiki

Core / Limage

Lim genetics revisited

This in not a new version, just a combined description of the genetics made in two seperate versions.

As a sort of brief review of pixels, pixels contain four values with value limits of 0 to 255. The colors are red, green, blue which in varying combinations make all the colors than can be displayed. The last value is intensity (alpha) which is basically how see though the pixel is.

Each pixel is additive. If there are two pixels for rotation they both rotate the creature (Lim).

All of these are subject to independent genetic drift. Red, Green, Blue, and alpha can go up down or stay the same independenly in each generation. This occurs independently for each pixel.

These pixels are exactly what is draw on the screen. You can see their genetic code.

The 256 (0 - 255) values of blue are split in half. One half be considered a rotate command and the other half being considered a move forward command. Blue means command also called blue code.

Intentsity (alpha) is used as the value for the command. An alpha of zero (which is totally see though) means do nothing. Intensity (alpha) means how much.

The creatures (Lims) sense food and each other. They sense by distance not location meaning that they only know how far the closest food or other creature is away, not which direction it is in. This simulates a kind of vibration or smell type sense.

The green parameter of the pixel is divided into three parts.

  1. Two of the 256 values mean "ignore food distance" The remaining 254 values are split between
  2. "Do this if closest food is farther than this"
  3. "Do this if closest food is nearer than this"

The value of green is reused as the amount of distance of pixels divided by 10. This gives the logic that goes soemthing like

  1. If green is all the way on 255 or all the way off 0 ignore food (and do the underlying blue/alpha command)
  2. If green is more that 127 do (blue command) if closest food is farther than green divided by ten pixels away. This range of green allows for the creature (Lim) to do it's blue code if the closest food is 12.8 to 25.4 (or more) away.
  3. If green is less than 128 do (blue command) if closest food is closer than green divided by ten pixels away. This range of green allows for the creature (Lim) to do it's blue code if the closest food is 0.1 to 12.7 (or less) away.

So, creature can't respond to "closer than 13.0" nor "farther than 11.0". It's an interesting but odd logical blind spot which may need to be revisited. Code below:

            if (g == 0 or g == 255 
                or (g > 127 and (g/10) > cf) 
                or (g < 128 and (g/10) < cf)) 

The red parameter works identically for the distance to the closest creature (Lim). And, yes, the blue parameter that contains the commands was referenced as "blue code" in honor of Redcode which was one of the inspirations for this effort.

1.3

Source Code

Changes

  • Triple tap for new random world
  • Zoom parameter for zooming in on large creatures (Lims)
  • Up/Left parameters for panning around zoomed worlds
  • Run parameter for halting the simulation
  • Naked creatures (grey borders removed)

1.2

Source Code

More control

Genetic drift and Viscosity are now available as parms.

The recommended genetic drift of 1 means each value (r,b,g,a) can drift by 1, 0, or -1. Higher vales spread it evenly on either size of the 0.

Viscosity how much the creatures (Lims) are slowed. It was noticed in 1.1 that the additional behaviors were making the Lims slow (1.1 defaulted to 100). For large Lims 50 displays good movement. For smaller creatures 10 displays good movement.

The control of viscosity expands the ranger of sizes of creatures (Lims). Six creatures of 32 by 32 functions fine.

function setup()
    displayMode(FULLSCREEN)
    --World(scale, num Lims, Lim width, Lim height, num Foods, genetic drift, viscosity)
    w = World(1, 6, 32, 32, 10, 1, 50)
end

1.1

Source Code

Updates

Encapsulation and control

Rewritten as a set of classes. All the prior settings (with the exception of generic drift which is still hard coded) are available as parms. The code below is all that is need to execute.

--living images
function setup()
    --World(scale, num Lims, Lim width, Lim height, num Foods)
    w = World(4, 20, 6, 6, 10)
end

function draw()
    w:draw()
    w:move()
end

Senses

The creatures (Lims) now sense food and each other. They sense by distance not location meaning that they only know how far the closest food or other is away, not which direction it is in. This simulates a kind of vibration or smell type sense.

The green parameter of the pixel is divided into three parts.

  1. Two of the 256 values mean "ignore food distance" The remaining 254 values are split between
  2. "Do this if closest food is farther than this"
  3. "Do this if closest food is nearer than this"

The value of green is reused as the amount of distance of pixels divided by 10. This give the logic that goes soemthing like

  1. If green is all the way on 255 or all the way off 0 ignore food (and do the underlying blue/alpha command)
  2. If green is more that 127 do (blue command) if closest food is farther than green divided by ten pixels away. This range of green allows for the creature (Lim) to do it's blue code if the closest food is 12.8 to 25.4 (or more) away.
  3. If green is less than 128 do (blue command) if closest food is closer than green divided by ten pixels away. This range of green allows for the creature (Lim) to do it's blue code if the closest food is 0.1 to 12.7 (or less) away.

So, creature can't response to "closer than 13.0" nor "farther than 11.0". It's an interesting but odd logical blind spot which may need to be revisited. Code below:

            if (g == 0 or g == 255 
                or (g > 127 and (g/10) > cf) 
                or (g < 128 and (g/10) < cf)) 

The red parameter works identically for the distance to the closest creature (Lim). And, yes, the blue parameter which was established in the prior version that contains the commands was reference as "blue code" in honor of Redcode which was one of the inspirations for this effort.

Obsevations

In general the creatures are showing a much more random yet directed behavior indicative of life. A successful lurching behavior near food often arises.

Narrower Range

Smaller creatures (Lims) with less genetic code are now much less functional with the new complexity that has been added for food and other detection. The added complexity also brings more lag so larger creatures cause lag sooner. A good range seems to be 4x4 to 6x6.

Less stagnation

Since movement is driven by multiple factors that are in a state of flux, it is rarer to get into a situation where nothing find food. Even very little food in a wide area with few creatures (Lims) normally avoids stagnation. This also means less likeihood of niches (clusters of food).

Boundries

Discussion in the prior version mentioned the absence of boundaries (go far left appear back at right). This was meant to avoid boundary behavior. There were some boundary behaviors at the corners due to how close many parts of the board were. These special zones have become more pronounced with the new behaviors.

1.0

Source Code

Overview

The program simulates organisms competing and evolving using the bits in the images of the organisms to store the genetic code. It is programmed in Codea Lua.

Controls

None. Code manipulation. This versions contains no sliders or others controls to manipulate the environment. In a future version controls may be added but changing the environment during a run changes the simulation greatly.

Inspiration

At it's core it is a Artifical life simulation. However there deviations that seperate it from 20th century iterations of that concept.

It also contains some thought given on how to reinvent programming games with languages like Redcode for the modern era.

Main variables

Since controls have not been implemented changing the model has to be done by changing the code. A few key variables that vary the behavior widely are metioned below.

These are in the setup() of the main.

Scale

scl = 10

A fittingly global variable that controls that controls how far zoomed in on the imaged one is. 10 is 10X zoom. Since the program responds to this value by adjusting the boundaries of the world for visual value, it has to be remembered that zooming in 10X also shrinks the world by 10X and since the number of creatures (Lim, Living Images) and food does not reduce the world also become ten times more dense.

Amounts

ni = 20 -- number images/knights who say ni
ft = {} -- food table
nf = 10 -- number food

ni controls the number of images which is the number of creatures (Lim). These creatures eat the food which is controlled by nf.

On an IPad1 the simulation shows signifant lag with 100 or each. In fact at lower numbers lag exists (since every creature needs it's distance to food checked every frame) but the lag is not as noticeable as there is still movement.

Changing the ratios, changes the behavior. At very low levels of food and creatures the game can easily get to a point where no creature will ever eat again so the game no longer progresses even though the creatures still move. This also occurs at low scale numbers with moderate amounts of creatures due to low density.

Creature Size

local h = 4
local w = 4

All creatures (Lim) are the same size. This one of the non-realistic constructs of the simulation. However, the speed at which real creatures change in size is at a rate simulations that evolve size take the other non-realistic approach of ultra-accelerating fitness based on size.

In the example above the creature (Lim) is 4 by 4. This not only controls it's size (4 by 4 with a grey cell boundary of 1 pixel for a total pixel size of 5 by 5 for 25), but also controls the number of genes it has (similar to Redcode size).

Height does not have to equal width, however, the eating algorithm assumes a square creature. So, long or wide creatures may eat food that they don't visibility touch.

Genetic Drift

function Lim:divide(d)
    local gd = 1 --genentic drift

This part is not in the main code but in the Lim class. While the value is at it's lowest setting the to allow any drift, it is still very high. At 1 each bit has even chances to raise 1, remain the same, or lower by 1.

Internals

Genetic code

Each pixel in the image (not including the grey cell wall which is drawn around the image) is used to drive behavior.

As a sort of brief review of pixels, pixels contains four values with value limits of 0 to 255. The colors are red, green, blue which in varying combinations make all the colors than can be displayed. The last value is intensity (alpha) which is basically how see though the pixel is.

In this version red and green values are purely decorative.

The 256 (0 - 255) values of blue are split in half. One half be considered a rotate command and the other half being considered a move forward command. Blue means command.

Intentsity (alpha) is used as the value for the command. An alpha of zero (which is totally see though) means do nothing. Intensity (alpha) means how much.

Each pixel is additive. If there are two pixels for rotation they both rotate the creature (Lim).

All of these are subject to independent genetic drift. Red, Green, Blue, and alpha can go up down or stay the same independenly in each generation. This occurs independently for each pixel.

These pixels are exactly what is draw on the screen. You can see their genetic code.

Rotation

Rotation is based on a circle being 256 degrees which matches the values availble for alpha. Only primitive creatures with number systems higher that base 2 would divide a circle into 360 degrees. (Actually 360 is a great number for sharing but these creatures never share a thing).

Life cycle

Now that you know how they work the next is how they live.

In the beginning

The pixels for each creature are entirely random.

Food

Anytime they get near food, they eat it. Eating one bit of food means two new creature (Lim) are born (and two die).

Birth

The two creatures that are born are subject to independent genetic drift based on the parent that just ate.

The first new creature replaces it's parent that just ate. That parent is dead.

The second new creature replaces the oldest creature in existence. That oldest creature is dead.

Both new creatures are born on the same exact spot the parent was on.

Death

There is no starvation nor death by old age. Both of these concepts are important in real life but for purposes of this model they are removed.

While everything is immortal there is still death.

Parents are removed the instant that they have children removed competion between generations. However, siblings are born on the exact same spot which starts sibling rivalry instantly.

The population is fixed. Again, in real life over population is important nut for the model it is removed. Since the population in fixed and parents have two children each a create needs elimated for each pair of new twins. The one that is choosen is the oldest in existence. Basically, if you took the longest to reproduce out of everyone living you do not contribute to future generations. This is in line with "Zombie Escape Protocol", one does not have to outrun a zombie to escape, one only has to run away slightly faster than your friend who is also being chased by the same zombie.

Food

Food is fixed thoughtout the world and is randomly placed. These keeps fitness from being based on a pattern of food placement.

Boundaries

None, the world is round in all directions. Placing boundaries only simulates boundary niche evolution.

Concepts

Population Stability

The population becomes stable when nothing eats. Another way to think of it is nothing is eating anything new which leads to variation. In the model these last forever. In real life the majority generations in a speicies are the same. It's only at population bottleneck does change happen quickly. If changed happened quickly even during stable periods, the pet cats of the world would be contributing to literature.

Niches

Since food is placed randomly, it can form clusters where creatures seldom go. This represents a niche. It at this point where survival of the fittest is simply replaced by survial of the luckiest. The first creature to find the niche expands rapidly which displaces population that would by 20th century standard been considered the most "fit". Fitness is temporary. It only applied to the current situation at the moment which can shift rapiidly. Think of this food cluster as contributing to larger populations which would have more members available to attempt to survive a population.

Sibling Rivary

The 20th century had overtones of comptetion between unlike things with cooperation assumed for like things. Who are you really competing against, a stranger making different choices or that person who lives with you, who is most like you, who just finished the last of your favorite drinks?

If two siblings take identical paths only the fastest one has a chance. However if they take different paths they turn their competion outwards. To add to this if they follow the exact path of their parent's it will be less fruitful than a slight different path using mostly the same behavior.

Genetic boundaries

The genetic drift is modular meaning that 255 with a genetic drift of +1 is 0.

Given the concepts above a creature that hovers close to a alpha value being on or off has a better chance of birthing siblings that do not directly rival each other and seek new paths. This also occurs on the 127/128 and 255/0 boundaries between movement and rotation for blue.

Model Expansion

Control

Symbollically the green attribute of a pixel could represent the distance to food and the red attribute the distance to a creature (Lim). Combined these would add an If/Or to the existing behaviors.

Of the 256 variations of blue all are used but for only two behaviors. More explicit behaviors such as all specific moves or attacks.

Also adding many no action values to represent inactive genetic code. One method would be "odd blue means off, even blues are commands". Another would be to cluster behaviors for multiples of action (slight move, regular move, fast move) [waltz, cha cha, mosh].

Recode has branching and other commands. Genetics has numerous behaviors and structures that are interesting.

Codons

Programming languages partition code structures with beginning and ends. Gententics has start and stop codon. Notice that stop codons even have color nicknames.

There are also the more familiar chromosomes and other structures.

Methylation

[[http://en.wikipedia.org/wiki/DNA_methylation|Methylation] can be thought of as the setup() for a creature that sets globals or parms based on exposusre to events encountered by the parent.

Enchancers

Enchancers can be thought of a type of loop or more precisely a repeat.

Visualation

As complexity increases more pixels will be needed. If thought isn't give to make structures more visible it will be harder to manually track inheritance. A possible solution would be to have long similar encoded pixels. For example 3 bright white pixels for a start codon.

Genentic Drift

As complexity increases genetic drift can and should be lowered to keep a similar level of change. Also different types of change. Using codons allows insertion and deletion to have more subtle effects. Another alternative is to simulate sexual reproduction.

Data Gathering

While manually observing can be entertaining the ability to track things like established programs have implemented would be interesting. One frustrating side effect of the current model is that if you can clearly see a creature (Lim) it isn't eating so is rapiidly becoming the oldest and will disappear.

Closing

Remember you are just an oddly designed genetic tool that carries your gut flora to places it couldn't get to on it's own and consume food it wouldn't otherwise get. Your gut flora basically existed in it's current form before the concept of stomach. We didn't conscript gut flora into our evolution, it designed us for it's use.

Updated