Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dynamic Modeling and Python Greg Baker, November 2003.

Similar presentations


Presentation on theme: "Dynamic Modeling and Python Greg Baker, November 2003."— Presentation transcript:

1 Dynamic Modeling and Python Greg Baker, November 2003

2 Dynamic Modeling

3 Assumption: individuals make decisions to maximize reproductive fitness Need fitness of possible decisions. Need fitness of possible decisions. Look at an individual in a certain time window Maximize fitness at the end of time window. Maximize fitness at the end of time window.

4 Fitness? What determines fitness? Depends on the situation. Depends on the situation. Fat stores? Location? Stress? Not dying. Fat stores? Location? Stress? Not dying. Immediate vs. lifetime reproduction Immediate vs. lifetime reproduction Biology. Biology. Keep track of each factor for the individual. “State variables” “State variables” eg. x = energy, s = stress level eg. x = energy, s = stress level

5 Discretizing Parameters We can’t handle an infinite number of values for each state variable. We will have to pick a fixed number of values that can be used for each eg. energy, x = 0, 1, 2, 3, …, 30 eg. energy, x = 0, 1, 2, 3, …, 30 time, t = 0, 1, 2, 3, …, 20 time, t = 0, 1, 2, 3, …, 20 Examine every possible combination. Examine every possible combination.

6 Dynamic array Track fitness values for every combination Will have to be stored as we calculate Will have to be stored as we calculate Fitness: Fitness: t x 012T 0 1 2 30 … … Want t = T values big

7 Filling in the array Fitness at t = T must be determined initially An approximation of total lifetime fitness. An approximation of total lifetime fitness. Based on values of state variables. Based on values of state variables. Biology. Biology. Calculate backwards from time T to 0 and fill in the table “backwards iteration” “backwards iteration” “dynamic programming” “dynamic programming”

8 Example t x 012T 0 1 2 10 … … 0 0 0 2 2 4 0 ? Don’t eat Eat

9 Fitness function Need to calculate fitness for each possible decision … and choose the largest. … and choose the largest. How do we calculate the fitness? Fitness after the decision Fitness after the decision … adjusted by predation risk, energy loss, etc. … adjusted by predation risk, energy loss, etc. Biology. Biology.

10 Decision Variables To do useful stuff later, also store the decisions themselves Another array like the fitness one. Another array like the fitness one. Lets us look at behaviour, not just fitness. Next week. Next week.

11 Linear Interpolation We might get a fractional value for some variable eg. After 1 time unit, x goes from 5 to 4.8 eg. After 1 time unit, x goes from 5 to 4.8 No x = 4.8 entry in the array Approximate from surrounding values. Approximate from surrounding values. X 45 f 4.8 f(4.8) ≈ 0.2 f(4) + 0.8 f(5)

12 Two Dimensional Same idea, but more complicated with two state variables.

13 Python Programming

14 First steps Programming Giving instructions to a computer to carry out calculations for you. Giving instructions to a computer to carry out calculations for you. Why Python? Free, widely available Free, widely available Easy to read/learn Easy to read/learn Good free documentation Good free documentation

15 Python Example 1 Code: for i in range(3): print i print iOutput:012

16 Python Example 2 Code:x=2 if x<5: if x<5: print "Yes" print "Yes" else: else: print "No" print "No"Output:Yes

17 Example Model #1 Patch selection from Clark, Mangel Individual has 3 choices each day: Visit feeding patch A (decision 0) Visit feeding patch A (decision 0) Visit feeding patch B (decision 1) Visit feeding patch B (decision 1) Visit reproductive patch (decision 2) Visit reproductive patch (decision 2)Variables: t: time in 1 day increments t: time in 1 day increments x: energy from 0-30. x: energy from 0-30.

18 Example Model #2 Seal foraging from Alejandro Variables: t: time in 10s intervals t: time in 10s intervals x: energy from 1-10 x: energy from 1-10 t: oxygen from 1-10 t: oxygen from 1-10 h: habitat (0=haulout, 1=surface, 2=diving) h: habitat (0=haulout, 1=surface, 2=diving)

19 On to the code…


Download ppt "Dynamic Modeling and Python Greg Baker, November 2003."

Similar presentations


Ads by Google