Presentation is loading. Please wait.

Presentation is loading. Please wait.

EE 194/Bio 196: Modeling,simulating and optimizing biological systems

Similar presentations


Presentation on theme: "EE 194/Bio 196: Modeling,simulating and optimizing biological systems"— Presentation transcript:

1 EE 194/Bio 196: Modeling,simulating and optimizing biological systems
Spring 2018 Tufts University Instructor: Joel Grodstein Lecture 2: Population modeling

2 Population modeling First big topic: population modeling.
The usual first questions… What is it? making models of how a population of individuals grows over time Why do we care? Populations can grow or become extinct, and it affects our lives Especially in Track C Many tasks are easier on a model than working with real animals EE 194/Bio 196 Joel Grodstein

3 Goals of this segment What we'll learn about biology
lx-mx models (and more in extra-credit problems) What we'll learn about modeling GIGO – when is a model valid? simulating models discrete-time vs. continuous time-models stochastic models desert tortoises: using models for things we cannot easily measure (and deciding if they’re correct) What we'll learn about programming Variables, loops, arrays, random numbers 3 homeworks EE 194/Bio 196 Joel Grodstein

4 Population models Inputs to the model
initial population size average birth rates, death rates these are called vital rates If you know the vital rates, it’s easy to project a population forwards i.e., simulate the model; future population is the model output But wait, there’s more Vital rates depend on numerous environmental factors how much food is available. Anything else? or how many predators are around or presence of a disease… and many more Here's where models get really useful Some factors may be under our control We can supply food, remove predators, etc. EE 194/Bio 196 Joel Grodstein

5 Simulating different parameters
Modeling makes it easy to run “what-if” simulations. Determining how things that are in our control can affect population growth. How exactly? Simulate population growth under average conditions. Change a vital rate based on, e.g., the assumption that humans remove some predators from the environment Model tells you the new results; perhaps improved growth EE 194/Bio 196 Joel Grodstein

6 The model is agnostic Our goal may actually be reduce a population rather than increase it. Example? feral cats (colonies not socialized to humans) Doesn’t matter: population modeling is not concerned with what our goal is What we do with the numbers is up to us We can try to optimize anything we want to… …maximum population, minimum population, least year-to-year variation, … EE 194/Bio 196 Joel Grodstein

7 GIGO Predicting “what will happen if” is not always so easy
The first rule of modeling: garbage in garbage out. Just because a computer model gives you a number, doesn’t mean that it’s right. GIGO examples Leave home for Tufts, check Google maps for traffic. By the time I get to the crunch point, traffic has changed If you remove predators, you can improve vital rates. But what side effects will that have? It may be hard to predict, and some may in turn reduce vital rates Cats were removed from an island to protect sea birds, resulted in huge increase in rats, making things worse for the seabirds! So effects are hard to predict EE 194/Bio 196 Joel Grodstein

8 Start simple What goes into a population model? First-cut example:
Initial population # of births, deaths every year First-cut example: Initial population size = 100 # of deaths per year = 10% of population size # of births per year = 20% of population size Can assumptions this simple be at all accurate? Many reasons why not… but hold that for later Now let's do an example EE 194/Bio 196 Joel Grodstein

9 Population example Try these yourself now Year #1 Year #2 Year #3
# deaths = 100 * 10% = 10 # births = 100 * 20% = 20 Population size = 100 – = 110 Year #2 # deaths = 110 * 10% = 11 # births = 110 * 20% = 22 Population size = 110 – = 121 Year #3 # deaths = # births = Population size = Year #4 Parameters Initial population = 100 # of deaths per year = 10% of pop size # of births per year = 20% of pop size 121 * 10% = 12.1 Try these yourself now 121 * 20% = 24.2 What is a fractional person? 121 – = 133.1 Do we really need two decimal places? 133.1 * 10% = 13.31 133.1 * 20% = 26.62 133.1 – = Answers will depend on your application EE 194/Bio 196 Joel Grodstein

10 Population growth over time
Constant growth of 20%-10% = 10% per year Does it look like a straight line? Actually, it’s not Each year, the population is a bit bigger and the number of new individuals is thus a bit bigger This toy model is too easy  EE 194/Bio 196 Joel Grodstein

