Exercise: Python vs R¶
Here we have provided SIR ODE model implementations in Python and in R. Each script runs several scenarios and produces a plot of infection prevalence for each scenario.
You can download each script to debug on your computer:
sir_ode.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
sir_ode.R | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
The model outputs differ!
Here are prevalence time-series plots produced by each script:
Interactive debugger sessions
If your editor supports running a debugger, use this feature! See these examples for RStudio, PyCharm, Spyder, and VS Code.
Some initial thoughts ...
-
Is it obvious whether one of the figures is correct and the other is wrong?
-
The
sir_rhs()
functions in the two scripts appear to be equivalent — but are they? -
The
default_settings()
functions appear to be equivalent — but are they? -
The
run_model_scaled_beta()
andrun_model_scaled_gamma()
functions also appear to be equivalent. -
Where might you begin looking?