| 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 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.
(* 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 Here is the corresponding Wiki. It also includes a neat image to show how complex these can be:
I believe, this graph is time-colored. - Mine is based on fitness.
|