11 Improve the model Make the model more accurate by adding detail
Different age classes have different vital rates Old and very young individuals die more often In between, they give birth more often Sexes are different Only females have babies (and only at certain ages) Some diseases are linked to sex Simplify the model without losing accuracy Strange concept! But in this case… Ignore males altogether 3 babies/year per individual” becomes “3 female babies/year per female” Doesn’t the number of males affect how many females become pregnant? In some species, we can assume that there are enough males to impregnate all receptive females Common assumption in population biology (not relevant for humans!) EE 194/Bio 196 Joel Grodstein

12 Our next model Only track females
Every age has its own birth and death rates Powerful enough to model numerous effects: High death rates for old and very young individuals Higher birth rates in middle ages Can model any effect on age-dependent vital rates EE 194/Bio 196 Joel Grodstein

13 Population example Just look at deaths for now (ignore births)
Assume the “survival rate” numbers are over one year Age group Survival rate Population, 2017 2018 2019 0-1 .7 100 1-2 .8 150 2-3 200 3-4 70 100*.7 = 70 120 150*.8 = 120 160 200*.8 = 160 EE 194/Bio 196 Joel Grodstein

14 Population example Just look at deaths for now (ignore births)
Assume the “survival rate” numbers are over one year Age group Survival rate Population, 2017 2018 2019 0-1 .7 100 1-2 .8 150 2-3 200 3-4 70 120 56 70*.8 = 56 160 96 120*.8 = 96 If we keep this up over multiple years, will the population eventually shrink to 0, grow bigger and bigger, or stabilize? With deaths and no births, it must die out EE 194/Bio 196 Joel Grodstein

15 Population example Any problems with this table?
Age group Survival rate Population, 2017 2018 2019 0-1 .7 100 1-2 .8 150 70 2-3 200 230 56 3-4 160 96 Any problems with this table? We haven’t added in births yet Why is 1 year the correct interval to work at? What would happen if we re-calculated every 5 years? Unable to model some effects (in humans, newborns and 1 year olds have very different survival rates) Every day? Model might take a long time to run In most species, may be unable to get vital rates every day EE 194/Bio 196 Joel Grodstein

16 The flow of time How do you decide what granularity of time to work at? The real world is continuous time Individuals can die at any time, and many species can be born at any time Most models are discrete-time Population modeling is often at, e.g., 1-year intervals Any reason to use a finer-granularity interval? E.coli reproduce every 30 minutes Why not use continuous time? May not be able to make observations very often Simulation and optimization are often infeasible to do in continuous time EE 194/Bio 196 Joel Grodstein

17 Pulse-birth model Many population models use a pulse-birth model
All births happen in one small instant just before you do your yearly population count Does not match reality. But it does simplify the model Are any species fairly close? Pulse-birth sequencing: Individuals in any age group first progress in age (if they survive) Then, in one big pulse, some proportion of them have babies Then we count the population (Some people reverse these last two steps) Births in spring is common Many species are in fact seasonal, or pulsed breeders. E.g., temperate zone birds breed in spring/early summer. Extreme examples are cicadas, bamboo. EE 194/Bio 196 Joel Grodstein

18 Population example The next year is for you to compute Age group
Survival rate Birth rate Population 2017 2018 2019 0-1 .7 100 1-2 .8 1 150 2-3 2 200 3-4 100 individuals in 0-1 group. 100*.7=70 survive; they generate 70*1=70 babies 150 individuals in 1-2 group. 150*.8=120 survive; they generate 120*2=240 babies (310 total) 200 individuals in 2-3 group. 200*.8=160 survive; they generate 160*0=0 babies 100 individuals in 3-4 group. 100*0= none of them survive. 310 70 70 120 160 The next year is for you to compute EE 194/Bio 196 Joel Grodstein

19 Population example Population equations:
Age group Survival rate Birth rate Population 2017 2018 2019 0-1 .7 100 310 1-2 .8 1 150 70 2-3 2 200 120 3-4 160 310 individuals in 0-1 group. 310*.7=217 survive; they generate 217*1=217 babies 70 individuals in 1-2 group. 70*.8=56 survive; they generate 56*2=112 babies (329 total) 120 individuals in 2-3 group. 120*.8=96 survive; they generate 96*0=0 babies 160 individuals in 3-4 group. 160*0= none of them survive. 217 329 217 56 96 Population equations: = * survival0-1 = * survival1-2 = * survival2-3 = ( *birth1-2)+( *birth2-3)+ ( *birth3-4) EE 194/Bio 196 Joel Grodstein

20 We get twists and turns early on
EE 194/Bio 196 Joel Grodstein

