lpnguyen commited on
Commit
9ebc767
1 Parent(s): 15c8365

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -18
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import streamlit as st
2
- from dynamical_system import invasion_fitness, invasion_fitness2, pop_dynamics2
3
  import numpy as np
4
  from tools import plot_3D_invfitness, plot_invasionfitness, make_interactive_video, plot_PIP
5
  from scipy.integrate import solve_ivp
@@ -41,7 +41,8 @@ inv_fitness3D = invasion_fitness(X, Y, pars=alpha)
41
  st.write("Invasion process video")
42
 
43
  st.plotly_chart(
44
- make_interactive_video(0.01, zlist[-1], 50, zlist, invasion_fitness, alpha, [-2, 2])
 
45
  )
46
 
47
 
@@ -68,7 +69,8 @@ zm = st.slider("Mutant trait value", 0.0, 2.0, value=0.2, step=0.01)
68
 
69
  col1, col2, col3 = st.columns(3)
70
  with col1:
71
- st.plotly_chart(plot_invasionfitness(zm, zlist, invasion_fitness, alpha, [-2, 2]))
 
72
  with col2:
73
  st.plotly_chart(plot_PIP(zlist, invasion_fitness, alpha))
74
  with col3:
@@ -110,7 +112,8 @@ ndsol = solve_ivp(
110
  col5, col6 = st.columns(2, gap="large")
111
  with col5:
112
  if ndsol.y[0, -1] > 0:
113
- st.write("The population density reaches", ndsol.y[0, -1])
 
114
  else:
115
  st.write("The population density reaches", 0)
116
  st.plotly_chart(
@@ -131,34 +134,57 @@ with col6:
131
  )
132
  )
133
 
134
- col7, col8 = st.columns(2, gap="large")
135
- with col7:
136
- st.write("Invasion process video")
137
- z_start = st.number_input(
138
- "Enter the start value of z then click play", 1e-5, 1.0, 0.1, step=0.01
139
- )
 
 
 
 
 
 
140
  st.plotly_chart(
141
  make_interactive_video(
142
- z_start, z_star, 20, zlist, invasion_fitness2, (alpha, beta), [-0.2, 0.2]
 
143
  )
144
  )
145
- with col8:
 
 
 
 
146
  zm2 = st.slider("Mutant trait value", 0.0, 1.0, value=0.1, step=0.01)
147
 
148
- st.plotly_chart(plot_invasionfitness(zm2, zlist, invasion_fitness2, (alpha, beta), [-0.2, 0.2]))
 
149
 
150
  X, Y = np.meshgrid(zlist, zlist)
151
  inv_fitness3D2 = invasion_fitness2(X, Y, pars=(alpha, beta))
152
 
153
- col9, col10 = st.columns(2, gap="large")
154
- range = (np.min(inv_fitness3D2) - np.mean(inv_fitness3D2) - 1e-5, np.max(inv_fitness3D2))
 
 
155
  with col9:
156
  st.plotly_chart(plot_3D_invfitness(zlist, inv_fitness3D2, zm, range))
157
- with col10:
158
- st.plotly_chart(plot_PIP(zlist, invasion_fitness2, (alpha, beta)))
159
-
160
 
161
  st.header("Assymetric competition")
 
 
 
 
 
 
 
 
 
 
 
 
162
  zlist = np.linspace(-3, 3, 100)
163
  inv_fitness3D3 = invasion_fitness3(zlist, zlist, (0, 2.4))
164
  st.plotly_chart(plot_PIP(zlist, invasion_fitness3, (0, 2.4)))
 
1
  import streamlit as st
2
+ from dynamical_system import invasion_fitness, invasion_fitness2, invasion_fitness3, pop_dynamics2
3
  import numpy as np
4
  from tools import plot_3D_invfitness, plot_invasionfitness, make_interactive_video, plot_PIP
5
  from scipy.integrate import solve_ivp
 
41
  st.write("Invasion process video")
42
 
43
  st.plotly_chart(
44
+ make_interactive_video(
45
+ 0.01, zlist[-1], 50, zlist, invasion_fitness, alpha, [-2, 2])
46
  )
47
 
48
 
 
69
 
70
  col1, col2, col3 = st.columns(3)
71
  with col1:
72
+ st.plotly_chart(plot_invasionfitness(
73
+ zm, zlist, invasion_fitness, alpha, [-2, 2]))
74
  with col2:
75
  st.plotly_chart(plot_PIP(zlist, invasion_fitness, alpha))
76
  with col3:
 
112
  col5, col6 = st.columns(2, gap="large")
113
  with col5:
114
  if ndsol.y[0, -1] > 0:
115
+ st.write(
116
+ r"The population density reaches $\frac{z_r - z_r^\beta}{\alpha}$ = ", ndsol.y[0, -1])
117
  else:
118
  st.write("The population density reaches", 0)
119
  st.plotly_chart(
 
134
  )
135
  )
136
 
137
+ st.write("Invasion process video")
138
+ z_start = st.number_input(
139
+ "Enter the start value of z then click play", 1e-5, 1.0, 0.1, step=0.01
140
+ )
141
+ if z_start - z_start**beta < 0:
142
+ st.write("Population goes extinct")
143
+ else:
144
+ if beta > 1:
145
+ z_end = z_star
146
+ elif beta < 1:
147
+ zlist = np.linspace(0, 2, 100)
148
+ z_end = zlist[-1]
149
  st.plotly_chart(
150
  make_interactive_video(
151
+ z_start, z_end, 20, zlist, invasion_fitness2, (alpha, beta), [
152
+ -0.2, 0.2]
153
  )
154
  )
155
+
156
+ st.write("Now try yourself with the step by step invasion replacement process to verify the video")
157
+ col7, col8, col9 = st.columns(3, gap="large")
158
+
159
+ with col7:
160
  zm2 = st.slider("Mutant trait value", 0.0, 1.0, value=0.1, step=0.01)
161
 
162
+ st.plotly_chart(plot_invasionfitness(
163
+ zm2, zlist, invasion_fitness2, (alpha, beta), [-0.2, 0.2]))
164
 
165
  X, Y = np.meshgrid(zlist, zlist)
166
  inv_fitness3D2 = invasion_fitness2(X, Y, pars=(alpha, beta))
167
 
168
+ range = (np.min(inv_fitness3D2) - np.mean(inv_fitness3D2) -
169
+ 1e-5, np.max(inv_fitness3D2))
170
+ with col8:
171
+ st.plotly_chart(plot_PIP(zlist, invasion_fitness2, (alpha, beta)))
172
  with col9:
173
  st.plotly_chart(plot_3D_invfitness(zlist, inv_fitness3D2, zm, range))
 
 
 
174
 
175
  st.header("Assymetric competition")
176
+
177
+ st.write(r"""
178
+ Assymetric competition results in evolutionary branching
179
+
180
+ Now the intrinsic growth rate is no longer a linear function of the trait z. It follows a Gaussian distribution.
181
+
182
+ $\frac{dn_r}{dt} = (\rho(z) - \alpha(\delta_z) n_r) n_r$
183
+
184
+ where $\rho(z) = e^{-(z - z_0)^2}$ is a Gaussian function.
185
+
186
+
187
+ """)
188
  zlist = np.linspace(-3, 3, 100)
189
  inv_fitness3D3 = invasion_fitness3(zlist, zlist, (0, 2.4))
190
  st.plotly_chart(plot_PIP(zlist, invasion_fitness3, (0, 2.4)))