Falcons And Mice

See if we can come up with the correct parameters to model a falcon-mouse predator-prey interaction. Here is a nice Wikipedia entry on Lotka-Volterra, a thing of true beauty.

The Notation

Let's try to line up with the Wikipedia article. Keep in mind they (Wikipedia) are using $x$ to be the number of prey, here mice. They are using $y$ to mean predator, here falcons. The lower-case Greek letter "delta" is $\partial$. In math, we used $\partial$ to mean "change in. So when I write $\partial x$ I mean "the change in the number of mice".

Also, in math, we like to be very precise about what exactly changed. I said the number of mice changed, but what do I mean by that? Do I mean it changed when the weather got hotter? Do I mean the number changed when I looked under a rock? What else changed to change the number of mice?

$$ \frac{\partial \mbox{Number of Rabbits}}{\partial \mbox{Number of Rocks I Looked Under}} $$

This tells me: The number of mice changes when I look under more or fewer rocks. If I look under more, the number goes up, if I look under fewer, the number goes down. Typical we say "with respect to" in describing that relationship. So I'd say "The change in the number of rabbits with respect to the number of rocks I looked under."

Probably the most common thing to change "with respect to" is time. A lot of things change over time. Your height, your age, how hungry you are. Suppose $h$ is how hungry you are and $t$ is time. Then

$$ \frac{\partial h}{\partial t} $$

is going up before dinner, since you are getting hungrier, and goes down at dinner, since you are getting full.

Quick Check

Above, I used the letter $h$ to mean how $h$ungry you are. Since $\partial$ means "change", I used $\partial h$ to mean "the change in hunger".

Questions

  1. If $f$ stands for "fun", what does $\frac{\partial f}{\partial t}$ mean?

More About Mice

The notation $\frac{\partial x}{\partial t}$ means "the change in x over time". And they are using $x$ to be the number of prey, here mice. So we can interpret "the change in x over time" to be "how many mice were born today". What if $x$ is negative, like $-2$? Then, sadly, two mice died today. Don't worry, the mice will make more.

How is this guy $\frac{\partial x}{\partial t}$

  • The term $$\frac{dx}{dt}$$ means the "change in x over time", and they are using "x" to mean the number of prey, here mice.

The term dy/dt means the "change in y over time", and they are using "y" to mean the number of predators, here falcons. $$ \begin{eqnarray*} \mbox{change in mouse population over time} &=& \mbox{mice surviving from yesterday} - \mbox{mice eaten}\\ \frac{d x}{dt} &=& \alpha x - \beta x y, \\ \end{eqnarray*} $$

And the falcons are governed by

A B C D
English $\frac{dy}{dt}$ = $\delta x y - \gamma y$
\begin{tabular}{l r c l} \mbox{English:} & \mbox{change in falcon population over time} &=& \mbox{falcons who ate yesterday} - \mbox{falcons who die}\\ \mbox{Math:} & $\frac{dy}{dt}$ &=& $\delta x y$ - $\gamma y$ \end{tabular}
  • $\alpha$: Mouse reproductive rate
  • $\beta$: Success rate of predators
  • $\delta$: Growth rate of predators from eating prey
  • $\gamma$: Death rate of predators

Prep stuff

First, set the working directory. Not actually sure we'll need to do this


In [ ]:
WD = "/Users/buddha/github/buddha314/predator-prey/src"
setwd(WD)

Parameters

We need to know a bit about each species, like how effectively can Falcons hunt and how effectively mice can reproduce.


In [ ]:
# Decide how effective everyone is
falcon_hunting_success_rate = 0.005
falcon_reproductive_rate = 0.001

mouse_reproductive_rate = 0.4

# What does it look like on day one?
n_falcons_day_one = 10
n_mice_day_one = 300
n_days_to_run = 60

Prep

Create a data frame for populating the results


In [ ]:
results = data.frame(
  day=1
, falcons=n_falcons_day_one
, falcons_fed = n_falcons_day_one
, falcons_born = 0
, mice=n_mice_day_one
, mice_born = 0
, mice_eaten = 0
)

The Simulation

Okay, run it! See what we come up with


In [ ]:
for (i in 2:n_days_to_run) {
  print(paste("Evaluating day", i)) 
  # Look at what we had yesterday
  falcons_yesterday = results[(i-1),"falcons"]
  mice_yesterday = results[(i-1), "mice"]
  
  # Figure out how many survived from yesterday
  falcons_born = falcons_yesterday * falcon_reproductive_rate # How many born yestery
  falcons_fed =  falcons_yesterday * falcon_hunting_success_rate * mice_yesterday # How many got to eat
  # So today we have
  falcons_today = falcons_fed + falcons_born
  
  mice_born = mice_yesterday * mouse_reproductive_rate # How many born
  # Below we use "min" to say that the falcons can't eat more mice than exist
  mice_eaten = min(mice_yesterday, mice_yesterday * falcons_yesterday * (1-falcon_hunting_success_rate)) # How many did the falcons get
  # So today we have
  mice_today = mice_yesterday + mice_born - mice_eaten
  

  # Add the new numbers to our results.  We use the max(x,y) function to keep things above 0,
  # you can't have -1 falcons
  results = rbind(
      results
    , data.frame(day=i
                 , falcons=max(0,falcons_today)
                 , falcons_born = max(0,falcons_born) 
                 , falcons_fed = max(0,falcons_fed)
                 , mice=max(0,mice_today)
                 , mice_born = max(0,mice_born)
                 , mice_eaten = max(0,mice_eaten)
                 )
  )
  
}