21 Eventually it seems to settle out
In fact, every age is growing at roughly 46% per year. This is called exponential growth EE 194/Bio 196 Joel Grodstein

22 Viewed on a log scale, exponential growth shows each age category growing at the same rate
EE 194/Bio 196 Joel Grodstein

23 lx-mx model Definitions:
"x" is a population category. For now, let's say it's how many years old you are (e.g., “2” is from 2.0 to 2.99 years old) lx= probability of a newborn surviving to the beginning of stage x (so l2 is their odds of making it to their 2nd birthday) mx= average number of female babies a female will have while in stage x (remember, we’re completely ignoring males) nx = number of females in stage x px= probability of surviving to the end of stage x, once you reached the beginning of that stage EE 194/Bio 196 Joel Grodstein

24 lx-mx model Definitions: nx = number of females in stage x
px= probability of surviving to the end of stage x, once you reached the beginning of that stage mx= average number of babies you will have while in stage x Population equations: = * survival0-1 = * survival1-2 = * survival2-3 = ( *birth1)+( *birth2) + ( *birth3) n1,2018 n2,2018 n3,2018 n0,2018 EE 194/Bio 196 Joel Grodstein

25 lx-mx model Definitions: nx = number of females in stage x
px= probability of surviving to the end of stage x, once you reached the beginning of that stage mx= average number of babies you will have while in stage x Population equations: n1,2018 = * survival0-1 n2,2018 = * survival1-2 n3,2018 = * survival2-3 n0,2018= ( *birth1)+( *birth2) + ( *birth3) n2,2017 n0,2017 n1,2017 EE 194/Bio 196 Joel Grodstein

26 lx-mx model Definitions: nx = number of females in stage x
px= probability of surviving to the end of stage x, once you reached the beginning of that stage mx= average number of babies you will have while in stage x Population equations: n1,2018 = n0,2017 * survival0-1 n2,2018 = n1,2017 * survival1-2 n3,2018 = n2,2017 * survival2-3 n0,2018= ( *birth1)+( *birth2) + ( *birth3) n1,2018 n2,2018 n3,2018 EE 194/Bio 196 Joel Grodstein

27 lx-mx model Definitions: nx = number of females in stage x
px= probability of surviving to the end of stage x, once you reached the beginning of that stage mx= average number of babies you will have while in stage x Population equations: n1,2018 = n0,2017 * survival0-1 n2,2018 = n1,2017 * survival1-2 n3,2018 = n2,2017 * survival2-3 n0,2018= (n1,2018 *birth1)+(n2,2018 *birth2)+ (n3,2018 *birth3) p0 p1 p2 EE 194/Bio 196 Joel Grodstein

28 lx-mx model Definitions: nx = number of females in stage x
px= probability of surviving to the end of stage x, once you reached the beginning of that stage mx= average number of babies you will have while in stage x Population equations: n1,2018 = n0,2017 * p0 n2,2018 = n1,2017 * p1 n3,2018 = n2,2017 * p2 n0,2018= (n1,2018 *birth1 ) + (n2,2018 *birth2 ) + (n3,2018 *birth3 ) m1 m2 m3 EE 194/Bio 196 Joel Grodstein

29 lx-mx model Definitions: nx = number of females in stage x
px= probability of surviving to the end of stage x, once you reached the beginning of that stage mx= average number of babies you will have while in stage x Population equations: n1,2018 = n0,2017 * p0 n2,2018 = n1,2017 * p1 n3,2018 = n2,2017 * p2 n0,2018= (n1,2018*m1 )+(n2,2018*m2)+ (n3,2018*m3) EE 194/Bio 196 Joel Grodstein

30 A rose by any other name But it’s called lx-mx – why do we use px instead of lx? It all comes out in the wash l0 = likelihood of surviving from birth to the beginning of age 0 = 1 l1 = likelihood of surviving from birth to the beginning of age 1 =p0 l2 = likelihood of surviving from birth to the beginning of age 2 = l1p1 =p0p1 l3 = likelihood of surviving from birth to the beginning of age 3 =l2p2 = p0p1p2 EE 194/Bio 196 Joel Grodstein

