This video introduces a Python simulation model for natural selection where organisms move along a one-dimensional line, consume food to survive and reproduce, with speed, position, and direction as key variables; organisms that eat two pieces of food survive and clone themselves moving in the opposite direction, while those that eat nothing die, demonstrating exponential population growth until food resources become limiting.
Simulating Natural Selection in Python: Modeling Evolution with Code
Added:okay let's discuss the model assumptions for my simulating natural selection project um these assumptions are based on the videos by primer so if you haven't seen those yet with the you know the blobs they uh that's a great thing I think they're great right so go and take a look at those if you haven't done so already and we're going to try and emulate that model to begin with um but we're going to do it in one domain we're going to simplify it we're going to make it into one Dimensions rather than two so first of all we're going to create some environments uh in in which for our organisms to exist we're going to essentially Define a one-dimensional straight line of size X okay um we're going to distribute pieces of food randomly across that environment with some coverage density uh row so for example if I want a 10 coverage and my line is a dow x equals a thousands um there will be 100 pieces of food on the line okay we are going to um let N organisms inhabit the environments at any given moment and to begin with N might equal one in fact it will um to begin with those organisms when we Define them will possess three key variables firstly it'll be this speeds V the position P along that line and the direction that they're going to move in G so the speeding Position will only take integer values um so for example if V equals one that means for every cycle of our simulation they will take um they will they will step by one so for example if they're at position um 99 and then moving forwards they will then take a step to a hundred okay if their speed is two in one um in one cycle of the the model they will go from 99 to 100 and so then 101. okay and that's how we're gonna get them to move so those speed and position variables will take integer values okay I don't want to module um a model which has continuous variables in of course that can get that can get a bit complicated later um every time the organism moves it's going to check to see actually we'll talk about eating food in a sec I'm first going to say that they will move s times in a day and for the purposes of this model one day um it's going to give us one generation so they're either gonna die or they're going to survive at the end of that day or they're going to survive and reproduce okay um when an organism encounters food this is the juicy bit right um if they haven't eaten any food yet they will eat the food so that food will be removed from the environment and that organism will have a counter associated with them that will tick up by one okay so they'll still start every organism at the start of the day we'll have food equals zero if they eat some food I'll get to food equals one um if they two pieces of Food they'll go through food equals two and then they'll stop eating in fact they'll just stop they won't they won't continue to move um and when all of the organisms in the environment have eaten two pieces of food or all of the food is being consumed the day will end okay and then at the end of that day if an organism hasn't eaten anything it will be removed from the environment in other words it dies if at the end of the day is it in one piece it will survive until the next day and if it's eaten two not only will it survive but it will reproduce and when when I say reproduce um it will spawn spontaneously clone of itself moving in the opposite direction okay and I'll say it again the day will end when all the foods be consumed or when all organisms have eaten two pieces of foods okay so they are our starting assumptions for our model um over the next couple of videos we're gonna try and translate that into code that's the tricky bit and what what I really want is for you to work through these videos one by one and recreate the code I'm not going to give you the code right it's important that your fingers do the work and hopefully in a week or two maybe um I would like you to reproduce this figure here so don't worry about what this looks like yet because I'm going to show you exactly how to code it up um but let me just start at the beginning of this video um okay let's start here so um what what I've done here is I've looped my one-dimensional line around on itself to make a circle so it's a bit easier to visualize what's going on um I've got one red dot okay so I've got one organism here in my environment and all the blue dots correspond to pieces of food so as this red dot moves it's going to eat one piece and then another piece and then the day is going to end and it should spawn another Corner itself there you go so it just did that in the time it took me to click twice as you can see on my graph over here on the right it's a bit dark down here but can I get rid of that no it's um it's starting to tick upwards so I've gone from one organism to two organisms and actually it's already I think looks like it's calculating the second generation and of course as I click play it'll it'll increase exponentially which is what we need and then what you'll see here oh not too far um there'll be a point when there is not enough food in the environment to sustain any further growth okay so that's the sort of natural limit to growth and it will just Plateau out okay um and there you go right so there you go we'll start coding that up in the next video
Up Next

Phages: A Natural Solution to Antibiotic Resistance | TEDx Talk
@TEDx
44.7K views•2016-10-06

Circadian Metabolomics: Sleep, Food Timing & Human Clocks
@tscnlab
359 views•2022-11-10

Enteric Nervous System Explained: The Gut's Brain | Neurobiology Lecture
@alumniu6029
438 views•2018-09-12

Bacteriophages: Earth's Deadliest Killers and Future Antibiotics
@kurzgesagt
34.6M views•2018-05-13
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Biology


![[Python] أساسيات البرمجة باستخدام لغة بايثون](https://i.ytimg.com/vi/sBh4vNcIPkQ/maxresdefault.jpg)




















![Entenda os Algoritmos Genéticos na prática [Cromossomos, genes, mutação...]](https://i.ytimg.com/vi/KApMlVdcf8o/hqdefault.jpg)















