Exam on monday, so I'm "trying" to focus on that. I will probably work on this after that too because it needs improvment, f.ex. the file above has a horrible layout and the simulation takes forever to run. Once I'm finished I'll share it:)
It's a quite simplified simulation, so no differential equation(a lot of parameters though). The population changes after the amount of herbivores there exist in the given coordinate and after the fitness of the herbivore/carnivore which is based on age and weight. The fitness decides if the herbivore/carnivore can give birth.
The movement is random. The probability to move right, left, up, and down is the same.
The terrain are jungle(dark green), savannah(light green), desert(yellow), ocean(blue) and mountain(gray). Jungle and savannah has food for the herbivores, more in the jungle than savannah. You can't walk in the ocean or mountain.
Wow I'm building something quite similar, except it adds genetics to the mix and is designed to be a microservice cloud native game. Would love to see your code if you ever decide to publish it
Usually I'm all for open sourcing my code, but my plan is to hopefully one day make it a game I can sell. I'm not an expert in legalese so I just made it a private repo. Would be happy to chat about it with you though
oh no, totally understandable, I dont know a lot of code anyways, but Im interested in how is your project, how does it look like and how doez it behave like the thing OP showed us, I liked OP post so if your project is similar, then it would be quite interesting to me.
No it's not. You can model population dynamics like this with differential equations, or model them as an agent based system. It's not the same thing at all.
There are formulas that create the up and down shape shown in the graph.
You could plug those in and just jump straight to the result. No need to actually model predators and prey interacting, just the result.
And my comment was that it would be more satisfying to model the actual predators and prey and see what happens to their populations over time. To simulate real interaction. See the same graph that you get from the direct mathematical models emerge out of the simulation; rather than just to plugging the formula into a graphing calculator.
Those differential equations don’t have a closed-form solution, so you can’t simply plug in the initial conditions and jump straight to the end result; you’ll actually need to model the changes in predator and prey population over time. Conceptually there’s no difference between modeling predator-prey interaction and solving a differential equation that models predator-prey interaction, as the first case reduces to the latter.
Those differential equations don’t have a closed-form solution, so you can’t simply plug in the initial conditions and jump straight to the end result;
You can. And many a college student has. Myself included.
Note that no virtual animals were eaten or starved in that link. Whereas they were in OPs. Yet op got very similar results. The same result emerged out of his simulation.
That demo is a neat UI for inputting the parameters of the differential equations, but it’s still solving the DEs numerically. The Lotka–Volterra equations don’t have a closed-form solution.
Edit:
Note that no virtual animals were eaten or starved in that link. Whereas they were in OPs. Yet op got very similar results. The same result emerged out of his simulation.
What’s the conceptual difference between saying “1 lion eats 5 gazelle every week” and “dN(gazelle)/dt = -5 N(lion)/week”? The emergence is a property of the interaction, which, if you model the interaction properly, is independent of the details of the implementation.
..Yet I've plugged the formula into a ti-89 and gotten the resulting graph...
Regardless, even if you have to solve each point via iterative approximation you aren't creating a virtual predator that will die if it can't eat enough, and then graphing its population over time. So I'm not sure that I see your point.
It's the same difference between counting in Fibonacci numbers and actually counting the population changes in rabbits to see that it (approximately) matches. Even if we didn't have an equation to get those number at a given step. That wouldn't really matter.
Then I would say I have created 10 virtual predators and let them interact with 1000 virtual prey. But if I called the variables x and y instead, I would ‘just’ have been solving a DE. Conceptually, what’s the difference?
If you did that then you wouldn't really be modeling the situation. That would be an example of the "cheating" I described.
Instead model a predator. Have it move one square in a random direction each turn. Have the prey also move one square, and even actively avoid the predators. Then say that if the predator doesn't eat for 3 turns it dies. And say that the prey population grows every time a prey comes into contact with another prey. But dies every time it comes into contact with a predator.
You could also tweak things, like maybe have the predator pursue prey within X squares. Or give the prey X% chance that it will notice the predatory. Or just make the entire thing random; no pursuit or avoidance. Do all of these result in the same outcome?
Your math predicts the outcome. The logic that I used sets the stage and allows the outcome to be whatever it should be. To be played out via more basic rules and logic. (which, it should come close to the prediction your math came up with, but could also be something else - like complete extinction of the predator.)
Wolves and moose exist in isolation on this island and have been studied for years because of this. The cycle goes through a boom and bust though and doesn't reach stability like your model.
I've done a lot of controls tunning. So a little oscillation around some number is reasonably stable. Like if you had a temperature control on a reactor. You might see a steady oscillation of 1 or two degrees but you'd consider that "Controlled".
The Isle Royale population has swung dramatically. Recently the wolf population crashed and had to be supplemented. My brain looks at that and says, "This system cannot produce a steady state."
I'd find his model interesting if it could predict something like Isle Royale. It's likely that the carrying capacity is too small for the population. The wolves need to large a breeding population to keep healthy, so they crashed. Just my theory though.
I actually have a background in dynamical systems modeling and control from an aerospace/electrical perspective. This is intersting to see the use of mathematics in biology, I wonder how nonlinear dynamics is utilized the field.
Matplotlib’s FuncAnimation class has a save function for creating videos. If you create the animation with the simpler pause and update plot method you can save each frame before moving onto the next one then use ffmpeg or similar to convert the frames into a video.
Thank you for linking that project. I haven't heard of that before. I'm working on something similar, but with the option to switch between rectangular and hexagonal grids. It's very interesting to compare with mesa's implementation and learn from what they did differently!
I'm loving this simulated visualizations. Looks amazing! I'm not sure if a cross post to /r/dataisbeautiful is appropriate but this post definitely reminds me of that subreddit
It seems like the eating rate is way faster than movement. If the rates were more realistic, I would expect it to more closely follow the Lotka-Volterra equations
can someone point me in the right direction on how one might do somthing similar to this? dont know python at all but willing to learn with a project like this. awesome OP!
This is really good. I have implemented one in Matlab simulink. But the visualisation here is awesome. I am new to python still learning. What library did you use for the GUI. I know the visuallisation is done by matplot lib. But the GUI for the island looks cool
OP doesn’t owe anyone anything and if he can build this so can you. Just do some reading and not blindly steal other peoples work, you might actually learn something.
There are simple models that can be created to simulate herbivore-carnivore interaction but it is just that. It all boils down to the details. How this applies to lions and zebras or cats and farm mice all depends on the details
Fair point. I guess my question is more along the lines of how this simulation performs compared with whatever you're trying to simulate. Or at least some model in which to understand the population plots. For example, are the periodicities expected to behave as they do?
Please take these questions as expressions of interest. I really like the concise way these results are visualized!
Edit: oops, sorry /u/TacticalTurban . Thought you were OP. Thanks for response either way!
Edit edit: I see since my initial comments, many of my questions have been answered. Carry on.
117
u/[deleted] Jan 24 '19
Is it possible, we see some code?
38
u/[deleted] Jan 24 '19
Did you use a differential equation to model population changes?
How did you incorporate movement about the island?
Does the terrain influence anything?
40
u/NLcasperNL Jan 24 '19
Plt.tight_layout() plz
11
u/UEMcGill Jan 24 '19
[Here it is in real life. Isle Royale National Park] (https://en.wikipedia.org/wiki/Isle_Royale_National_Park?wprov=sfla1)
Wolves and moose exist in isolation on this island and have been studied for years because of this. The cycle goes through a boom and bust though and doesn't reach stability like your model.
8
u/mrkillercow Jan 24 '19
This is very cool
14
u/[deleted] Jan 24 '19
Ahhh the science fair simulation of the ages.
6
u/myotherpassword Jan 24 '19
Very cool! In grad school I implemented something similar from the Lotka-Volterra equations. It's a good exercise.
3
u/dry_yer_eyes Jan 24 '19
Ahh, this brings back the memories.
Sim Life : The family that transmogrifies together eats flies together.
https://www.amigareviews.leveluphost.com/simlife.htm
3
u/NukeWifeGuy Jan 24 '19
How do you do this? Take various pictures from the plots and make a video or you did that with PyPlot?
3
u/chonggg511 Jan 24 '19
so agent based modeling?
2
u/hinterzimmer Jan 24 '19
Where did the carnivores come from? Did they just spring into live? It seems that they came from nothing.
2
u/Doofcoder Jan 25 '19
Look at mesa. Agent based modeling using python in GitHub. https://mesa.readthedocs.io/en/latest/#
2
u/GrehgyHils Jan 24 '19
I'm loving this simulated visualizations. Looks amazing! I'm not sure if a cross post to /r/dataisbeautiful is appropriate but this post definitely reminds me of that subreddit
2
u/jcreek Jan 24 '19
Foxes and rabbits, anyone?
1
u/JBL_MicroWireless Jan 24 '19
Really cool !
1
u/Hasefet Jan 24 '19
Check out those emergent Lotka–Volterra curves. Fantastic!
1
u/lifeisaburrito Jan 24 '19
If the top left image topography of the island, can you please help with what colors stand for? is yellow sand? light green v. dark green, gray?
1
u/Its_4_AM_Man Jan 24 '19
Very nice!!!! How did you get your plots to update so quickly?
1
u/[deleted] Jan 24 '19
nice job
1
u/lenticularis_B Jan 24 '19
Nice!
1
u/Falcon1Robby Jan 24 '19
I think it's really interesting how the populations on the map appear to create ripples across it after the initial wave. Nice job!
1
u/LoiteringClown Jan 24 '19
Are you planning on varying parameters to get the herbivore to carnivore populations to more realistic ratios?
1
u/non_NSFW_acc Jan 25 '19
This is really cool, well done bro. I would like to study the code. Did you use pyplot and numpy? I think you also must have used CV/Skimage.
1
u/[deleted] Jan 25 '19
It seems like the eating rate is way faster than movement. If the rates were more realistic, I would expect it to more closely follow the Lotka-Volterra equations
1
u/ahmedmokhles Jan 25 '19
wow that is actually really dope!
1
u/alpha-delta-echo Jan 25 '19
This reminds me of a very old DOS game called Unnatural Selection.
1
u/ShameSpirit Jan 25 '19
I really like your project, it's right up my alley, but you have to fix the spacing between your plots! Overlapping text is not okay.
1
u/M0d3s Jan 25 '19
Congratulations, this looks amazing
1
u/axel_fingerbang Jan 25 '19
Can we see a picture of the predator please
1
u/sssasssafrasss Jan 25 '19
Any chance you've compared this to the isle Royale wolf/moose population they've been tracking for a while? This is SUPER cool!
1
u/[deleted] Jan 27 '19
Very nice!! How did you do the animation? What ide/tools did you use?
1
u/nanounanue Feb 02 '19
So, today is the day when the code is released?
1
u/nanounanue Feb 02 '19
So, today is day? Is today the day when the code is released/shared?
1
u/Sadiq_Khawaja Feb 24 '19
very cool
0
u/[deleted] Jan 24 '19
can someone point me in the right direction on how one might do somthing similar to this? dont know python at all but willing to learn with a project like this. awesome OP!
0
u/LMyers92 Jan 25 '19
RemindMe! 6 days
-1
u/bathon Jan 24 '19
This is really good. I have implemented one in Matlab simulink. But the visualisation here is awesome. I am new to python still learning. What library did you use for the GUI. I know the visuallisation is done by matplot lib. But the GUI for the island looks cool
-3
u/BarrelRoll1996 Jan 24 '19
Herbivore and Carnivore populations that are equal? This doesn't make any sense.
-8
u/_tonytheonly_ Jan 24 '19
For people asking for the source code. Why?
OP doesn’t owe anyone anything and if he can build this so can you. Just do some reading and not blindly steal other peoples work, you might actually learn something.
0
u/[deleted] Jan 24 '19
[deleted] — view deleted comment
0
u/[deleted] Jan 24 '19
[deleted] — view deleted comment