31 Simple code Age group Survival rate Birth rate Population 2017 2018
2019 0-1 .7 100 1-2 .8 1 150 2-3 2 200 3-4 n1,2018 = n0,2017* p0 n2,2018 = n1,2017* p1 n3,2018 = n2,2017 * p2 n0,2018= (n1,2018 * m1)+(n2,2018 * m2)+ (n3,2018 * m3) n0_2017=100; n1_2017=150; n2_2017=200; n3_2017=100 p0=.7; p1=.8; p2=.8; p3=0 m0=0; m1=1; m2=2; m3=0 n1_2018 = n0_2017*p0 n2_2018 = n1_2017*p1 n3_2018 = n2_2017*p2 n0_2018 = n1_2017*m1 + n2_2017*m2 + n3_2017*m3 or n1_2018*m1 + n2_2018*m2 + n3_2018*m3 First just define our initial population and vital rates Next, the equations Which choice is correct? EE 194/Bio 196 Joel Grodstein

32 Simple code U U U U U U U U U U U U U U U U Age group Survival rate
Birth rate Population 2017 2018 2019 0-1 .7 100 310 1-2 .8 1 150 70 2-3 2 200 120 3-4 160 Simple code n0_2017=100; n1_2017=150; n2_2017=200; n3_2017=100 p0=.7; p1=.8; p2=.8; p3=0 m0=0; m1=1; m2=2; m3=0 n1_2018 = n0_2017* p0 n2_2018 = n1_2017*p1 n3_2018 = n2_2017*p2 n0_2018 = n1_2018*m1 + n2_2018*m2 + n3_2018*m3 100 U 150 U 200 U U 310 100 U U 70 120 U 160 U n0_2017 n1_2017 n2_2017 n3_2017 n0_2018 n1_2018 n2_2018 n3_2018 U .7 U .8 U .8 U U U 1 U 2 U p0 p1 p2 p3 m0 m1 m2 m3 EE 194/Bio 196 Joel Grodstein

33 Loops We have our equations
Population equations: n1,2018 = n0,2017 * p0 n2,2018 = n1,2017 * p1 n3,2018 = n2,2017 * p2 n0,2018= (n1,2018*m1 )+(n2,2018*m2)+ (n3,2018*m3) These are very useful if we know 2017 and want 2018 We often (usually) want to simulate many years into the future. So how do we compute the 2019 numbers? We need some more flexible equations EE 194/Bio 196 Joel Grodstein

34 Loops We have our equations to go from 2017 to 2018
Population equations: n1,2018 = n0,2017 * p0 n2,2018 = n1,2017 * p1 n3,2018 = n2,2017 * p2 n0,2018= (n1,2018*m1)+(n2,2018*m2)+ (n3,2018*m3) Can we rewrite this to go from 2018 to 2019? n1,2019 = n0,2018 * p0 n2,2019 = n1,2018 * p1 n3,2019 = n2,2018 * p2 n0,2019= (n1,2019*m1)+(n2,2019*m2)+ (n3,2019*m3) EE 194/Bio 196 Joel Grodstein

35 Loops Population equations from 2018 to 2019:
n1,2019 = n0,2018 * p0 n2,2019 = n1,2018 * p1 n3,2019 = n2,2018 * p2 n0,2019= (n1,2019*m1)+(n2,2019*m2)+ (n3,2019*m3) Can we rewrite this to go from 2019 to 2020? n1,2020 = n0,2019 * p0 n2,2020 = n1,2019 * p1 n3,2020 = n2,2019 * p2 n0,2020= (n1,2020*m1)+(n2,2020*m2)+ (n3,2020*m3) EE 194/Bio 196 Joel Grodstein

36 Loops Population equations from 2019 to 2020:
n1,2020 = n0,2019 * p0 n2,2020 = n1,2019 * p1 n3,2020 = n2,2019 * p2 n0,2020= (n1,2020*m1)+(n2,2020*m2)+ (n3,2020*m3) Can we rewrite this to go from year n to year n+1? n1,next = n0,now* p0 n2,next = n1,now* p1 n3,next = n2,now* p2 n0,next= (n1,next * m1)+(n2,next * m2)+ (n3,next * m3) What does this actually mean? Just that you have pretty much the same equation to go forwards a year, no matter what year it is. The “next” and “now” subscripts can be any two consecutive years EE 194/Bio 196 Joel Grodstein

37 Break to the Python Loops lecture
EE 194/Bio 196 Joel Grodstein

