-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13 Landscapes and Complex Systems.jl
3155 lines (2494 loc) · 116 KB
/
13 Landscapes and Complex Systems.jl
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
### A Pluto.jl notebook ###
# v0.19.24
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local iv = try Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value catch; b -> missing; end
local el = $(esc(element))
global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : iv(el)
el
end
end
# ╔═╡ 30b13841-97f1-47ab-a5c9-346ea8261f03
using Plots, PlutoUI, ParameterizedFunctions, DifferentialEquations
# ╔═╡ 3aee4ef3-15bc-435f-89bb-c07a17c72021
using CairoMakie
# ╔═╡ 64b8c8d1-91d2-4cb7-bf20-84fa04eeb738
begin
#using Gadfly
using Random
function F(x,parms)
(S,I,R) = x
(beta,gamma) = parms
infection = beta*S*I
recovery = gamma*I
[infection,recovery]
end
x0 = [999,1,0]
nu = [[-1 1 0];[0 -1 1]]
parms = [0.1/1000.0,0.01]
tf = 250.0
Random.seed!(1234)
result = ssa(x0,F,nu,parms,tf)
data = ssa_data(result)
plot_theme = Theme(
panel_fill=colorant"white",
default_color=colorant"black"
)
pppp=plot(data,
layer(x=:time,y=:x1,Geom.step,Theme(default_color=colorant"red")),
layer(x=:time,y=:x2,Geom.step,Theme(default_color=colorant"orange")),
layer(x=:time,y=:x3,Geom.step,Theme(default_color=colorant"blue")),
Guide.xlabel("Time"),
Guide.ylabel("Number"),
Guide.title("SSA simulation"),
Guide.manual_color_key("Subpopulation",["S","I","R"],["red","orange","blue"]),
plot_theme
)
end
# ╔═╡ c8765318-d2d1-4af4-8604-c363038018b7
html"<button onclick='present()'>present</button>"
# ╔═╡ 01bab882-2588-4d5d-8808-cdd4aaa23a47
#Pkg.add("Gillespie")
# ╔═╡ 3878c1bf-64fd-403a-aab1-dd5364588744
#import Pkg; Pkg.add("Gillespie")
# ╔═╡ 190cc65b-0fad-4150-98f8-0494cc018636
html"<button onclick='present()'>present</button>"
# ╔═╡ 7c9d5d2d-9d2f-4490-a891-eaffa42e6cca
begin
struct Foldable{C}
title::String
content::C
end
function Base.show(io, mime::MIME"text/html", fld::Foldable)
write(io,"<details><summary>$(fld.title)</summary><p>")
show(io, mime, fld.content)
write(io,"</p></details>")
end
end
# ╔═╡ 24a0dea7-bbd3-4eaa-8d69-c78e2a484534
md"## Other tools
Often times, the linearization approach does not succesfully recovers the dynamcis of teh system of interest, maybe becausde we are not close to a steady state (where perturbations behave as in the linear system). In thsi case, we can use other mathematical tools,. Apart from linear stability analysis and other mathematical tools, there are other common approaches.
- Lyapunov exponents
- Poincaré maps
- Numerical simulations
- Agent base models
- Null Clines, Phase potraits and lansdcapes
### Lyapunov exponents
Lyapunov stability theory is a standard tool and one of the most important tools in the analysis of nonlinear systems. The Lyapunov exponent of a dynamical system is a quantity that characterizes the rate of separation of infinitesimally close trajectories.
### Poincaré maps
Poincaré map represents the intersection of a periodic orbit in the state space of a continuous dynamical system with a certain lower-dimensional subspace (a 3D orbit and a plane), called the Poincaré section, transversal to the flow of the system. A Poincaré maps can be interpreted as a discrete dynamical system with a state space that is one dimension smaller than the original continuous dynamical system. Because it preserves many properties of periodic and quasiperiodic orbits of the original system and has a lower-dimensional state space, it is often used for analyzing the original system in a simpler way.
### Numerical simulations
If we do have teh differential equations, but these are not analitically solvable, a common approac is to simulate the dynamics just by intergrating the differential equations numerically. For instance, in this model of interactions between two species (cubic autocatalator model)
```math
\begin{eqnarray}
\frac{\partial x}{\partial t} = x^2 y -x \\
\frac{\partial y}{\partial t} = \mu - x^2 y
\end{eqnarray}
```
we need the initial conditions
"
# ╔═╡ 95aa2183-e03c-41a7-98f9-1ad074ba3baa
Cubic! = @ode_def Cubic begin
dX = µ - X * Y^2 - r * X
dY = X * Y^2 - Y + r * X
end µ r
# ╔═╡ 52b75ad6-d1ad-4f33-ad7d-2089f02ca6a7
begin
µ_slide = @bind µ html"<input type=range min=0.0 max=3.0 step=.1>"
r_slide = @bind r html"<input type=range min=0.0 max=3.0 step=.1>"
md"""
**Set the values of the kinetic constants**
value of µ: $(µ_slide)
value of r: $(r_slide)
"""
end
# ╔═╡ 43f4f9de-a09a-43ae-8383-06d3a3be3589
begin
prob3 = ODEProblem(Cubic!,[0.0,0.0],(0.0,50.0),[µ,r])
sol3 = solve(prob3)
Plots.plot(sol3,label=["X" "Y"])
title!("Cubic Autocatalator")
Plots.xlabel!("Time [s]")
Plots.ylabel!("Concentration [a.u]")
end
# ╔═╡ de58d9dd-dc03-44b0-bc6a-6068d3ff9d28
md" ### Models of partial differential equations
(reaction-diffusion-flow)
The Diffusion Equation is a partial differential equation which describes changes in concentratio
n of a substance that diffusing in a spatial system. When the diffusion coefficient `D` of the substance `u` is constant throughout the system, the diffusion equation takes the form.
```math
\begin{equation}
\frac{\partial u}{\partial t} = D \frac{ \partial^2 u}{\partial x^2} \tag{1}
\end{equation}
```
This equation is also called the Heat Equation, since it also describes the distribution of a heat in a given region over time. It is also Fick’s second law. To solve these type of equations, we need to now the initial conditions, as well as the boundary condition, i.e., the value of `u` at the two edges of the system: `u(0)` and `u(L)`. Let’s assume that the value of `u` is constant in one of the edges with a value `u_0`. This is equivalent to assume that our substance `u` is being produced at one side of the system. Let's also assume that at the other edge, `u` disappears or is being consumed, so `u(L)=0`. Therefore, our boundary conditions are $u(0,t)=u_0$ and $u(L,t)=0$.
If we want to find the steady state solution we obtain:
```math
\begin{equation}
\frac{\partial u}{\partial t} = D \frac{ \partial^2 u}{\partial x^2} =0 \tag{2}
\end{equation}
```
In this condition, Fick’s second law is reduced to Laplace’s equation, $\nabla^2 u= 0$. It follows that $u=C_1 x + C_2$, where $C_1$ and $C_2$ are intergration constants that we can find using the boundary conditions.
```math
\begin{equation}
u(0)=C_1 \cdot 0 + C_2 = C_2\\
u(L)= 0 = C_1 \cdot L + C_2 = C_1 \cdot L + u(0) \\
C_1 = -\frac{u(0)}{L} \tag{3}
\end{equation}
```
so the solution of the gradient is simply a straight line when the system is stable, such as:
```math
u_{ss}(x)= - \frac{u(0)}{L} x + u(0)=u(0)(1-\frac{x}{L}) \tag{4}
```
"
# ╔═╡ 40bac874-8e71-4a45-9fd6-fd6b5f673b16
md"
Quite often in biology, these diffusing substances or morphogens interact with other substances or receptor molecules, or are being internalized by cells, or simply degraded constantly in the systems. To study this type of systems we use a class of partial differential equations (PDE's) called Reaction-Diffusion Equations. These type of equations are used to describe the diffusion (spreading out) and reaction of one or several chemical species.
In the simplest one-dimensional case and one single substance, let `u(x,t)` be the concentration of `u` at location `x` at time `t`. Then, the reaction-diffusion equation has the form:
```math
\begin{equation} \frac{\partial u}{\partial t} = \underbrace{D_u \frac{\partial^2 u}
{\partial x^2}}_{\text{Diffusion}} + \overbrace{f(u)}^{\text{Reaction}} \tag{5}
\end{equation}
```
where `D` is a coefficient associated with the diffusive properties of `u`, and `f(u)` is a function that describes how `u` grows or decays depending on its current state.
## Degradation or clearance
Lets for now consider the simplest reaction where `u` is simply being consumed in the extended system with a constant rate. This is a very common scenario for morphogens, that are consumed by the cells as they process the information:
```math
u \overset{k}{\longrightarrow} 0 \tag{6}
```
so, the reaction term is $f(u) = - k \cdot u$. In this case, in a a-dimensional system, (no diffusion), the system is described by a single first order differential equation.
```math
\frac{\mathrm{d} u}{\mathrm{d} t} = - k \cdot u \tag{7}
```
with a solution
```math
u (t)= u (0) \cdot e^{- k t} \tag{8}
```
When we combine both diffusion and degradation we have the following equation:
```math
\begin{equation}
\frac{\partial u(x,t)}{\partial t} = D \frac{ \partial^2u(x,t)}{\partial x^2} - k \cdot u(x,t) \tag{9}
\end{equation}
```
if we look for the steady state solution
```math
\begin{equation}
\frac{ \partial^2u(x,t)}{\partial x^2} = \frac{k}{D} u(x,t) \tag{10}
\end{equation}
```
where, the second derivative of `u` with respect to `x` is proportional to itself. The only functions for `u` with this property are exponential functions. Therefore, one can propose a general solution for `u` :
```math
u= C_1 \cdot e^{-x/\lambda} + C_2 e^{+x/\lambda} \tag{11}
```
if we test if the previous equation is a solution, the first derivative:
```math
\frac{ \partial u(x,t)}{\partial x}=-\frac{C_1}{\lambda} \cdot e^{-x/\lambda} + \frac{C_2}{\lambda} e^{+x/\lambda} \tag{12}
```
and the second derivative
```math
\frac{ \partial^2 u(x,t)}{\partial^2 x}=\frac{C_1}{\lambda^2} \cdot e^{-x/\lambda} + \frac{C_2}{\lambda^2} e^{+x/\lambda} \tag{13}
```
rearranging terms
```math
\frac{ \partial^2 u(x,t)}{\partial^2 x}=\frac{1}{\lambda^2}(C_1 \cdot e^{-x/\lambda} + C_2 e^{+x/\lambda})=\frac{u}{\lambda^2} \tag{4}
```
using the Eq 10. we arrive at the condition for the solution
```math
\frac{u(x,t)}{\lambda^2}=\frac{k}{D} u(x,t) \tag{15}
```
so, the characteristic length of the exponential
```math
\lambda = \sqrt{\frac{D}{k}} \tag{16}
```
To determine the constants $C_1$ and $C_2$, we need two equations. We use the two boundary conditions used for the case of only diffusion.
```math
u(0,t)_{ss}= C_1 \cdot e^{-0/\lambda} + C_2 e^{+0/\lambda}= C_1 + C_2 = u_0 \tag{17}
```
```math
u(L,t)_{ss}= C_1 \cdot e^{-L/\lambda} + C_2 e^{+L/\lambda}= 0 \tag{18}
```
for the case that the dimensions are much larger than the characteristic length of the exponential, the second term of the equation goes to infinite, so $C_2$ has to be zero. Therefore $ C_1=u_0 $ and the solution of the stable gradient is a single exponential:
```math
\begin{equation} u(x,t)_{ss} = u_0 e^{-x\sqrt{\frac{k}{D}}} \tag{19}
\end{equation}
```
"
# ╔═╡ dad48b2a-201f-40d1-a515-347b5fbc15bc
begin
## spatial scaling
number_of_steps=100;
size_of_system=100;
space_step=size_of_system/number_of_steps;
x_vector = LinRange(0,size_of_system,number_of_steps)
## temporal scaling
number_of_iterations=1000;
total_time=70;
time_step=total_time/number_of_iterations;
## Parameters and initial conditions
Diff=10; # ?m^2/min
k=0.1
u=zeros(1,number_of_steps)
u[1]=1;
u_=u;
plt2=Plots.plot(x_vector,u')
end
# ╔═╡ e6b6aa9f-f3c6-4f4a-92dd-b881c61f7df9
begin
for ii=1:number_of_iterations
for i=2:number_of_steps-1
u[i]= u_[i] + time_step *(-k*u_[i]+ Diff * (u_[i-1]-2*u_[i]+u_[i+1])/(space_step*space_step));
end
u[1]=1; # fixed boundary conditions
u[number_of_steps]=0; # fixed boundary conditions
#u[1]=u[2]; # zero flux boundary conditions
#u[number_of_steps]=u[number_of_steps-1]; # zero flux boundary conditions
#u[1]=u[number_of_steps]; # periodic boundary conditions
u_=u;
if ii% 10 == 0
plt2=Plots.plot!(x_vector,u',legend=false)
end
end
#show(plt2)
#Plots.plot!(x_vector,u')
end
# ╔═╡ 903e68f4-7766-43bd-bfa0-018140101606
Plots.plot!(x_vector,x_vector->1*exp(-x_vector*sqrt(k/Diff)),label="Theory",seriestype=:scatter,
xaxis = ("Space", (-1,100), 0:25:100, font(15, "Futura")),
yaxis = ("Concentration of u", (-0.015,1.05), 0:0.2:1, font(15, "Futura")),
title=("Diffusion and degradation system"))
# ╔═╡ 46ed8542-733c-4a0d-9f60-c2bc1df955b4
md"This shows that the simulation and the analytical solution produce the same output"
# ╔═╡ de723296-d4e4-4762-ade7-add5e2b8c79c
md" ### Stochastic numerical simulations
Gillespies simulations, in situatiosn where the number of particles is small, so we cannot assume a continumm system. Collisions between players are so rare that we see jumps.
"
# ╔═╡ 14994f78-8f03-4e5e-bfb6-533ac0f2c289
# ╔═╡ 2df1ebdd-1889-42c7-9617-5f445f206553
md"### Agent base models
If we dont even have the differential equations, we can use agent-based modeling: a computational model for simulating the actions and interactions of autonomous agents (both individual or collective entities such as organizations or groups) in order to understand the behavior of a system and what governs its outcomes.
We set entities and rules of behavior.
"
# ╔═╡ aec8b317-d3d8-49d3-823f-14a1b16e9f58
md"https://agentscript.org"
# ╔═╡ c7304b77-70a5-444f-9199-eff5539e65bc
md" # 5 Representation of Dynamical Systems
When the solution is known (analytically or numerically), the optimal way to represent the dynamics is by directly plotting the value of the variables against time. In these plots, to observe the dynamics, we just need to follow the change of the curve as time progresses. We can see where the system moves and how fast or slow the dynamics is.
We will illustrate this by solving the pendulum problem. In the physics class, we often solve this problem by small angle approximation, i.e. sin(\theta) \approx \theta, because otherwise, we get an elliptic integral which doesn't have an analytic solution. The linearized form is
```math
\ddot{\theta} + \frac{g}{L}{\theta} = 0
```
But we have numerical ODE solvers! Why not solve the real pendulum?
```math
\ddot{\theta} + \frac{g}{L}{\sin(\theta)} = 0
```
"
# ╔═╡ e3dd377a-a26d-400e-867b-ffb037dd1c5b
begin
L_slider = @bind 😺 html"<input type=range min=0.1 max=2.0 step=0.5>"
md"""
**slide to change the length of the pendulum**
Length : $(L_slider)
"""
end
# ╔═╡ 1ee73b45-192d-4a9d-8a89-d2199cb99dae
begin
# Simple Pendulum Problem
# Constants
const g = 9.81
const L = 😺
#Initial Conditions
#Define the problem
function simplependulum(du,u,p,t)
θ = u[1]
dθ = u[2]
du[1] = dθ
du[2] = -(g/L)*sin(θ)
end
#Pass to solvers
prob = ODEProblem(simplependulum,[0,π/2], (0.0,6.3))
sol = solve(prob,Tsit5())
#Plot
Plots.plot(sol,linewidth=2,
title ="Simple Pendulum Problem",
xaxis = "Time",
yaxis = "Height",
label = ["Angle" "Speed"])
end
# ╔═╡ 1703658a-7b64-4e4a-a8ed-c953dfa11f81
md"
But, what if we do not have the full solution, which is often the case when dealing with complex systems, researches often represet their dynamcis and response using graphicall representations. The two most common and useful ones are phase potraits and landscapes.
"
# ╔═╡ 64063f3d-4f4f-4923-82c6-73f387732944
md" ## 5.1 Phase potraits
A first approximation is to represent a plot where the value of the variables are in each of the axis. This is called a _phase potrait_. In this representation, each point a posible state of the system. A phase portrait is a geometric representation of the trajectories of a dynamical system in the phase plane. Each set of initial conditions is represented by a different curve, or point.
Phase portraits are an invaluable tool in studying dynamical systems. They consist of a plot of typical trajectories in the state space. This reveals information such as whether an attractor, a repellor or limit cycle is present for the chosen parameter value. The concept of topological equivalence is important in classifying the behaviour of systems by specifying when two different phase portraits represent the same qualitative dynamic behavior. An attractor is a stable point which is also called _sink_. The repeller is considered as an unstable point, which is also known as _source_.
The dynamcis of the system is then represented by a trajectory in this representation. In two dimensional systems we can see
plane is called the _phase plane_.
"
# ╔═╡ c4089458-3561-439a-9285-f2d9e0f7cb13
md"So now we know that behavior of the position versus time. However, it will be useful to us to look at the phase space of the pendulum, i.e., and representation of all possible states of the system in question (the pendulum) by looking at its velocity and position. Phase space analysis is ubiquitous in the analysis of dynamical systems, and thus we will provide a few facilities for it."
# ╔═╡ b3b3db0d-196e-4f6f-b297-873e908caabb
begin
pp = Plots.plot(sol, idxs = (1,2), xlims = (-9,9),
title = "Phase Space Plot",
xaxis = "Velocity",
yaxis = "Position",
leg=false)
function phase_plot(prob, u0, p, tspan=2pi)
_prob = ODEProblem(prob.f,u0,(0.0,tspan))
sol = solve(_prob) # Use Vern9 solver for higher accuracy
Plots.plot!(pp, sol, idxs = (1,2))
end
for i in -4pi:pi:4π
for j in -4pi:pi:4π
phase_plot(prob, [j,i], pp)
end
end
Plots.plot(pp,xlims = (-9,9))
end
# ╔═╡ 30a4eca5-511c-41f1-832e-897f1e755f0c
md"In The typical buterfly in the Lorenz atractor is the phase representation of the three variables. "
# ╔═╡ 7c288433-e782-4f2e-97c0-b70c7c2d3748
# define the Lorenz attractor
Base.@kwdef mutable struct Lorenz
dt::Float64 = 0.02
σ::Float64 = 10
ρ::Float64 = 28
β::Float64 = 8/3
x::Float64 = 1
y::Float64 = 1
z::Float64 = 1
end
# ╔═╡ fd7d91f0-b58b-4600-b39e-288ed09bbe34
function step!(l::Lorenz)
dx = l.σ * (l.y - l.x)
dy = l.x * (l.ρ - l.z) - l.y
dz = l.x * l.y - l.β * l.z
l.x += l.dt * dx
l.y += l.dt * dy
l.z += l.dt * dz
end
# ╔═╡ 821963b2-a6d2-45e4-bff0-247fe75f8852
attractor = Lorenz()
# ╔═╡ 6b5c3ff9-57ed-4801-ae9b-2691102e0db7
begin
plt = plot3d(
1,
xlim = (-30, 30),
ylim = (-30, 30),
zlim = (0, 60),
title = "Lorenz Attractor",
marker = 2,
xlabel="x [a.u.]",
ylabel="y [a.u.]",
zlabel="z [a.u.]",
legend=false
)
# build an animated gif by pushing new points to the plot, saving every 10th frame
@gif for i=1:1500
step!(attractor)
push!(plt, attractor.x, attractor.y, attractor.z)
end every 10
end
# ╔═╡ a68f4047-b934-4e56-a70b-f99e640afb9f
md" In nonlinear systems, we do not have the full trajectory, but the have the dynamics in the vicinity of the fixed points (thanks to our linear stability analysis, that calculates the dynamcis of perturbation if we aproximate our system and linearize around each steady state). By looking at trajectories, we can ask whether or not the solution will approach the equilibrium solution as
An example of the null-clines for the _Cubic Autocatalor Model_. The equations for this specific model are:
```math
\begin{eqnarray}
\frac{\partial x}{\partial t} = x^2 y -x \\
\frac{\partial y}{\partial t} = \mu - x^2 y
\end{eqnarray}
```
The steady state for this model is ($x_0,y_0$)= ($\mu, 1/\mu$)."
# ╔═╡ 836e1653-4f3e-4043-96c3-38a5616d2f89
begin
Plots.plot(sol3,idxs=(1,2),label="limit cycle plot")
title!("Cubic Autocatalator")
Plots.xlabel!("X [a.u.]")
Plots.ylabel!("Y [a.u.]")
end
# ╔═╡ 8ad14cbb-2737-4142-b52b-2a22a3b8352a
md"Static landscapes: no not change z(x,y) do not depend on is not $z$"
# ╔═╡ 64c9dbd0-edfd-4b1c-b14d-5e9875ea4f33
html"""<iframe width="700" height="400" src="https://www.youtube.com/embed/4pdiAneMMhU?start=83" title="static" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>"""
# ╔═╡ 1822e04a-9986-42e0-9235-06ef0e486a74
html"""<iframe width="700" height="400" src="https://www.youtube.com/embed/4pdiAneMMhU?start=26" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>"""
# ╔═╡ 9db87f92-f361-465a-8841-fac3fc078343
md"Moving landscapes: z(x,y,z) feedback
A complex system is not the one that has several maxima, minima, are systems where the landscape moves, it depends on variables of the system. The landscape changes depending on the state of the system (Feedback).
Imagine that the landscape is a mountain, that you want to climb, and that the peak moves to another location as you approach, this is a complex system.
- Feedback between you (position) and the mountain (value).
- Adaptation, you need to change your direction if you want to go up.
Examples of these landscapes that move:
- Living making decisions
- Evolution: evolutionary landscape
- Development: Fittness landscapes"
# ╔═╡ 7e6ae3bb-e518-4b15-80fb-e853eceef96c
begin
x=-1:0.01:1
y=-1:0.01:1
h(x,y)=x^2-y^2;
Plots.surface(x,y,h, title= "A saddle node landscape")
end
# ╔═╡ 42924ebd-0bc9-4bd2-9e22-daba975b19e2
html"""<iframe width="700" height="400" src="https://www.youtube.com/embed/iaq_Fpr4KZc?start=83" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>"""
# ╔═╡ 0e68a81f-d628-40e4-a56f-1dc386247946
md" ## Landscapes in Biology:
Exploration + Exploitation:
Exploration = Mutations, Genetic recombination (mix of genes of mother and father in sexual reproduction), (increased variability in a population of bacteria)
Exploitation: natural selection
(Reduces de variability in a population of bacteria)
Imaging these with feedbacks, with moving landscapes
In moving landscapes, the system never stops exploring, if the system stops exploring, a shitf in the landscape, can convert a peak on a valley, and if you are not exploring you are done
So, complex systems have to always balance between exploring and exploiting
So, here it is the cool thing: complexity itself is an emerging property!
Generated by the need of a system to balance exploitation and exploration.
"
# ╔═╡ 5b77331c-adfa-4df2-9fb8-c1d14785cc2b
html"""
<iframe width="700" height="400" src="https://www.youtube.com/embed/KUvuv74_E1U" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
"""
# ╔═╡ c87ffaca-cec4-4aef-8fa8-9d8608941284
md"In this second rendition of Wadington's 'epigenetic landscape', we introduce two variations which we believe reflect some important developmental processes. The first one is that the valleys and the hills, the actual landscape that cells will traverse, are not predermined, that the cells make them as they move along the developmental landscape. The second notion is that at every bifurcation of the landscape there is a binary decision (green or red)"
# ╔═╡ e23af05f-d125-4798-918f-8a20c0f55065
html"""<iframe width="700" height="400" src="https://www.youtube.com/embed/PRmWBBnWfdA" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>"""
# ╔═╡ 6bd76627-d6f0-4adb-af46-203f21f95d27
annealing_url = "https://www.researchgate.net/profile/Omid_Ghasemalizadeh/publication/308786233/figure/fig1/AS:412751978614791@1475419148801/Simulated-Annealing-optimization-of-a-one-dimensional-objective-function.png"
# ╔═╡ 0aa7e21a-255c-4fcc-8ee6-8b3ef96a82b9
md" ## Dynamical systems in lanscape:
Systems evolve dynamically in a landscape towards the point of minimal energy. They do so by exploring locally in small steps (using pertubrbation and noise).
- Small perturbations, (finds local minima)
- Large perturbations (global minimum, but risky, the system can move too fat away from optimal, and dies)
The process of moving in a landscape is often compared to the process of __Annealing__: a treatment that alters the physical and sometimes chemical properties of a material. It involves heating above recrystallization temperature, followed by cooling. Heat increases the rate of diffusion, which results in redistributing and eradicating the dislocations in metals. Cooling is then perfomed gradually to reduce gradually the excursions and more local exploration.
So intially the system can explore larger regions, and then smaller regions to find local minimum.
- $(Resource(annealing_url)) simulated annealing
This process has inspired many algoritms and optimization methdos, called __Simulated anhealing__: a probabilistic method for finding the minimum of a complex functions using computers.
"
# ╔═╡ b5174a24-428e-4a41-9b85-fccc7bcf8d32
path_url = "https://cdncontribute.geeksforgeeks.org/wp-content/uploads/exampleFigure-1.png"
# ╔═╡ 6c11b041-72c9-41c7-9fdb-f3257fea0fd9
waddington_url = "https://www.researchgate.net/profile/Vladimir-Kovac/publication/230718157/figure/fig1/AS:300417280954380@1448636469781/The-epigenetic-landscape-proposed-by-C-H-Waddington-1940-in-Organisers-genes.png"
# ╔═╡ 08ff363a-a0e9-4eb2-a118-5374869fc0da
md" ## Waddington epigenetic landscape: Stem cell differentiation
In 1957, Conrad Waddington described that mammalian development is unidirectional, which means that embryonic stem cells develop into a more mature differentiated state. This idea has been depicted as a ball rolling down from the top of Waddington’s mountain to the bottom of a valley (Figure 1a). It demonstrates visually the natural restriction of cell differentiation potential during normal development.
$(Resource(waddington_url)) Waddington
In this short animation we take the original idea of the 'epigenetic landscape' by CH Waddington and put it into motion, as he probably conceived it in his mind. Waddington saw cells as pebbles rolling down a mountain with hills and valleys. The bottom of the valleys represents cell or differentiation states. Our rendition keeps close to the notions of Waddington except that it looks at the starting point not as a summit but rather as the crater of a volcano"
# ╔═╡ 02c540f7-cdf8-428d-88c0-64ae6cb905c5
fuji_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/1/12/Mount_Fuji_and_Shinkansen_100_from_Fuji_River.jpg/1200px-Mount_Fuji_and_Shinkansen_100_from_Fuji_River.jpg"
# ╔═╡ 6be4813b-fb90-4fcb-bc93-314971a7b50d
ireland_url = "https://images.ireland.com/media/Images/Down/3e656c481c7a49a2b366d4f8696b17b2.jpg"
# ╔═╡ e25205ff-a4fa-4a54-8a6c-1f94c9dd9ac3
discrete_url = "https://reference.wolfram.com/language/ref/Files/DiscretePlot3D.en/O_3.png"
# ╔═╡ 52f9023e-fb67-43ca-8548-46dfeeb7fb86
continuum_url = "https://i.stack.imgur.com/jGmh5.png"
# ╔═╡ 40804fce-7a1e-420e-94cc-2b1dbdf6e357
md" ## 5.2 Fittness Landscapes
In many cases, the rather abstract and mathematically complex structure of a system of attractors and basins can be replaced by the more intuitive model of a fitness landscape. Under certain mathematical conditions, the deterministic dynamics of a system can be represented by a potential function F on the state space, which attaches a certain number to each state: F: S -> R: s -> F(s), such that trajectory of the system through the state space will always follow the path of steepest descent, i.e. move from a given state s to that neighboring state for which F is minimal. In mechanics, this function corresponds to the potential energy of the system. More generally, the function represents the degree to which a certain state is __preferable__ to another state: the lower the value of F, the __better__ or the more __fit__ the state. Thus, the potential can be seen as the negative of the fitness function.
The fitness function transforms the state space into a fitness landscape, where every point in the space has a certain __height__ corresponding to its fitness value. This landscape has peaks and valleys. The attractors of the dynamics will now correspond to the local minima of the potential function (potential valleys), or, equivalently, to the maxima of the fitness function (fitness peaks). This can be understood by noting that the system will always move downward in the potential landscape.
Landscapes are potential functions that define the behavior of the system. Plotting and analyzing landscapes is a great tool to approach a system (for instance , find maximums, minimums of energy, equilibrium points., local versus global maxima on minima...)
z = z (x, y)
the state of a system is its position in the _xy_ plane (teh pase plane),
the elevation _z_ is the value of a given property of the system (for instance, temperature…)
usually lanscapes are drawn in such a way that moving up in _z_ (potential function) represents a change in state that requires energy, while moving down is spontaneous.
### 5.2.1 Types of landscapes
$(Resource(fuji_url)) Mount Fuji landscapes: One peak
$(Resource(ireland_url)) Ripple landscapes: many peaks and valleys
$(Resource(discrete_url)) Discrete landscapes: a finite numer of states
$(Resource(continuum_url)) Continuum landscapes: infinite number of states
"
# ╔═╡ 99b02d20-8596-4b56-bda8-30d671d9f098
Plots.wireframe(x,y,h)
# ╔═╡ f88f76e6-2b7a-4feb-88e4-34fb62a4ebe7
NoFeedback! = @ode_def ab2 begin
dM = -γ_M*M+α_M*T^n/(K^n +T^n)
dP = α_P * M - γ_P * P
end α_M γ_M T n α_P γ_P K
# ╔═╡ 00c2793d-2414-48e6-9946-c4211428d649
PositiveFeedback! = @ode_def ab begin
dM = -γ_M*M+α_M*P^n/(K^n +P^n)
dP = α_P * M - γ_P * P
end α_M γ_M T n α_P γ_P K
# ╔═╡ 68184209-041c-4e78-9d29-1ba56f21a7fd
begin
dog_slide = @bind 🐶 html"<input type=range min=0.01 max=0.5 step=0.1>"
cat_slide = @bind 🐱 html"<input type=range min=0.01 max=0.5 step=0.1>"
md"""
**How many molecules do you have?**
Initial concentration of a: $(dog_slide)
Initial concentration of b: $(cat_slide)
"""
end
# ╔═╡ af5781a8-73f3-4ab4-bf20-38d41e5274e1
begin
u₀ = [🐶,🐱]
tspan = (0.0,50.0)
n=3
K=1
k_m=1
D=1
T=3
α_M=k_m*D
γ_M=0.1
α_P=0.6
γ_P=0.5
p=[α_M,γ_M,T,n,α_P,γ_P,K];
prob1 = ODEProblem(PositiveFeedback!,u₀,tspan,p)
prob2 = ODEProblem(NoFeedback!,u₀,tspan,p)
sol1 = solve(prob1)
P1=plot(sol1,label=["mRNA","Protein"],ylims = (0,12))
title!("Positive feedback")
xlabel!("Time [s]")
ylabel!("Concentration [M]")
sol2 = solve(prob2)
P2=plot(sol2,label=["mRNA","Protein"],ylims = (0,12))
title!("Linear")
xlabel!("Time [s]")
ylabel!("Concentration [M]")
plot(P1,P2,layout=(1,2),legend=true)
end
# ╔═╡ bcfe0e20-c93b-41b7-8291-3f4f9792ba64
pendulum_url="https://upload.wikimedia.org/wikipedia/commons/thumb/4/49/Pendulum_phase_portrait.svg/618px-Pendulum_phase_portrait.svg.png"
# ╔═╡ d22c55f9-d8a0-443b-804e-4cb9976a0ac3
# ╔═╡ 25fcbb57-f3ec-4cce-b22c-2503c9bb36e5
# ╔═╡ ce8ccbe5-2637-43df-906a-ce6a71e9b918
# ╔═╡ 87e78056-fecc-4b15-a723-16f51fa19353
# ╔═╡ 0162ae2a-c19c-4700-9c87-4c76f1169d06
# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
ParameterizedFunctions = "65888b18-ceab-5e60-b2b9-181511a3b968"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
[compat]
CairoMakie = "~0.10.4"
DifferentialEquations = "~7.7.0"
ParameterizedFunctions = "~5.15.0"
Plots = "~1.38.11"
PlutoUI = "~0.7.51"
"""
# ╔═╡ 00000000-0000-0000-0000-000000000002
PLUTO_MANIFEST_TOML_CONTENTS = """
# This file is machine-generated - editing it directly is not advised
julia_version = "1.8.5"
manifest_format = "2.0"
project_hash = "8844f899021d17492dbfb56ccc751377ac8eb45e"
[[deps.AbstractAlgebra]]
deps = ["GroupsCore", "InteractiveUtils", "LinearAlgebra", "MacroTools", "Random", "RandomExtensions", "SparseArrays", "Test"]
git-tree-sha1 = "3ee5c58774f4487a5bf2bb05e39d91ff5022b4cc"
uuid = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
version = "0.29.4"
[[deps.AbstractFFTs]]
deps = ["ChainRulesCore", "LinearAlgebra"]
git-tree-sha1 = "16b6dbc4cf7caee4e1e75c49485ec67b667098a0"
uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c"
version = "1.3.1"
[[deps.AbstractPlutoDingetjes]]
deps = ["Pkg"]
git-tree-sha1 = "8eaf9f1b4921132a4cff3f36a1d9ba923b14a481"
uuid = "6e696c72-6542-2067-7265-42206c756150"
version = "1.1.4"
[[deps.AbstractTrees]]
git-tree-sha1 = "faa260e4cb5aba097a73fab382dd4b5819d8ec8c"
uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
version = "0.4.4"
[[deps.Adapt]]
deps = ["LinearAlgebra", "Requires"]
git-tree-sha1 = "cc37d689f599e8df4f464b2fa3870ff7db7492ef"
uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
version = "3.6.1"
[[deps.Animations]]
deps = ["Colors"]
git-tree-sha1 = "e81c509d2c8e49592413bfb0bb3b08150056c79d"
uuid = "27a7e980-b3e6-11e9-2bcd-0b925532e340"
version = "0.4.1"
[[deps.ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
version = "1.1.1"
[[deps.ArnoldiMethod]]
deps = ["LinearAlgebra", "Random", "StaticArrays"]
git-tree-sha1 = "62e51b39331de8911e4a7ff6f5aaf38a5f4cc0ae"
uuid = "ec485272-7323-5ecc-a04f-4719b315124d"
version = "0.2.0"
[[deps.ArrayInterface]]
deps = ["Adapt", "LinearAlgebra", "Requires", "SnoopPrecompile", "SparseArrays", "SuiteSparse"]
git-tree-sha1 = "38911c7737e123b28182d89027f4216cfc8a9da7"
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
version = "7.4.3"
[[deps.ArrayInterfaceCore]]
deps = ["LinearAlgebra", "SnoopPrecompile", "SparseArrays", "SuiteSparse"]
git-tree-sha1 = "e5f08b5689b1aad068e01751889f2f615c7db36d"
uuid = "30b0a656-2188-435a-8636-2ec0e6a096e2"
version = "0.1.29"
[[deps.ArrayLayouts]]
deps = ["FillArrays", "LinearAlgebra", "SparseArrays"]
git-tree-sha1 = "4aff5fa660eb95c2e0deb6bcdabe4d9a96bc4667"
uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
version = "0.8.18"
[[deps.Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
[[deps.Automa]]
deps = ["Printf", "ScanByte", "TranscodingStreams"]
git-tree-sha1 = "d50976f217489ce799e366d9561d56a98a30d7fe"
uuid = "67c07d97-cdcb-5c2c-af73-a7f9c32a568b"
version = "0.8.2"
[[deps.AxisAlgorithms]]
deps = ["LinearAlgebra", "Random", "SparseArrays", "WoodburyMatrices"]
git-tree-sha1 = "66771c8d21c8ff5e3a93379480a2307ac36863f7"
uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950"
version = "1.0.1"
[[deps.AxisArrays]]
deps = ["Dates", "IntervalSets", "IterTools", "RangeArrays"]
git-tree-sha1 = "1dd4d9f5beebac0c03446918741b1a03dc5e5788"
uuid = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
version = "0.4.6"
[[deps.BandedMatrices]]
deps = ["ArrayLayouts", "FillArrays", "LinearAlgebra", "SnoopPrecompile", "SparseArrays"]
git-tree-sha1 = "6ef8fc1d77b60f41041d59ce61ef9eb41ed97a83"
uuid = "aae01518-5342-5314-be14-df237901396f"
version = "0.17.18"
[[deps.Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
[[deps.Bijections]]
git-tree-sha1 = "fe4f8c5ee7f76f2198d5c2a06d3961c249cce7bd"
uuid = "e2ed5e7c-b2de-5872-ae92-c73ca462fb04"
version = "0.1.4"
[[deps.BitFlags]]
git-tree-sha1 = "43b1a4a8f797c1cddadf60499a8a077d4af2cd2d"
uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
version = "0.1.7"
[[deps.BitTwiddlingConvenienceFunctions]]
deps = ["Static"]
git-tree-sha1 = "0c5f81f47bbbcf4aea7b2959135713459170798b"
uuid = "62783981-4cbd-42fc-bca8-16325de8dc4b"
version = "0.1.5"
[[deps.BoundaryValueDiffEq]]
deps = ["BandedMatrices", "DiffEqBase", "FiniteDiff", "ForwardDiff", "LinearAlgebra", "NLsolve", "Reexport", "SciMLBase", "SparseArrays"]
git-tree-sha1 = "ed8e837bfb3d1e3157022c9636ec1c722b637318"
uuid = "764a87c0-6b3e-53db-9096-fe964310641d"
version = "2.11.0"
[[deps.Bzip2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "19a35467a82e236ff51bc17a3a44b69ef35185a2"
uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0"
version = "1.0.8+0"
[[deps.CEnum]]
git-tree-sha1 = "eb4cb44a499229b3b8426dcfb5dd85333951ff90"
uuid = "fa961155-64e5-5f13-b03f-caf6b980ea82"
version = "0.4.2"
[[deps.CPUSummary]]
deps = ["CpuId", "IfElse", "Static"]
git-tree-sha1 = "2c144ddb46b552f72d7eafe7cc2f50746e41ea21"
uuid = "2a0fbf3d-bb9c-48f3-b0a9-814d99fd7ab9"
version = "0.2.2"
[[deps.CRC32c]]
uuid = "8bf52ea8-c179-5cab-976a-9e18b702a9bc"
[[deps.CSTParser]]
deps = ["Tokenize"]
git-tree-sha1 = "3ddd48d200eb8ddf9cb3e0189fc059fd49b97c1f"
uuid = "00ebfdb7-1f24-5e51-bd34-a7502290713f"
version = "3.3.6"
[[deps.Cairo]]
deps = ["Cairo_jll", "Colors", "Glib_jll", "Graphics", "Libdl", "Pango_jll"]
git-tree-sha1 = "d0b3f8b4ad16cb0a2988c6788646a5e6a17b6b1b"
uuid = "159f3aea-2a34-519c-b102-8c37f9878175"
version = "1.0.5"
[[deps.CairoMakie]]
deps = ["Base64", "Cairo", "Colors", "FFTW", "FileIO", "FreeType", "GeometryBasics", "LinearAlgebra", "Makie", "SHA", "SnoopPrecompile"]
git-tree-sha1 = "2aba202861fd2b7603beb80496b6566491229855"
uuid = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
version = "0.10.4"
[[deps.Cairo_jll]]
deps = ["Artifacts", "Bzip2_jll", "CompilerSupportLibraries_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "JLLWrappers", "LZO_jll", "Libdl", "Pixman_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Zlib_jll", "libpng_jll"]
git-tree-sha1 = "4b859a208b2397a7a623a03449e4636bdb17bcf2"