Results Table

This will output one row for every day of the simulation.


In [1]:
print(results)


[1] "Evaluating day 2"
[1] "Evaluating day 3"
[1] "Evaluating day 4"
[1] "Evaluating day 5"
[1] "Evaluating day 6"
[1] "Evaluating day 7"
[1] "Evaluating day 8"
[1] "Evaluating day 9"
[1] "Evaluating day 10"
[1] "Evaluating day 11"
[1] "Evaluating day 12"
[1] "Evaluating day 13"
[1] "Evaluating day 14"
[1] "Evaluating day 15"
[1] "Evaluating day 16"
[1] "Evaluating day 17"
[1] "Evaluating day 18"
[1] "Evaluating day 19"
[1] "Evaluating day 20"
[1] "Evaluating day 21"
[1] "Evaluating day 22"
[1] "Evaluating day 23"
[1] "Evaluating day 24"
[1] "Evaluating day 25"
[1] "Evaluating day 26"
[1] "Evaluating day 27"
[1] "Evaluating day 28"
[1] "Evaluating day 29"
[1] "Evaluating day 30"
[1] "Evaluating day 31"
[1] "Evaluating day 32"
[1] "Evaluating day 33"
[1] "Evaluating day 34"
[1] "Evaluating day 35"
[1] "Evaluating day 36"
[1] "Evaluating day 37"
[1] "Evaluating day 38"
[1] "Evaluating day 39"
[1] "Evaluating day 40"
[1] "Evaluating day 41"
[1] "Evaluating day 42"
[1] "Evaluating day 43"
[1] "Evaluating day 44"
[1] "Evaluating day 45"
[1] "Evaluating day 46"
[1] "Evaluating day 47"
[1] "Evaluating day 48"
[1] "Evaluating day 49"
[1] "Evaluating day 50"
[1] "Evaluating day 51"
[1] "Evaluating day 52"
[1] "Evaluating day 53"
[1] "Evaluating day 54"
[1] "Evaluating day 55"
[1] "Evaluating day 56"
[1] "Evaluating day 57"
[1] "Evaluating day 58"
[1] "Evaluating day 59"
[1] "Evaluating day 60"
   day      falcons  falcons_fed falcons_born         mice    mice_born