38 Code for loops Will this code work?
for gen in range(70): n0=100; n1=150; n2=200; n3=100 p0=.7; p1=.8; p2=.8; p3=0 m0=0; m1=1; m2=2; m3=0 n1_next = n0* p0 n2_next = n1*p1 n3_next = n2*p2 n0_next = n1_next*m1 + n2_next*m2 + n3_next*m3 Will this code work? No. After the first time through the loop, it just assigns the same values to the same variables over and over. 310 100 U 150 U 200 U 100 U U U 70 120 U 160 U n0 n1 n2 n3 n0_next n1_next n2_next n3_next EE 194/Bio 196 Joel Grodstein

39 Code for loops, take 2 Will it work now?
Still not, for the same reason. It’s a bit better, though; at least we don’t assign the p’s and m’s every time around the loop. Somehow we have to update n0, n1, n2 and n3 every time around the loop. You get to figure out how on HW1 n0=100; n1=150; n2=200; n3=100 p0=.7; p1=.8; p2=.8; p3=0 m0=0; m1=1; m2=2; m3=0 for gen in range(70): n1_next = n0* p0 n2_next = n1*p1 n3_next = n2*p2 n0_next = n1_next*m1 + n2_next*m2 + n3_next*m3 310 100 U 150 U 200 U 100 U U U 70 120 U 160 U n0 n1 n2 n3 n0_next n1_next n2_next n3_next EE 194/Bio 196 Joel Grodstein

40 Age vs. stage vs. size We’ve stated all of our vital rates per age
Different rates for 0 years old, 1 year old, etc. In some species, it makes more sense to delineate groups based on size In others, life stages is a better choice What makes size or life stage better? What does “better” mean? We want our vital rates to be accurate Birth rates and survival rates may correlate much better to size or to life stage in some species than to age Yet again: you can build whatever model you want, but it’s only really useful if it matches reality We won’t discuss stage-based models in this course EE 194/Bio 196 Joel Grodstein

41 Problems with our model
We neglected population density Nothing can really grow exponentially forever. As a population gets bigger, vital rates shrink because we run out of food, space, etc. We’ve ignored that; you can experiment with it as part of HW #1 extra credit What happens if your model ignores overcrowding? As usual: garbage in, garbage out EE 194/Bio 196 Joel Grodstein

42 Why model variation Real life is full of surprises
There are good years and bad years Some years have better weather, more food, less disease, etc. Do we need to model this? If we just pick “average” vital rates, will it all even out in the end? Is it faster to bicycle uphill and then back down, or just stay flat? Is it worse if the hill is steeper? Similar effect in investing money. Stocks pay higher returns on average than bonds but have more fluctuation, and that fluctuation usually lowers their effective return. Variation in vital rates often yields less growth than slow & steady So we usually do want to model vital-rate variation EE 194/Bio 196 Joel Grodstein

43 Stochastic models Obvious way to model variation: make the vital rates change randomly every “year” Where “year” is whatever makes sense for your problem What is the shape of your distribution? Bell-shaped curve is commonly used. Any issues? It never tails off to zero, so there is a non-zero possibility of a negative number of offspring! The “right” answer depends on your problem HW #3 will model this EE 194/Bio 196 Joel Grodstein

44 What are fractional people?
Remember our first example? 121 people in the population 10% of them die (that’s 12.1 people) 20% new births (24.1 people) Next year we have people! Any ideas what that might mean physically? It’s just wrong; we never want to deal with fractions It’s fine… we really do have fractional people walking around It represents averages (like 2.1 children per family) EE 194/Bio 196 Joel Grodstein

45 What to do with fractional people
Averages are all well and good, but what should we do in our model? Keep working with fractional people? Truncate them at every generation? So 12.9 people become 12 Round them at every generation? Then 12.9 becomes 13 Reasons to keep working with fractional people? Our vital rates are just averages anyway But sometimes we care about quantization; it causes small populations to be more vulnerable Truncate vs. round? A 0.9 person is no more viable than a .1 person On average, the .9 person is more likely to represent an entire person than a non-person HW #3 will let you program these issues EE 194/Bio 196 Joel Grodstein

46 Recap What we learned about biology What we learned about modeling
lx-mx models What we learned about modeling GIGO – when is a model valid? Desert tortoise: using models for things we cannot easily measure (and deciding if they're correct). That’s HW2. Simulating models (we did several examples) Discrete-time vs. continuous time-models stochastic and quantized models What we learned about programming The basics: variables, loops, arrays & random numbers (up next) 3 homeworks EE 194/Bio 196 Joel Grodstein


Download ppt "EE 194/Bio 196: Modeling,simulating and optimizing biological systems"

Similar presentations


Ads by Google