File:Predator-prey toy model.gif
Predator-prey_toy_model.gif (576 × 489 pixels, file size: 6.35 MB, MIME type: image/gif, looped, 244 frames, 24 s)
Captions
Summary
[edit]DescriptionPredator-prey toy model.gif |
English: An extremely simple predator-prey toy model. At each time step each pray (black dot) has a chance to duplicate, but is eaten if within a distance from predator (red circle). Predators can also duplicate, but have a chance to die, if they don't eat.
To avoid the predator extinction one can either fine-tune the parameter, or build a more complex model. |
Date | |
Source | https://twitter.com/j_bertolotti/status/1424778017902039054 |
Author | Jacopo Bertolotti |
Permission (Reusing this file) |
https://twitter.com/j_bertolotti/status/1030470604418428929 |
Mathematica 12.0 code
[edit]nprey = 2*10^3; npredator = 5; predatorradius = 0.3; stepprey = 0.2; steppredator = 0.2;
prey0 = RandomReal[{-10, 10}, {nprey, 2}];
predator0 = RandomReal[{-10, 10}, {npredator, 2}];
prey = prey0; predator = predator0;
probpreybreed = 0.025; probpredatordie = 0.2; probpredatorbreed = 0.2;
histnprey = {}; histnpredator = {};
evo = Reap[
Do[
feedingpredators = Table[0, npredator];
For[j = 1, j <= npredator, j++,
feeding = Position[Norm[# - predator[[j]]] & /@ prey, x_ /; (x < predatorradius)];
prey = Delete[prey, feeding];
If[Total[Flatten@feeding] > 0, feedingpredators[[j]] = 1];
];
random = RandomReal[{0, 1}, npredator];
dyingpredators = Position[random, x_ /; (x <= probpredatordie)];
dyingpredators = DeleteCases[ Abs[(feedingpredators[[Flatten@dyingpredators]] - 1)*dyingpredators], {0}];
predator = Delete[predator, dyingpredators];
nprey = Dimensions[prey][[1]];
npredator = Dimensions[predator][[1]];
random = RandomReal[{0, 1}, npredator];
breedingpredators = Flatten@Position[random, x_ /; (x <= probpredatorbreed)];
predator = Join[predator, predator[[breedingpredators]] ];
nprey = Dimensions[prey][[1]];
npredator = Dimensions[predator][[1]];
random = RandomReal[{0, 1}, nprey];
breedingpreys = Flatten@Position[random, x_ /; (x <= probpreybreed)];
prey = Join[prey, prey[[breedingpreys]] ];
nprey = Dimensions[prey][[1]];
npredator = Dimensions[predator][[1]];
prey = Clip[prey + RandomVariate[NormalDistribution[0, stepprey], {nprey, 2}], {-10, 10}];
predator = Clip[predator + RandomVariate[NormalDistribution[0, steppredator], {npredator, 2}], {-10,
10}];
If[npredator < 1, Break[]];
Sow[{prey, predator}]
, {500}];
][[2]];
history = Table[(Dimensions /@ evo[[1, k]] )[[All, 1]], {k, 1, Dimensions[evo[[1]] ][[1]]}];
frames = Table[
GraphicsRow[{
Graphics[{Point[evo[[1, j, 1]]], Red, Thick, Circle[#, predatorradius] & /@ evo[[1, j, 2]] }, PlotRange -> {{-10, 10}, {-10, 10}}, ImageSize -> Large]
,
GraphicsColumn[{
ListLinePlot[history[[1 ;; j]], PlotRange -> {{0, Max@history[[All, 1]] + 100}, {-1, Max@history[[All, 2]] + 10}}, Axes -> False, Frame -> True, FrameLabel -> {"Prey", "Predators"}, LabelStyle -> {Black, Bold}, FrameTicks -> None, PlotStyle -> {Gray, Thick}, AspectRatio -> 1]
,
ListLinePlot[history[[1 ;; j, 1]], PlotRange -> {{0, Dimensions[evo[[1]] ][[1]]}, {-1, Max@history[[All, 1]] + 10}}, Axes -> False, Frame -> True, FrameLabel -> {"Time", "Prey"}, LabelStyle -> {Orange, Bold}, FrameTicks -> None, PlotStyle -> {Orange, Thick}, AspectRatio -> 1]
,
ListLinePlot[history[[1 ;; j, 2]], PlotRange -> {{0, Dimensions[evo[[1]] ][[1]]}, {-1, Max@history[[All, 2]] + 10}}, Axes -> False, Frame -> True, FrameLabel -> {"Time", "Predators"}, LabelStyle -> {Purple, Bold}, FrameTicks -> None, PlotStyle -> {Purple, Thick}, AspectRatio -> 1]
}]
}, ImageSize -> Large]
, {j, 1, Dimensions[evo[[1]] ][[1]]}];
ListAnimate[frames]
Licensing
[edit]This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication. | |
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.
http://creativecommons.org/publicdomain/zero/1.0/deed.enCC0Creative Commons Zero, Public Domain Dedicationfalsefalse |
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 14:10, 11 August 2021 | 576 × 489 (6.35 MB) | Berto (talk | contribs) | Uploaded own work with UploadWizard |
You cannot overwrite this file.
File usage on Commons
There are no pages that use this file.
Metadata
This file contains additional information such as Exif metadata which may have been added by the digital camera, scanner, or software program used to create or digitize it. If the file has been modified from its original state, some details such as the timestamp may not fully reflect those of the original file. The timestamp is only as accurate as the clock in the camera, and it may be completely wrong.
GIF file comment | Created with the Wolfram Language : www.wolfram.com |
---|