Welcome to Fractal Forums

Real World Examples & Fractical Applications => Fractal News across the World => Topic started by: kram1032 on April 01, 2013, 02:57:07 AM




Title: Evolutionary Automaton - The Bak-Sneppen Model
Post by: kram1032 on April 01, 2013, 02:57:07 AM
(http://i.imgur.com/ku49F1Z.png)I made this image according to the rules of the Bak-Sneppen Model

EDIT: Code updated to have an actually working mutation process. It previously did nothing.

A super-simple model of co-evolution.
You can find a more indepth explanation as well as a javascript simulation here  (http://cmol.nbi.dk/models/bs/bs.html)
Furthermore, here is my Mathematica Implementation,
that produced the image you can see on the left.
It should be pretty straightforward to port to other languages.

Code:
(* User Parameters *)
len = 100; (* Population-size = list-length *)
count = 1000; (* While loop counter - number of timesteps *)
mRate = .001; (* Mutation rate *)

(*Initialization*)
data = RandomVariate[UniformDistribution[],
  len]; (* generate a list of random variables *)
mat = {data}; (* put generated data into a second list level - this \
will be the output matrix *)

(*Main Program*)
While[count > 1,
 smallest =
  Ordering[data][[1]];(* find the element with the smallest value *)
 replace =
  RandomVariate[UniformDistribution[],
   3];(* build a list of replace values *)
 data = If[1 < smallest < len,
   ReplacePart[
    data, {smallest - 1 -> replace[[1]], smallest -> replace[[2]],
     smallest + 1 -> replace[[3]]}], (*
   replace the correct array positions *)
   If[smallest == 1,
    ReplacePart[
     data, {len -> replace[[1]], 1 -> replace[[2]],
      2 -> replace[[3]]}], (* special-cases for borders *)
    ReplacePart[
     data, {len - 1 -> replace[[1]], len -> replace[[2]],
      1 -> replace[[3]]}]]]; (*in order to make it a full circle *)
 
 mat = Append[mat, data]; (* add a line to the history *)
 (* initialize Mutation *)
 i = 1;
 mArray =
  RandomVariate[UniformDistribution[],
   len]; (*generate a List of random variables. Again. *)
 
 While[i < len,
  
   If[mArray[[i]] < mRate,
     data = ReplacePart[data,
        i -> RandomVariate[UniformDistribution[]]];] (*
    if the variables are below the mutation rate,
    replace the data with a random value *)
    i++]
  
  
  count--] (*make sure, the two while loops finish *)

MatrixPlot[mat, ColorFunction -> "TemperatureMap", Frame -> False,
 PixelConstrained -> 1](*plot with pretty colors*)

Enjoy!

The Bak-Sneppen Model is an example of Self-organized criticality (http://en.wikipedia.org/wiki/Self-organized_criticality)
Here is the corresponding Wiki (http://en.wikipedia.org/wiki/Bak%E2%80%93Sneppen_model).
It also includes a neat image to show how complex these can be:
(http://upload.wikimedia.org/wikipedia/commons/a/ac/Bak_sneppen_model.png)
I believe, this graph is time-colored. - Mine is based on fitness.