1    1 1.000000e+01 1.000000e+01 0.000000e+00   300.000000    0.0000000
2    2 1.501000e+01 1.500000e+01 1.000000e-02   120.000000  120.0000000
3    3 9.021010e+00 9.006000e+00 1.501000e-02    48.000000   48.0000000
4    4 2.174063e+00 2.165042e+00 9.021010e-03    19.200000   19.2000000
5    5 2.108842e-01 2.087101e-01 2.174063e-03     7.680000    7.6800000
6    6 8.308836e-03 8.097951e-03 2.108842e-04     9.140508    3.0720000
7    7 3.880437e-04 3.797349e-04 8.308836e-06    12.721144    3.6562031
8    8 2.506984e-05 2.468180e-05 3.880437e-07    17.804689    5.0884574
9    9 2.256874e-06 2.231804e-06 2.506984e-08    24.926121    7.1218757
10  10 2.835324e-07 2.812755e-07 2.256874e-09    34.896513    9.9704483
11  11 4.975499e-08 4.947146e-08 2.835324e-10    48.855109   13.9586053
12  12 1.220368e-08 1.215393e-08 4.975499e-11    68.397150   19.5420434
13  13 4.185689e-09 4.173486e-09 1.220368e-11    95.756009   27.3588598
14  14 2.008210e-09 2.004024e-09 4.185689e-12   134.058412   38.3024034
15  15 1.348096e-09 1.346087e-09 2.008210e-12   187.681776   53.6233646
16  16 1.266413e-09 1.265065e-09 1.348096e-12   262.754486   75.0727103
17  17 1.665045e-09 1.663778e-09 1.266413e-12   367.856280  105.1017944
18  18 3.064151e-09 3.062486e-09 1.665045e-12   514.998791  147.1425120
19  19 7.893234e-09 7.890170e-09 3.064151e-12   720.998306  205.9995166
20  20 2.846294e-08 2.845504e-08 7.893234e-12  1009.397623  288.3993225
21  21 1.436806e-07 1.436521e-07 2.846294e-11  1413.156644  403.7590493
22  22 1.015359e-06 1.015216e-06 1.436806e-10  1978.419100  565.2626576
23  23 1.004505e-05 1.004403e-05 1.015359e-09  2769.784741  791.3676398
24  24 1.391231e-04 1.391131e-04 1.004505e-08  3877.670953 1107.9138962
25  25 2.697508e-03 2.697369e-03 1.391231e-07  5428.202558 1551.0683813
26  26 7.321579e-02 7.321310e-02 2.697508e-06  7584.914175 2171.2810233
27  27 2.776751e+00 2.776678e+00 7.321579e-05 10066.321008 3033.9656701
28  28 1.397611e+02 1.397583e+02 2.776751e-03  4026.528403 4026.5284030
29  29 2.813900e+03 2.813760e+03 1.397611e-01  1610.611361 1610.6113612
30  30 2.266331e+04 2.266050e+04 2.813900e+00   644.244544  644.2445445
31  31 7.302623e+04 7.300357e+04 2.266331e+01   257.697818  257.6978178
32  32 9.416653e+04 9.409350e+04 7.302623e+01   103.079127  103.0791271
33  33 4.862719e+04 4.853302e+04 9.416653e+01    41.231651   41.2316508
34  34 1.007352e+04 1.002490e+04 4.862719e+01    16.492660   16.4926603
35  35 8.407695e+02 8.306960e+02 1.007352e+01     6.597064    6.5970641
36  36 2.857382e+01 2.773305e+01 8.407695e-01     2.638826    2.6388257
37  37 4.055805e-01 3.770067e-01 2.857382e-02     1.055530    1.0555303
38  38 2.546093e-03 2.140512e-03 4.055805e-04     1.051780    0.4222121
39  39 1.593575e-05 1.338965e-05 2.546093e-06     1.469828    0.4207122
40  40 1.330498e-07 1.171140e-07 1.593575e-08     2.057736    0.5879312
41  41 1.501956e-09 1.368907e-09 1.330498e-10     2.880830    0.8230944
42  42 2.313636e-11 2.163440e-11 1.501956e-12     4.033162    1.1523320
43  43 4.896998e-13 4.665635e-13 2.313636e-14     5.646427    1.6132648
44  44 1.431497e-14 1.382527e-14 4.896998e-16     7.904998    2.2585708
45  45 5.801140e-16 5.657991e-16 1.431497e-17    11.066997    3.1619991
46  46 3.268071e-17 3.210060e-17 5.801140e-19    15.493795    4.4267987
47  47 2.564422e-18 2.531742e-18 3.268071e-20    21.691314    6.1975182
48  48 2.806929e-19 2.781284e-19 2.564422e-21    30.367839    8.6765255
49  49 4.290087e-20 4.262018e-20 2.806929e-22    42.514975   12.1471357
50  50 9.162548e-21 9.119647e-21 4.290087e-23    59.520965   17.0059899
51  51 2.735981e-21 2.726819e-21 9.162548e-24    83.329351   23.8083859
52  52 1.142674e-21 1.139938e-21 2.735981e-24   116.661091   33.3317402
53  53 6.676704e-22 6.665277e-22 1.142674e-24   163.325527   46.6644363
54  54 5.459058e-22 5.452381e-22 6.676704e-25   228.655738   65.3302108
55  55 6.246684e-22 6.241225e-22 5.459058e-25   320.118033   91.4622952
56  56 1.000463e-21 9.998380e-22 6.246684e-25   448.165246  128.0472133
57  57 2.242864e-21 2.241863e-21 1.000463e-24   627.431345  179.2660986
58  58 7.038457e-21 7.036214e-21 2.242864e-24   878.403883  250.9725380
59  59 3.092008e-20 3.091304e-20 7.038457e-24  1229.765436  351.3615532
60  60 1.901531e-19 1.901222e-19 3.092008e-23  1721.671611  491.9061745
     mice_eaten
1  0.000000e+00
2  3.000000e+02
3  1.200000e+02
4  4.800000e+01
5  1.920000e+01
6  1.611492e+00
7  7.556724e-02
8  4.911678e-03
9  4.441289e-04
10 5.597383e-05
11 9.844820e-06
12 2.418632e-06
13 8.305236e-07
14 3.988009e-07
15 2.678714e-07
16 2.517479e-07
17 3.310919e-07
18 6.094347e-07
19 1.570144e-06
20 5.662553e-06
21 2.858677e-05
22 2.020279e-04
23 1.998762e-03
24 2.768351e-02
25 5.367764e-01
26 1.456941e+01
27 5.525588e+02
28 1.006632e+04
29 4.026528e+03
30 1.610611e+03
31 6.442445e+02
32 2.576978e+02
33 1.030791e+02
34 4.123165e+01
35 1.649266e+01
36 6.597064e+00
37 2.638826e+00
38 4.259619e-01
39 2.664541e-03
40 2.330569e-05
41 2.724124e-07
42 4.305246e-09
43 9.284613e-11
44 2.751229e-12
45 1.125940e-13
46 6.388020e-15
47 5.038166e-16
48 5.534756e-17
49 8.481415e-18
50 1.814810e-18
51 5.426369e-19
52 2.268476e-19
53 1.326390e-19
54 1.085024e-19
55 1.242004e-19
56 1.989678e-19
57 4.461307e-19
58 1.400207e-18
59 6.151695e-18
60 3.783432e-17

In [6]:
plot(falcons ~ day, type="l", col="gold", data=results)
lines(mice ~ day, col="blue", data=results)