From 033803255be0954954b7e5709dc0a9df0a4d1053 Mon Sep 17 00:00:00 2001 From: Herman Obst Demaestri Date: Mon, 1 Mar 2021 17:51:46 -0300 Subject: [PATCH 1/8] Chapter summary added, html updated --- 12_ultima_continued/12_ultima_continued.jl | 8 +- docs/12_ultima_continued.jl.html | 1349 ++++++++++---------- 2 files changed, 674 insertions(+), 683 deletions(-) diff --git a/12_ultima_continued/12_ultima_continued.jl b/12_ultima_continued/12_ultima_continued.jl index e0bb63c4..ee0a6f33 100644 --- a/12_ultima_continued/12_ultima_continued.jl +++ b/12_ultima_continued/12_ultima_continued.jl @@ -1,5 +1,5 @@ ### A Pluto.jl notebook ### -# v0.12.20 +# v0.12.21 using Markdown using InteractiveUtils @@ -393,7 +393,11 @@ parameters(Ψf) md"So we recover the equations and its parameters with an outstanding acurracy. And that is even more incredible if we remember that we did this with a **minimum** of data." # ╔═╡ e6ec4364-54eb-11eb-1bf6-83db426cd32f -md"After seeing that, Garriot took a big deep breath. He immediately understood what was going on. The players were mass killing the animals. He called his team and start planning the strategy to face this, not knowing that already was a lost cause... " +md"""After seeing that, Garriot took a big deep breath. He immediately understood what was going on. The players were mass killing the animals. He called his team and start planning the strategy to face this, not knowing that already was a lost cause... + +### Summary + +In this chapter we continue to deepen our understanding of systems of differential equations and their complex behavior. We went a step further, introducing the concept of "Universal Differential Equations" which allow us, given a very small amount of data, to estimate some unknow term of the system. This opens a very big door, connecting machine learning and science, which can greatly enhance the production of knowledge.""" # ╔═╡ aac56d4e-54e7-11eb-2d8a-1f21c386ef8d md"""### References diff --git a/docs/12_ultima_continued.jl.html b/docs/12_ultima_continued.jl.html index d279f32e..f4905ca9 100644 --- a/docs/12_ultima_continued.jl.html +++ b/docs/12_ultima_continued.jl.html @@ -5,9 +5,9 @@ ⚡ Pluto.jl ⚡ - - - + + + -

Letting the computer do science

+

Letting the computer do science

Let's think a little. What do you think is the process by which scientific discoveries are made?

First, you have some situation or event of interest from which you want to discover the rules that govern it. Second, you carefully design the experiments to get as much unbiased data as you can. Third, you analyze that data to gain some knowledge and, hopefully, you can begin to write some equations that condense the underling process. Finally, you keep doing experiments to confirm that the equations you have invented are correct. You are doing science, my friend!

Throughout the book, we were learning a wide variety of statistical methods that sought to be as general as possible, but that required us to define the model to be used. The equations, then, were already defined and the algorithm only had to find the best parameters (or distribution of them) to fit that model to the data.

@@ -189,96 +189,96 @@

Looking for the catastrophe culprit

mpred=1.8

He smiles and happily goes to sleep, thinking that tomorrow is the big day.

Let´s see how were the system equilibrium that he decided.

-
2.0 ms
61.3 s
379 ms
3.4 s
+
1.7 ms
388 s
345 ms
3.9 s
- + - - + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8.5 s

So the system seems in complete equilibrium.

+ +
10.3 s

So the system seems in complete equilibrium.

The infamous day begins.

And finally we arrive at the day when the madness begins.

Garriot wakes up early, doesn´t have any breakfast and goes to meet his team. Everything is ready. The countdown start: 3, 2, 1... And the game is online, running.

After the champagne, hugs and a little celebration Garriot returns to work and starts to analyze the metrics to see if everything is alright, and it does. He relax a little bit until something calls his attention: The curves of carnivorous and herbivorous animals are a little different than they should be. There are still too few points (only four hours from the release) to be alarmed, but he decides to do a deeper analysis. Luckily, a few days ago, he had read a paper on the Universal ODEs, so he thinks they can help him in this case.

-
9.8 μs
lotka_volterra_players (generic function with 1 method)
38.6 μs
6.3 s
+
9.9 μs
lotka_volterra_players (generic function with 1 method)
40.5 μs
7.1 s
- + - - + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - -
1.6 s
3.8 s
+ +
1.6 s
4.0 s
- + - - + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - -
768 ms

As you can see, the animals were taking more time to recover. The period of the cycle was longer than ir should be: A clear sing that something were killing them. But he wanted to be sure. The Universal ODEs were key to do so.

+ +
839 ms

As you can see, the animals were taking more time to recover. The period of the cycle was longer than ir should be: A clear sing that something were killing them. But he wanted to be sure. The Universal ODEs were key to do so.

So, he start thinking "I know that the model has to be running cause I can see it in the code! So maybe, something external is producing this divergence. Something that I don´t know. But something that a Neural Network could find out" Let´s see

-
6.5 μs
24.0 s
2×41 Array{Float32,2}:
- 0.44198  0.330608  0.26585  0.223638  …  1.67964     1.83585     2.00891
- 4.62752  3.83069   3.14661  2.5762       0.00398262  0.00372037  0.00460533
338 ms
dudt_ (generic function with 1 method)
383 ms

So lets stop for a minute to analize the code that Garriot just propose.

+
9.5 μs
93.5 s
2×41 Array{Float32,2}:
+ 0.442105  0.331631  0.264585  0.224956  …  1.67959     1.83622     2.01051
+ 4.62858   3.82721   3.14701   2.57497      0.00630082  0.00561034  0.00321225
364 ms
dudt_ (generic function with 1 method)
422 ms

So lets stop for a minute to analize the code that Garriot just propose.

In the first two lines, he just define the Neural Network that is going to learn the missing components of the two equations (one for the dynamics of the Pray and other for the dynamics of the Predator) and fill the variable p with its untrained parameters.

Then, he is defining the Universal Differential Equation. Where he is specifying the parts of the model that he knows, and adding a Neural Network to learn others things that might be happening (and we know that indeed were happening). In other words, he is proposing:

dPreydt=Prey(1.30.9Pred)+ANN1(prey,pred)

dPreddt=Pred(0.8Prey1.8)+ANN2(prey,pred)

So, as we already know, he is just adding a function. Which one? We already know that those are Preyplayersprey and Predplayerspred (and playerspred=playersprey=0.4), but Garriot doesn´t, and is exactly what the Neural Network is going to learn for him.

-
7.7 μs
2.1 s
+
11.5 μs
2.5 s
- + - - + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - -
759 ms
predict (generic function with 1 method)
34.0 μs
loss (generic function with 1 method)
20.2 μs
callback (generic function with 1 method)
28.9 μs

And lets train the NN!!

-
3.0 μs
156 s
77.2 s
+ +
846 ms
predict (generic function with 1 method)
36.5 μs
loss (generic function with 1 method)
32.6 μs
callback (generic function with 1 method)
40.9 μs

And lets train the NN!!

+
6.6 μs
170 s
91.9 s
- + - - + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + - - - -
1.0 s
+ +
866 ms
- + - - + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - -
905 ms

Nice! Now that we have our Neural Network already learned the Input-Output relation in order to the entire system behave as the data Garriot were seeing in that Infamous morning, we need to transform that Input-Output behaviour into some function. We do this in order to gain interpretability of what may be happening and, in a scientific frame, learn the underling model. We do this by creating a Function Space in order to the NN learn which function (or linear combination of those) is the best one to describe that Input-Output relation. The loss function to do so is designed in a way that the result will be the least complex one, that is, the answer will be the simplest function that behave like the NN.

-
6.4 μs
246 ms
18.0 s
29 dimensional basis in ["u₁", "u₂"]
39.0 ns

So, as you can see above, we just created a Function Space of 29 dimensions. That space include every possible linear combination of each dimension. And we are going to ask to SINDy to give us the simplest function that shows the same Input-Output behaviour the Neural Network just learned.

+ +
842 ms

Nice! Now that we have our Neural Network already learned the Input-Output relation in order to the entire system behave as the data Garriot were seeing in that Infamous morning, we need to transform that Input-Output behaviour into some function. We do this in order to gain interpretability of what may be happening and, in a scientific frame, learn the underling model. We do this by creating a Function Space in order to the NN learn which function (or linear combination of those) is the best one to describe that Input-Output relation. The loss function to do so is designed in a way that the result will be the least complex one, that is, the answer will be the simplest function that behave like the NN.

+
12.5 μs
212 ms
15.4 s
29 dimensional basis in ["u₁", "u₂"]
38.0 ns

So, as you can see above, we just created a Function Space of 29 dimensions. That space include every possible linear combination of each dimension. And we are going to ask to SINDy to give us the simplest function that shows the same Input-Output behaviour the Neural Network just learned.

Without saying more, let's do it!

-
6.7 μs
Sparse Identification Result with 2 active terms.
18.4 s
p₁ * u₁
5.0 ms
p₂ * u₂
3.4 μs

OMG! The equations were perfectly restored! You can read this as:

+
11.0 μs
Sparse Identification Result with 2 active terms.
16.5 s
p₁ * u₁
5.1 ms
p₂ * u₂
3.1 μs

OMG! The equations were perfectly restored! You can read this as:

ANN1(prey,pred)=p1u1=p1Prey

ANN2(prey,pred)=p2u2=p2Pred

dPreydt=Prey(1.30.9Pred)+p1Prey=Prey(1.30.9Pred+p1)

@@ -1550,18 +1535,20 @@

The infamous day begins.

dPreddt=Pred(0.8Prey1.8playerspred)

And that we also define that playersprey=playerspred=0.4, the recover parameter from de NN should 0.4. Does it makes sense?

Lets ask for the parameters then:

-
6.3 μs
149 ns

So, the parameters are a bit off. But now that we have the equations restored, we can run another SINDy to gain much more accuracy:

-
2.7 μs
Sparse Identification Result with 2 active terms.
11.9 s
206 ns

So we recover the equations and its parameters with an outstanding acurracy. And that is even more incredible if we remember that we did this with a minimum of data.

-
3.7 μs

After seeing that, Garriot took a big deep breath. He immediately understood what was going on. The players were mass killing the animals. He called his team and start planning the strategy to face this, not knowing that already was a lost cause...

-
6.7 μs

References

+
6.4 μs
203 ns

So, the parameters are a bit off. But now that we have the equations restored, we can run another SINDy to gain much more accuracy:

+
2.9 μs
Sparse Identification Result with 2 active terms.
12.3 s
197 ns

So we recover the equations and its parameters with an outstanding acurracy. And that is even more incredible if we remember that we did this with a minimum of data.

+
3.8 μs

After seeing that, Garriot took a big deep breath. He immediately understood what was going on. The players were mass killing the animals. He called his team and start planning the strategy to face this, not knowing that already was a lost cause...

+

Summary

+

In this chapter we continue to deepen our understanding of systems of differential equations and their complex behavior. We went a step further, introducing the concept of "Universal Differential Equations" which allow us, given a very small amount of data, to estimate some unknow term of the system. This opens a very big door, connecting machine learning and science, which can greatly enhance the production of knowledge.

+
17.1 μs
2.6 ms
- +2.4 ms + \ No newline at end of file From 88b1ca1c059b96fcbc3e1c4b5029c66a188d104c Mon Sep 17 00:00:00 2001 From: Pedro Fontana Date: Wed, 10 Mar 2021 17:47:38 -0300 Subject: [PATCH 2/8] corrections --- 12_ultima_continued/12_ultima_continued.jl | 4 +++- docs/12_ultima_continued.jl.html | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/12_ultima_continued/12_ultima_continued.jl b/12_ultima_continued/12_ultima_continued.jl index ee0a6f33..71cd84b0 100644 --- a/12_ultima_continued/12_ultima_continued.jl +++ b/12_ultima_continued/12_ultima_continued.jl @@ -397,7 +397,9 @@ md"""After seeing that, Garriot took a big deep breath. He immediately understoo ### Summary -In this chapter we continue to deepen our understanding of systems of differential equations and their complex behavior. We went a step further, introducing the concept of "Universal Differential Equations" which allow us, given a very small amount of data, to estimate some unknow term of the system. This opens a very big door, connecting machine learning and science, which can greatly enhance the production of knowledge.""" +In this chapter we continue to deepen our understanding of systems of differential equations and their complex behavior. +We went a step further, introducing the concept of universal differential equations which allow us, given a very small amount of data, to estimate some unknown term of the system. +This opens a very big door, connecting machine learning and science, which can greatly enhance the production of knowledge. # ╔═╡ aac56d4e-54e7-11eb-2d8a-1f21c386ef8d md"""### References diff --git a/docs/12_ultima_continued.jl.html b/docs/12_ultima_continued.jl.html index f4905ca9..cc5c8bb2 100644 --- a/docs/12_ultima_continued.jl.html +++ b/docs/12_ultima_continued.jl.html @@ -1539,7 +1539,7 @@

The infamous day begins.

2.9 μs
Sparse Identification Result with 2 active terms.
12.3 s
197 ns

So we recover the equations and its parameters with an outstanding acurracy. And that is even more incredible if we remember that we did this with a minimum of data.

3.8 μs

After seeing that, Garriot took a big deep breath. He immediately understood what was going on. The players were mass killing the animals. He called his team and start planning the strategy to face this, not knowing that already was a lost cause...

Summary

-

In this chapter we continue to deepen our understanding of systems of differential equations and their complex behavior. We went a step further, introducing the concept of "Universal Differential Equations" which allow us, given a very small amount of data, to estimate some unknow term of the system. This opens a very big door, connecting machine learning and science, which can greatly enhance the production of knowledge.

+

In this chapter we continue to deepen our understanding of systems of differential equations and their complex behavior.We went a step further, introducing the concept of universal differential equations which allow us, given a very small amount of data, to estimate some unknown term of the system.This opens a very big door, connecting machine learning and science, which can greatly enhance the production of knowledge.

17.1 μs

References

  • Universal Differential Equations for Scientific Machine Learning Paper

    From 809ec9ebddd89f9138b8b80ff8e156fe7430a03a Mon Sep 17 00:00:00 2001 From: Pedro Fontana Date: Wed, 10 Mar 2021 17:59:10 -0300 Subject: [PATCH 3/8] quotation marks corrections --- 12_ultima_continued/12_ultima_continued.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/12_ultima_continued/12_ultima_continued.jl b/12_ultima_continued/12_ultima_continued.jl index 71cd84b0..d2fa975b 100644 --- a/12_ultima_continued/12_ultima_continued.jl +++ b/12_ultima_continued/12_ultima_continued.jl @@ -400,6 +400,7 @@ md"""After seeing that, Garriot took a big deep breath. He immediately understoo In this chapter we continue to deepen our understanding of systems of differential equations and their complex behavior. We went a step further, introducing the concept of universal differential equations which allow us, given a very small amount of data, to estimate some unknown term of the system. This opens a very big door, connecting machine learning and science, which can greatly enhance the production of knowledge. +""" # ╔═╡ aac56d4e-54e7-11eb-2d8a-1f21c386ef8d md"""### References @@ -436,7 +437,7 @@ md"""### References # ╠═d84d16c2-5447-11eb-0caf-6d099ef176a7 # ╠═d9ec41a0-5448-11eb-09f9-ffbb2a896a64 # ╠═03e26dea-5449-11eb-38dc-957ea73db154 -# ╟─58a1294c-544c-11eb-27ca-8512bc3d5461 +# ╠═58a1294c-544c-11eb-27ca-8512bc3d5461 # ╠═b38b9410-544e-11eb-220b-5746f897b5f4 # ╠═d58d6d84-544e-11eb-17b8-91723456fc15 # ╠═5a6dcdc8-5451-11eb-2a2f-cbc4f35844c0 @@ -450,5 +451,5 @@ md"""### References # ╠═520b2d00-5457-11eb-349f-3bec665738fd # ╠═fef7edba-54dd-11eb-3025-35fe9ffae6ac # ╟─fe88958e-54e5-11eb-12bc-01ad625d85c5 -# ╟─e6ec4364-54eb-11eb-1bf6-83db426cd32f +# ╠═e6ec4364-54eb-11eb-1bf6-83db426cd32f # ╟─aac56d4e-54e7-11eb-2d8a-1f21c386ef8d From d18bb08dc47bdf4e239b6185e9e8f25d6eccbe41 Mon Sep 17 00:00:00 2001 From: Pedro Fontana Date: Fri, 12 Mar 2021 18:54:54 -0300 Subject: [PATCH 4/8] corrections --- 12_ultima_continued/12_ultima_continued.jl | 2 +- docs/12_ultima_continued.jl.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/12_ultima_continued/12_ultima_continued.jl b/12_ultima_continued/12_ultima_continued.jl index d2fa975b..383b306e 100644 --- a/12_ultima_continued/12_ultima_continued.jl +++ b/12_ultima_continued/12_ultima_continued.jl @@ -397,7 +397,7 @@ md"""After seeing that, Garriot took a big deep breath. He immediately understoo ### Summary -In this chapter we continue to deepen our understanding of systems of differential equations and their complex behavior. +In this chapter, we continued to deepen our understanding of systems of differential equations and their complex behavior. We went a step further, introducing the concept of universal differential equations which allow us, given a very small amount of data, to estimate some unknown term of the system. This opens a very big door, connecting machine learning and science, which can greatly enhance the production of knowledge. """ diff --git a/docs/12_ultima_continued.jl.html b/docs/12_ultima_continued.jl.html index cc5c8bb2..bbf3f70b 100644 --- a/docs/12_ultima_continued.jl.html +++ b/docs/12_ultima_continued.jl.html @@ -1539,7 +1539,7 @@

    The infamous day begins.

2.9 μs
Sparse Identification Result with 2 active terms.
12.3 s
197 ns

So we recover the equations and its parameters with an outstanding acurracy. And that is even more incredible if we remember that we did this with a minimum of data.

3.8 μs

After seeing that, Garriot took a big deep breath. He immediately understood what was going on. The players were mass killing the animals. He called his team and start planning the strategy to face this, not knowing that already was a lost cause...

Summary

-

In this chapter we continue to deepen our understanding of systems of differential equations and their complex behavior.We went a step further, introducing the concept of universal differential equations which allow us, given a very small amount of data, to estimate some unknown term of the system.This opens a very big door, connecting machine learning and science, which can greatly enhance the production of knowledge.

+

In this chapter, we continued to deepen our understanding of systems of differential equations and their complex behavior.We went a step further, introducing the concept of universal differential equations which allow us, given a very small amount of data, to estimate some unknown term of the system.This opens a very big door, connecting machine learning and science, which can greatly enhance the production of knowledge.

17.1 μs

References

  • Universal Differential Equations for Scientific Machine Learning Paper

    From 79f48ae36c5f2ee0e90d53bf8ab28fc671bb3b87 Mon Sep 17 00:00:00 2001 From: Pedro Fontana Date: Mon, 29 Mar 2021 12:51:27 -0300 Subject: [PATCH 5/8] corrected Garriott name #70 --- 11_ultima_online/11_ultima_online.jl | 4 ++-- 12_ultima_continued/12_ultima_continued.jl | 22 +++++++++++----------- docs/11_ultima_online.jl.html | 4 ++-- docs/12_ultima_continued.jl.html | 22 +++++++++++----------- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/11_ultima_online/11_ultima_online.jl b/11_ultima_online/11_ultima_online.jl index 7200f916..2511bb3c 100644 --- a/11_ultima_online/11_ultima_online.jl +++ b/11_ultima_online/11_ultima_online.jl @@ -109,7 +109,7 @@ plot(sol) # ╔═╡ 4aff3714-284b-11eb-2047-814ca175e07b md"""#### Obtaining the model from the data -Back to the terrible case of Ultima Online. Suppose we had data on the population of predators and prey that were in harmony during the game at a given time. If we wanted to venture out and analyze what parameters Garriot and his team used to model their great ecosystem, would it be possible? Of course it is, we just need to add a little Bayesianism. +Back to the terrible case of Ultima Online. Suppose we had data on the population of predators and prey that were in harmony during the game at a given time. If we wanted to venture out and analyze what parameters Garriott and his team used to model their great ecosystem, would it be possible? Of course it is, we just need to add a little Bayesianism. """ # ╔═╡ e3da565c-2851-11eb-0fa7-a3cd80bb9d63 @@ -340,7 +340,7 @@ md"### References - [SciML](https://sciml.ai/) - [Turing Bayesian Differential Equation](https://turing.ml/dev/tutorials/10-bayesiandiffeq/) -- [Garriot telling the Story](https://www.youtube.com/watch?v=KFNxJVTJleE&ab_channel=ArsTechnica)" +- [Garriott telling the Story](https://www.youtube.com/watch?v=KFNxJVTJleE&ab_channel=ArsTechnica)" # ╔═╡ Cell order: # ╟─74cc60be-2821-11eb-3ad7-e581052437bd diff --git a/12_ultima_continued/12_ultima_continued.jl b/12_ultima_continued/12_ultima_continued.jl index 383b306e..59b8bd57 100644 --- a/12_ultima_continued/12_ultima_continued.jl +++ b/12_ultima_continued/12_ultima_continued.jl @@ -102,7 +102,7 @@ Let´s see how were the system equilibrium that he decided. # ╔═╡ 247a6e7e-5417-11eb-3509-3d349198ec43 begin -#The Lotka-Volterra model Garriot define for Ultima Online +#The Lotka-Volterra model Garriott define for Ultima Online function lotka_volterra(du,u,p,t) prey, pred = u @@ -132,15 +132,15 @@ md"""So the system seems in complete equilibrium. And finally we arrive at the day when the madness begins. -Garriot wakes up early, doesn´t have any breakfast and goes to meet his team. Everything is ready. The countdown start: 3, 2, 1... And the game is online, running. +Garriott wakes up early, doesn´t have any breakfast and goes to meet his team. Everything is ready. The countdown start: 3, 2, 1... And the game is online, running. -After the champagne, hugs and a little celebration Garriot returns to work and starts to analyze the metrics to see if everything is alright, and it does. He relax a little bit until something calls his attention: The curves of carnivorous and herbivorous animals are a little different than they should be. There are still **too few points** (only four hours from the release) to be alarmed, but he decides to do a deeper analysis. Luckily, a few days ago, he had read a paper on the Universal ODEs, so he thinks they can help him in this case. +After the champagne, hugs and a little celebration Garriott returns to work and starts to analyze the metrics to see if everything is alright, and it does. He relax a little bit until something calls his attention: The curves of carnivorous and herbivorous animals are a little different than they should be. There are still **too few points** (only four hours from the release) to be alarmed, but he decides to do a deeper analysis. Luckily, a few days ago, he had read a paper on the Universal ODEs, so he thinks they can help him in this case. """ # ╔═╡ 3bb32294-5423-11eb-1c75-27dc2f242255 function lotka_volterra_players(du,u,p,t) #Lotka-Volterra function with players that hunt - #Of course, Garriot doesn´t know about this new players part of the equation. + #Of course, Garriott doesn´t know about this new players part of the equation. #He only saw some differences in the real curve vs the one he expected. birth_prey, mort_prey, birth_pred, mort_pred, players_prey, players_pred = p @@ -159,7 +159,7 @@ end; # ╔═╡ 8de32f8c-5423-11eb-24c6-5be06370cb3f begin -scatter(solution, alpha = 0.25, title="The data Garriot was seeing") +scatter(solution, alpha = 0.25, title="The data Garriott was seeing") plot!(solution, alpha = 0.5) end @@ -171,7 +171,7 @@ end; # ╔═╡ 5d5c55a0-5426-11eb-0e93-27e67f42dc8e begin -scatter(expected_solution, alpha = 0.25, title="The data Garriot was expecting to see") +scatter(expected_solution, alpha = 0.25, title="The data Garriott was expecting to see") plot!(expected_solution, alpha = 0.5) end @@ -204,7 +204,7 @@ end # ╔═╡ a0b0497a-5436-11eb-0bad-f564c6033968 md""" -So lets stop for a minute to analize the code that Garriot just propose. +So lets stop for a minute to analize the code that Garriott just propose. In the first two lines, he just define the Neural Network that is going to learn the missing components of the two equations (one for the dynamics of the Pray and other for the dynamics of the Predator) and fill the variable p with its untrained parameters. @@ -214,7 +214,7 @@ $\frac{dPrey}{dt} = Prey*(1.3 - 0.9*Pred) + ANN_1(prey, pred)$ $\frac{dPred}{dt} = Pred*(0.8*Prey - 1.8) + ANN_2(prey, pred)$ -So, as we already know, he is just adding a **function**. Which one? We already know that those are $Prey*players_{prey}$ and $Pred*players_{pred}$ (and $players_{pred}=players_{prey}=0.4$), but Garriot doesn´t, and is exactly what the Neural Network is going to learn for him. +So, as we already know, he is just adding a **function**. Which one? We already know that those are $Prey*players_{prey}$ and $Pred*players_{pred}$ (and $players_{pred}=players_{prey}=0.4$), but Garriott doesn´t, and is exactly what the Neural Network is going to learn for him. """ @@ -286,7 +286,7 @@ plot!(solution.t, X', title="The trained NN have fitted well") end # ╔═╡ 58a1294c-544c-11eb-27ca-8512bc3d5461 -md"""Nice! Now that we have our Neural Network already learned the **Input-Output** relation in order to the entire system behave as the data Garriot were seeing in that Infamous morning, we need to transform that Input-Output behaviour into some function. We do this in order to *gain* interpretability of what may be happening and, in a scientific frame, learn the underling model. We do this by creating a [Function Space](https://en.wikipedia.org/wiki/Function_space) in order to the NN learn which function (or linear combination of those) is the best one to describe that Input-Output relation. The loss function to do so is designed in a way that the result will be the least complex one, that is, the answer will be the simplest function that behave like the NN. +md"""Nice! Now that we have our Neural Network already learned the **Input-Output** relation in order to the entire system behave as the data Garriott were seeing in that Infamous morning, we need to transform that Input-Output behaviour into some function. We do this in order to *gain* interpretability of what may be happening and, in a scientific frame, learn the underling model. We do this by creating a [Function Space](https://en.wikipedia.org/wiki/Function_space) in order to the NN learn which function (or linear combination of those) is the best one to describe that Input-Output relation. The loss function to do so is designed in a way that the result will be the least complex one, that is, the answer will be the simplest function that behave like the NN. """ # ╔═╡ b38b9410-544e-11eb-220b-5746f897b5f4 @@ -357,7 +357,7 @@ $\frac{dPrey}{dt} = Prey*(1.3 - 0.9*Pred) + p_1*Prey = Prey*(1.3 - 0.9*Pred + p1 $\frac{dPred}{dt} = Pred*(0.8*Prey - 1.8) + p_2*Pred = Pred*(0.8*Prey - 1.8 + p2)$ -So, Remembering that we define the data Garriot was seeing as: +So, Remembering that we define the data Garriott was seeing as: $\frac{dPrey}{dt} = Prey*(1.3 - 0.9*Pred - players_{prey})$ @@ -393,7 +393,7 @@ parameters(Ψf) md"So we recover the equations and its parameters with an outstanding acurracy. And that is even more incredible if we remember that we did this with a **minimum** of data." # ╔═╡ e6ec4364-54eb-11eb-1bf6-83db426cd32f -md"""After seeing that, Garriot took a big deep breath. He immediately understood what was going on. The players were mass killing the animals. He called his team and start planning the strategy to face this, not knowing that already was a lost cause... +md"""After seeing that, Garriott took a big deep breath. He immediately understood what was going on. The players were mass killing the animals. He called his team and start planning the strategy to face this, not knowing that already was a lost cause... ### Summary diff --git a/docs/11_ultima_online.jl.html b/docs/11_ultima_online.jl.html index 6957c58c..65360e73 100644 --- a/docs/11_ultima_online.jl.html +++ b/docs/11_ultima_online.jl.html @@ -485,7 +485,7 @@

    Returning to LotkaVolterra

    ">
8.2 s

Obtaining the model from the data

-

Back to the terrible case of Ultima Online. Suppose we had data on the population of predators and prey that were in harmony during the game at a given time. If we wanted to venture out and analyze what parameters Garriot and his team used to model their great ecosystem, would it be possible? Of course it is, we just need to add a little Bayesianism.

+

Back to the terrible case of Ultima Online. Suppose we had data on the population of predators and prey that were in harmony during the game at a given time. If we wanted to venture out and analyze what parameters Garriott and his team used to model their great ecosystem, would it be possible? Of course it is, we just need to add a little Bayesianism.

6.4 μs
5.5 s
data
Column1Column2
Float64Float64
1
1.0
1.0
2
2.44646
0.852693
3
4.90536
1.7076
4
2.32078
3.90827
5
0.670135
2.88228
6
0.569719
1.62614
7
1.03
0.984499
8
2.5327
0.857645
9
4.94699
1.78325
10
2.19317
3.92488
more
16
2.08182
3.9374
14.1 s
ultima_online
2×16 LinearAlgebra.Adjoint{Float64,Array{Float64,2}}:
  1.0  2.44646   4.90536  2.32078  0.670135  …  1.05926   2.61348   4.97878  2.08182
  1.0  0.852693  1.7076   3.90827  2.88228      0.969715  0.864201  1.86019  3.9374
163 ms

Probably seeing this data in a table is not being very enlightening, let's plot it and see if it makes sense with what we have been discussing:

@@ -14329,7 +14329,7 @@

The virtual catastrophe

  • Turing Bayesian Differential Equation

  • -
  • Garriot telling the Story

    +
  • Garriott telling the Story

  • 9.4 μs
    diff --git a/docs/12_ultima_continued.jl.html b/docs/12_ultima_continued.jl.html index bbf3f70b..098d0962 100644 --- a/docs/12_ultima_continued.jl.html +++ b/docs/12_ultima_continued.jl.html @@ -189,7 +189,7 @@

    Looking for the catastrophe culprit

    mpred=1.8

    He smiles and happily goes to sleep, thinking that tomorrow is the big day.

    Let´s see how were the system equilibrium that he decided.

    -
    1.7 ms
    388 s
    345 ms
    3.9 s
    +
    1.7 ms
    388 s
    345 ms
    3.9 s
    @@ -540,9 +540,9 @@

    Looking for the catastrophe culprit

    10.3 s

    So the system seems in complete equilibrium.

    The infamous day begins.

    And finally we arrive at the day when the madness begins.

    -

    Garriot wakes up early, doesn´t have any breakfast and goes to meet his team. Everything is ready. The countdown start: 3, 2, 1... And the game is online, running.

    -

    After the champagne, hugs and a little celebration Garriot returns to work and starts to analyze the metrics to see if everything is alright, and it does. He relax a little bit until something calls his attention: The curves of carnivorous and herbivorous animals are a little different than they should be. There are still too few points (only four hours from the release) to be alarmed, but he decides to do a deeper analysis. Luckily, a few days ago, he had read a paper on the Universal ODEs, so he thinks they can help him in this case.

    -
    9.9 μs
    lotka_volterra_players (generic function with 1 method)
    40.5 μs
    7.1 s
    +

    Garriott wakes up early, doesn´t have any breakfast and goes to meet his team. Everything is ready. The countdown start: 3, 2, 1... And the game is online, running.

    +

    After the champagne, hugs and a little celebration Garriott returns to work and starts to analyze the metrics to see if everything is alright, and it does. He relax a little bit until something calls his attention: The curves of carnivorous and herbivorous animals are a little different than they should be. There are still too few points (only four hours from the release) to be alarmed, but he decides to do a deeper analysis. Luckily, a few days ago, he had read a paper on the Universal ODEs, so he thinks they can help him in this case.

    +
    9.9 μs
    lotka_volterra_players (generic function with 1 method)
    40.5 μs
    7.1 s
    @@ -822,7 +822,7 @@

    The infamous day begins.

    1959.94,408.716 2109.31,408.716 "> -
    1.6 s
    4.0 s
    +
    1.6 s
    4.0 s
    @@ -1108,16 +1108,16 @@

    The infamous day begins.

    1959.94,408.716 2109.31,408.716 "> -
    839 ms

    As you can see, the animals were taking more time to recover. The period of the cycle was longer than ir should be: A clear sing that something were killing them. But he wanted to be sure. The Universal ODEs were key to do so.

    +
    839 ms

    As you can see, the animals were taking more time to recover. The period of the cycle was longer than ir should be: A clear sing that something were killing them. But he wanted to be sure. The Universal ODEs were key to do so.

    So, he start thinking "I know that the model has to be running cause I can see it in the code! So maybe, something external is producing this divergence. Something that I don´t know. But something that a Neural Network could find out" Let´s see

    9.5 μs
    93.5 s
    2×41 Array{Float32,2}:
      0.442105  0.331631  0.264585  0.224956  …  1.67959     1.83622     2.01051
    - 4.62858   3.82721   3.14701   2.57497      0.00630082  0.00561034  0.00321225
    364 ms
    dudt_ (generic function with 1 method)
    422 ms

    So lets stop for a minute to analize the code that Garriot just propose.

    + 4.62858 3.82721 3.14701 2.57497 0.00630082 0.00561034 0.00321225
    364 ms
    dudt_ (generic function with 1 method)
    422 ms

    So lets stop for a minute to analize the code that Garriott just propose.

    In the first two lines, he just define the Neural Network that is going to learn the missing components of the two equations (one for the dynamics of the Pray and other for the dynamics of the Predator) and fill the variable p with its untrained parameters.

    Then, he is defining the Universal Differential Equation. Where he is specifying the parts of the model that he knows, and adding a Neural Network to learn others things that might be happening (and we know that indeed were happening). In other words, he is proposing:

    dPreydt=Prey(1.30.9Pred)+ANN1(prey,pred)

    dPreddt=Pred(0.8Prey1.8)+ANN2(prey,pred)

    -

    So, as we already know, he is just adding a function. Which one? We already know that those are Preyplayersprey and Predplayerspred (and playerspred=playersprey=0.4), but Garriot doesn´t, and is exactly what the Neural Network is going to learn for him.

    +

    So, as we already know, he is just adding a function. Which one? We already know that those are Preyplayersprey and Predplayerspred (and playerspred=playersprey=0.4), but Garriott doesn´t, and is exactly what the Neural Network is going to learn for him.

    11.5 μs
    2.5 s
    @@ -1522,7 +1522,7 @@

    The infamous day begins.

    2001.28,410.825 2150.65,410.825 "> -
    842 ms

    Nice! Now that we have our Neural Network already learned the Input-Output relation in order to the entire system behave as the data Garriot were seeing in that Infamous morning, we need to transform that Input-Output behaviour into some function. We do this in order to gain interpretability of what may be happening and, in a scientific frame, learn the underling model. We do this by creating a Function Space in order to the NN learn which function (or linear combination of those) is the best one to describe that Input-Output relation. The loss function to do so is designed in a way that the result will be the least complex one, that is, the answer will be the simplest function that behave like the NN.

    +
    842 ms

    Nice! Now that we have our Neural Network already learned the Input-Output relation in order to the entire system behave as the data Garriott were seeing in that Infamous morning, we need to transform that Input-Output behaviour into some function. We do this in order to gain interpretability of what may be happening and, in a scientific frame, learn the underling model. We do this by creating a Function Space in order to the NN learn which function (or linear combination of those) is the best one to describe that Input-Output relation. The loss function to do so is designed in a way that the result will be the least complex one, that is, the answer will be the simplest function that behave like the NN.

    12.5 μs
    212 ms
    15.4 s
    29 dimensional basis in ["u₁", "u₂"]
    38.0 ns

    So, as you can see above, we just created a Function Space of 29 dimensions. That space include every possible linear combination of each dimension. And we are going to ask to SINDy to give us the simplest function that shows the same Input-Output behaviour the Neural Network just learned.

    Without saying more, let's do it!

    11.0 μs
    Sparse Identification Result with 2 active terms.
    16.5 s
    p₁ * u₁
    5.1 ms
    p₂ * u₂
    3.1 μs

    OMG! The equations were perfectly restored! You can read this as:

    @@ -1530,14 +1530,14 @@

    The infamous day begins.

    ANN2(prey,pred)=p2u2=p2Pred

    dPreydt=Prey(1.30.9Pred)+p1Prey=Prey(1.30.9Pred+p1)

    dPreddt=Pred(0.8Prey1.8)+p2Pred=Pred(0.8Prey1.8+p2)

    -

    So, Remembering that we define the data Garriot was seeing as:

    +

    So, Remembering that we define the data Garriott was seeing as:

    dPreydt=Prey(1.30.9Predplayersprey)

    dPreddt=Pred(0.8Prey1.8playerspred)

    And that we also define that playersprey=playerspred=0.4, the recover parameter from de NN should 0.4. Does it makes sense?

    Lets ask for the parameters then:

    6.4 μs
    203 ns

    So, the parameters are a bit off. But now that we have the equations restored, we can run another SINDy to gain much more accuracy:

    2.9 μs
    Sparse Identification Result with 2 active terms.
    12.3 s
    197 ns

    So we recover the equations and its parameters with an outstanding acurracy. And that is even more incredible if we remember that we did this with a minimum of data.

    -
    3.8 μs

    After seeing that, Garriot took a big deep breath. He immediately understood what was going on. The players were mass killing the animals. He called his team and start planning the strategy to face this, not knowing that already was a lost cause...

    +
    3.8 μs

    After seeing that, Garriott took a big deep breath. He immediately understood what was going on. The players were mass killing the animals. He called his team and start planning the strategy to face this, not knowing that already was a lost cause...

    Summary

    In this chapter, we continued to deepen our understanding of systems of differential equations and their complex behavior.We went a step further, introducing the concept of universal differential equations which allow us, given a very small amount of data, to estimate some unknown term of the system.This opens a very big door, connecting machine learning and science, which can greatly enhance the production of knowledge.

    17.1 μs

    References

    From dc581e38ac5c5242859ff645b429612f8730c14f Mon Sep 17 00:00:00 2001 From: Pedro Fontana Date: Mon, 10 May 2021 18:37:03 -0300 Subject: [PATCH 6/8] correct Garriot name in chap 11 at Rmd and html fil-e --- 11_ultima_online.Rmd | 4 ++-- docs/ultima-online.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/11_ultima_online.Rmd b/11_ultima_online.Rmd index 0acc170b..472ca802 100644 --- a/11_ultima_online.Rmd +++ b/11_ultima_online.Rmd @@ -101,7 +101,7 @@ plot(sol) #### Obtaining the model from the data -Back to the terrible case of Ultima Online. Suppose we had data on the population of predators and prey that were in harmony during the game at a given time. If we wanted to venture out and analyze what parameters Garriot and his team used to model their great ecosystem, would it be possible? Of course it is, we just need to add a little Bayesianism. +Back to the terrible case of Ultima Online. Suppose we had data on the population of predators and prey that were in harmony during the game at a given time. If we wanted to venture out and analyze what parameters Garriott and his team used to model their great ecosystem, would it be possible? Of course it is, we just need to add a little Bayesianism. ```{julia} data = CSV.read("./11_ultima_online/ultima_online_data.csv", DataFrame) @@ -342,4 +342,4 @@ In this chapter we have learned about the usefulness of differential equations f - [SciML](https://sciml.ai/) - [Turing Bayesian Differential Equation](https://turing.ml/dev/tutorials/10-bayesiandiffeq/) -- [Garriot telling the Story](https://www.youtube.com/watch?v=KFNxJVTJleE&ab_channel=ArsTechnica) +- [Garriott telling the Story](https://www.youtube.com/watch?v=KFNxJVTJleE&ab_channel=ArsTechnica) diff --git a/docs/ultima-online.html b/docs/ultima-online.html index b584cf40..fc194435 100644 --- a/docs/ultima-online.html +++ b/docs/ultima-online.html @@ -354,7 +354,7 @@

    11.1.1.3 SciML to simulate popula

    11.1.1.4 Obtaining the model from the data

    -

    Back to the terrible case of Ultima Online. Suppose we had data on the population of predators and prey that were in harmony during the game at a given time. If we wanted to venture out and analyze what parameters Garriot and his team used to model their great ecosystem, would it be possible? Of course it is, we just need to add a little Bayesianism.

    +

    Back to the terrible case of Ultima Online. Suppose we had data on the population of predators and prey that were in harmony during the game at a given time. If we wanted to venture out and analyze what parameters Garriott and his team used to model their great ecosystem, would it be possible? Of course it is, we just need to add a little Bayesianism.

    data = CSV.read("./11_ultima_online/ultima_online_data.csv", DataFrame)
    ## 16×2 DataFrame
     ##  Row │ Column1   Column2
    @@ -533,7 +533,7 @@ 

    11.3 References

    From c0e39b491e7fc73b7ce2ff2ae43a3690df5317bc Mon Sep 17 00:00:00 2001 From: Pedro Fontana Date: Mon, 10 May 2021 19:47:33 -0300 Subject: [PATCH 7/8] correct typos --- 11_ultima_online.Rmd | 19 ++++++------ 11_ultima_online/11_ultima_online.jl | 22 +++++++------- 12_ultima_continued/12_ultima_continued.jl | 35 +++++++++------------- docs/ultima-online.html | 20 ++++++------- 4 files changed, 45 insertions(+), 51 deletions(-) diff --git a/11_ultima_online.Rmd b/11_ultima_online.Rmd index 472ca802..0c99e96c 100644 --- a/11_ultima_online.Rmd +++ b/11_ultima_online.Rmd @@ -19,7 +19,7 @@ using MCMCChains ## The Ultima Online Catastrophe -[Ultima online](https://uo.com/) is a fantasy massively multiplayer online role-playing game (MMORPG) created by [Richard Garriott](https://en.wikipedia.org/wiki/Richard_Garriott) between 1995 and 1997, when it was realesed. +[Ultima online](https://uo.com/) is a fantasy massively multiplayer online role-playing game (MMORPG) created by [Richard Garriott](https://en.wikipedia.org/wiki/Richard_Garriott) between 1995 and 1997, when it was released. The game consisted of a medieval fantasy world in which each player could build their own character. What was interesting and disruptive was that all players interacted with each other, and what one did had repercussions on the general map. So, the game was "live" in the sense that if two people were fighting in one area and another one came in, the latter could see that fight. Also, the warriors had to hunt and look for resources to get points and improve their skills and again, if a treasure was discovered, or an animal was hunted, it would no longer be available for the rest. @@ -49,17 +49,17 @@ The population at time $t$ multiplies at both rates because if the population is #### Parentheses on differential equations -Before anyone freaks out, lets talk a little bit about that strange notation. +Before anyone freaks out, let's talk a little bit about that strange notation. -As we said above, the prey´s population will grow proportionally to the birth rate and the actual population. And we also said that the population will shrink proportional to the mortality rate and its actual population. Can you realize that we are describing change? +As we said above, the prey's population will grow proportionally to the birth rate and the actual population. And we also said that the population will shrink proportional to the mortality rate and its actual population. Can you realize that we are describing change? -So that is exactly what the equation is saying! You can read that horrendous $d$ as change! So, the entire term $\frac{dPrey}{dt}=$ is just saying "The change of the pupulation over time (that´s why the $dt$ term is deviding there) is equal to..." and that´s it! +So that is exactly what the equation is saying! You can read that horrendous $d$ as change! So, the entire term $\frac{dPrey}{dt}=$ is just saying "The change of the population over time (that's why the $dt$ term is dividing there) is equal to..." and that's it! -This can be a difficult concept to understand because we are very used to work with absolute values. But sometimes (In fact, very often) it is much more easier to describe change over absolute values. And this is one of this cases. But, for now, lets leave this up to here, we will take it up again in the next chapter. +This can be a difficult concept to understand because we are very used to work with absolute values. But sometimes (In fact, very often) it is much more easier to describe change over absolute values. And this is one of these cases. But, for now, let's leave this up to here, we will take it up again in the next chapter. #### Returning to LotkaVolterra -But the model we are looking for have to explain the interaction between the two species. To do so, we must include the Pradator Population in order to modify the mortality rate of the Prey, leaving us with: +But the model we are looking for has to explain the interaction between the two species. To do so, we must include the Predator Population in order to modify the mortality rate of the Prey, leaving us with: $\frac{dPrey}{dt} = Prey*(b_{prey} - m_{prey}*Pred)$ @@ -72,7 +72,7 @@ In this way we obtain the Lotka-Volterra model in which the population dynamics #### SciML to simulate population dynamics ```{julia} -#Let´s define our Lotka-Volterra model +#Let's define our Lotka-Volterra model function lotka_volterra(du,u,p,t) prey, pred = u @@ -177,7 +177,7 @@ The powerful SciML engine allows us to make Bayesian inferences but from dynamic #### Visualizing the results -As always, it is very interesting to be able to observe the uncertainty that Bayesianism provides us within our model. Let´s go for it! +As always, it is very interesting to be able to observe the uncertainty that Bayesianism provides us within our model. Let's go for it! First we should make a smaller sampling of the distributions of each parameter so that the number of models we plot does not become a problem when visualizing: @@ -190,7 +190,7 @@ begin end; ``` -And now let's solve the system of differential equations for each of the combinations of parameters that we form, saving them in solutions so that later we can use this array in the plotting. You can scroll left and see the solution to the 101 models we propouse (Notice that we add one final model using the mean of each parameter) +And now let's solve the system of differential equations for each of the combinations of parameters that we form, saving them in solutions so that later we can use this array in the plotting. You can scroll left and see the solution to the 101 models we propose (Notice that we add one final model using the mean of each parameter) ```{julia , results = FALSE} begin @@ -287,6 +287,7 @@ plot(sol_players) As you can see, the players could hunt enough to double the mortality rate of both animals, and the system would still be in balance. More herbivores would be observed (because they have a higher birth rate, and there would now be fewer carnivores) and the phase - the time it takes for a full cycle of population decline and rise - would be delayed. The creators of the game even assumed that the players would hunt mostly carnivores, because they would be rewarded with higher scores and resources (and because they would also have to defend themselves from the fierce attacks of the carnivores). The balance would be maintained anyway: + ```{julia,results = FALSE} begin p2 = [0.8, 0.4, 0.2, 0.4, 0.4, 0.6] diff --git a/11_ultima_online/11_ultima_online.jl b/11_ultima_online/11_ultima_online.jl index 4118c646..2e6aafae 100644 --- a/11_ultima_online/11_ultima_online.jl +++ b/11_ultima_online/11_ultima_online.jl @@ -24,7 +24,7 @@ We are currently working on: # ╔═╡ 74cc60be-2821-11eb-3ad7-e581052437bd md"""# The Ultima Online Catastrophe -[Ultima online](https://uo.com/) is a fantasy massively multiplayer online role-playing game (MMORPG) created by [Richard Garriott](https://en.wikipedia.org/wiki/Richard_Garriott) between 1995 and 1997, when it was realesed. +[Ultima online](https://uo.com/) is a fantasy massively multiplayer online role-playing game (MMORPG) created by [Richard Garriott](https://en.wikipedia.org/wiki/Richard_Garriott) between 1995 and 1997, when it was released. The game consisted of a medieval fantasy world in which each player could build their own character. What was interesting and disruptive was that all players interacted with each other, and what one did had repercussions on the general map. So, the game was "live" in the sense that if two people were fighting in one area and another one came in, the latter could see that fight. Also, the warriors had to hunt and look for resources to get points and improve their skills and again, if a treasure was discovered, or an animal was hunted, it would no longer be available for the rest. @@ -62,17 +62,17 @@ md"""The population at time *t* multiplies at both rates because if the populati #### Parentheses on differential equations -Before anyone freaks out, lets talk a little bit about that strange notation. +Before anyone freaks out, let's talk a little bit about that strange notation. -As we said above, the prey´s population will **grow** proportionally to the birth rate and the actual population. And we also said that the population will **shrink** proportional to the mortality rate and its actual population. Can you realize that we are describing **change**? +As we said above, the prey's population will **grow** proportionally to the birth rate and the actual population. And we also said that the population will **shrink** proportional to the mortality rate and its actual population. Can you realize that we are describing **change**? -So that is exactly what the equation is saying! You can read that horrendous $d$ as change! So, the entire term $\frac{dPrey}{dt}=$ is just saying "The change of the pupulation over time (that´s why the $dt$ term is deviding there) is equal to..." and that´s it! +So that is exactly what the equation is saying! You can read that horrendous $d$ as change! So, the entire term $\frac{dPrey}{dt}=$ is just saying "The change of the population over time (that's why the $dt$ term is dividing there) is equal to..." and that's it! -This can be a difficult concept to understand because we are very used to work with **absolute** values. But sometimes (In fact, very often) it is much more easier to describe change over absolute values. And this is one of this cases. But, for now, lets leave this up to here, we will take it up again in the next chapter. +This can be a difficult concept to understand because we are very used to work with **absolute** values. But sometimes (In fact, very often) it is much easier to describe change over absolute values. And this is one of these cases. But, for now, let's leave this up to here, we will take it up again in the next chapter. #### Returning to LotkaVolterra -But the model we are looking for have to explain the *interaction* between the two species. To do so, we must include the Pradator Population in order to modify the mortality rate of the Prey, leaving us with: +But the model we are looking for has to explain the *interaction* between the two species. To do so, we must include the Predator Population in order to modify the mortality rate of the Prey, leaving us with: """ # ╔═╡ e0f34b58-2845-11eb-0480-9d200fc79403 @@ -91,7 +91,7 @@ md"In this way we obtain the Lotka-Volterra model in which the population dynami md"#### SciML to simulate population dynamics" # ╔═╡ 5da9eb00-2848-11eb-0dfa-17ca0490bd44 -#Let´s define our Lotka-Volterra model +#Let's define our Lotka-Volterra model function lotka_volterra(du,u,p,t) prey, pred = u @@ -189,7 +189,7 @@ The powerful SciML engine allows us to make Bayesian inferences but from dynamic #### Visualizing the results -As always, it is very interesting to be able to observe the uncertainty that Bayesianism provides us *within* our model. Let´s go for it! +As always, it is very interesting to be able to observe the uncertainty that Bayesianism provides us *within* our model. Let's go for it! First we should make a smaller sampling of the distributions of each parameter so that the number of models we plot does not become a problem when visualizing: " @@ -203,7 +203,7 @@ begin end; # ╔═╡ dee1f67c-291a-11eb-11ba-7d6b7129b15c -md"And now let's solve the system of differential equations for each of the combinations of parameters that we form, saving them in *solutions* so that later we can use this array in the plotting. You can scroll left and see the solution to the 101 models we propouse (Notice that we add one final model using the mean of each parameter)" +md"And now let's solve the system of differential equations for each of the combinations of parameters that we form, saving them in *solutions* so that later we can use this array in the plotting. You can scroll left and see the solution to the 101 models we propose (Notice that we add one final model using the mean of each parameter)" # ╔═╡ 3794d5aa-291b-11eb-1e16-31c59b6d37a2 begin @@ -336,11 +336,11 @@ plot(sol_crazy_players, legend=false) # ╔═╡ 0e53ba34-29d5-11eb-3540-bbc2a0127cf5 md"This sad story ends with the whole beautiful virtual ecosystem, planned for 3 years, destroyed in seconds. The animals of the medieval world that Garriott and his team had imagined had to be eliminated... In case you want to know more about this, you can listen to the story from the mouth of the protagonist himself [here](https://www.youtube.com/watch?v=KFNxJVTJleE&ab_channel=ArsTechnica) -But like every difficult moment, this one also left great lessons. From that moment on, the games started to been tested with real people during the whole development process. The idea that you could predict the behavior of millions of players was finished, and they started to test instead. +But like every difficult moment, this one also left great lessons. From that moment on, the games started to be tested with real people during the whole development process. The idea that you could predict the behavior of millions of players was finished, and they started to test instead. This was the beginning of a very Bayesian way of thinking, in which we start with a priori hypotheses that are tested with reality to modify the old beliefs, and gain a deeper understanding of what is really happening. -It makes sense, doesn't it? After all, getting comfortable with our beliefs never is a very good option, and going out into the world to learn new things seem like a more interesting one. +It makes sense, doesn't it? After all, getting comfortable with our beliefs is never a very good option, and going out into the world to learn new things seems like a more interesting one. ### Summary diff --git a/12_ultima_continued/12_ultima_continued.jl b/12_ultima_continued/12_ultima_continued.jl index 89c97ba5..025d8dbe 100644 --- a/12_ultima_continued/12_ultima_continued.jl +++ b/12_ultima_continued/12_ultima_continued.jl @@ -102,7 +102,7 @@ Let´s see how were the system equilibrium that he decided. # ╔═╡ 247a6e7e-5417-11eb-3509-3d349198ec43 begin -#The Lotka-Volterra model Garriott define for Ultima Online +#The Lotka-Volterra model Garriot define for Ultima Online function lotka_volterra(du,u,p,t) prey, pred = u @@ -132,15 +132,15 @@ md"""So the system seems in complete equilibrium. And finally we arrive at the day when the madness begins. -Garriott wakes up early, doesn´t have any breakfast and goes to meet his team. Everything is ready. The countdown start: 3, 2, 1... And the game is online, running. +Garriot wakes up early, doesn´t have any breakfast and goes to meet his team. Everything is ready. The countdown start: 3, 2, 1... And the game is online, running. -After the champagne, hugs and a little celebration Garriott returns to work and starts to analyze the metrics to see if everything is alright, and it does. He relax a little bit until something calls his attention: The curves of carnivorous and herbivorous animals are a little different than they should be. There are still **too few points** (only four hours from the release) to be alarmed, but he decides to do a deeper analysis. Luckily, a few days ago, he had read a paper on the Universal ODEs, so he thinks they can help him in this case. +After the champagne, hugs and a little celebration Garriot returns to work and starts to analyze the metrics to see if everything is alright, and it does. He relax a little bit until something calls his attention: The curves of carnivorous and herbivorous animals are a little different than they should be. There are still **too few points** (only four hours from the release) to be alarmed, but he decides to do a deeper analysis. Luckily, a few days ago, he had read a paper on the Universal ODEs, so he thinks they can help him in this case. """ # ╔═╡ 3bb32294-5423-11eb-1c75-27dc2f242255 function lotka_volterra_players(du,u,p,t) #Lotka-Volterra function with players that hunt - #Of course, Garriott doesn´t know about this new players part of the equation. + #Of course, Garriot doesn´t know about this new players part of the equation. #He only saw some differences in the real curve vs the one he expected. birth_prey, mort_prey, birth_pred, mort_pred, players_prey, players_pred = p @@ -159,7 +159,7 @@ end; # ╔═╡ 8de32f8c-5423-11eb-24c6-5be06370cb3f begin -scatter(solution, alpha = 0.25, title="The data Garriott was seeing") +scatter(solution, alpha = 0.25, title="The data Garriot was seeing") plot!(solution, alpha = 0.5) end @@ -171,7 +171,7 @@ end; # ╔═╡ 5d5c55a0-5426-11eb-0e93-27e67f42dc8e begin -scatter(expected_solution, alpha = 0.25, title="The data Garriott was expecting to see") +scatter(expected_solution, alpha = 0.25, title="The data Garriot was expecting to see") plot!(expected_solution, alpha = 0.5) end @@ -204,7 +204,7 @@ end # ╔═╡ a0b0497a-5436-11eb-0bad-f564c6033968 md""" -So lets stop for a minute to analize the code that Garriott just propose. +So lets stop for a minute to analize the code that Garriot just propose. In the first two lines, he just define the Neural Network that is going to learn the missing components of the two equations (one for the dynamics of the Pray and other for the dynamics of the Predator) and fill the variable p with its untrained parameters. @@ -214,7 +214,7 @@ $\frac{dPrey}{dt} = Prey*(1.3 - 0.9*Pred) + ANN_1(prey, pred)$ $\frac{dPred}{dt} = Pred*(0.8*Prey - 1.8) + ANN_2(prey, pred)$ -So, as we already know, he is just adding a **function**. Which one? We already know that those are $Prey*players_{prey}$ and $Pred*players_{pred}$ (and $players_{pred}=players_{prey}=0.4$), but Garriott doesn´t, and is exactly what the Neural Network is going to learn for him. +So, as we already know, he is just adding a **function**. Which one? We already know that those are $Prey*players_{prey}$ and $Pred*players_{pred}$ (and $players_{pred}=players_{prey}=0.4$), but Garriot doesn´t, and is exactly what the Neural Network is going to learn for him. """ @@ -286,7 +286,7 @@ plot!(solution.t, X', title="The trained NN have fitted well") end # ╔═╡ 58a1294c-544c-11eb-27ca-8512bc3d5461 -md"""Nice! Now that we have our Neural Network already learned the **Input-Output** relation in order to the entire system behave as the data Garriott were seeing in that Infamous morning, we need to transform that Input-Output behaviour into some function. We do this in order to *gain* interpretability of what may be happening and, in a scientific frame, learn the underling model. We do this by creating a [Function Space](https://en.wikipedia.org/wiki/Function_space) in order to the NN learn which function (or linear combination of those) is the best one to describe that Input-Output relation. The loss function to do so is designed in a way that the result will be the least complex one, that is, the answer will be the simplest function that behave like the NN. +md"""Nice! Now that we have our Neural Network already learned the **Input-Output** relation in order to the entire system behave as the data Garriot were seeing in that Infamous morning, we need to transform that Input-Output behaviour into some function. We do this in order to *gain* interpretability of what may be happening and, in a scientific frame, learn the underling model. We do this by creating a [Function Space](https://en.wikipedia.org/wiki/Function_space) in order to the NN learn which function (or linear combination of those) is the best one to describe that Input-Output relation. The loss function to do so is designed in a way that the result will be the least complex one, that is, the answer will be the simplest function that behave like the NN. """ # ╔═╡ b38b9410-544e-11eb-220b-5746f897b5f4 @@ -357,7 +357,7 @@ $\frac{dPrey}{dt} = Prey*(1.3 - 0.9*Pred) + p_1*Prey = Prey*(1.3 - 0.9*Pred + p1 $\frac{dPred}{dt} = Pred*(0.8*Prey - 1.8) + p_2*Pred = Pred*(0.8*Prey - 1.8 + p2)$ -So, Remembering that we define the data Garriott was seeing as: +So, Remembering that we define the data Garriot was seeing as: $\frac{dPrey}{dt} = Prey*(1.3 - 0.9*Pred - players_{prey})$ @@ -393,14 +393,7 @@ parameters(Ψf) md"So we recover the equations and its parameters with an outstanding acurracy. And that is even more incredible if we remember that we did this with a **minimum** of data." # ╔═╡ e6ec4364-54eb-11eb-1bf6-83db426cd32f -md"""After seeing that, Garriott took a big deep breath. He immediately understood what was going on. The players were mass killing the animals. He called his team and start planning the strategy to face this, not knowing that already was a lost cause... - -### Summary - -In this chapter, we continued to deepen our understanding of systems of differential equations and their complex behavior. -We went a step further, introducing the concept of universal differential equations which allow us, given a very small amount of data, to estimate some unknown term of the system. -This opens a very big door, connecting machine learning and science, which can greatly enhance the production of knowledge. -""" +md"After seeing that, Garriot took a big deep breath. He immediately understood what was going on. The players were mass killing the animals. He called his team and start planning the strategy to face this, not knowing that already was a lost cause... " # ╔═╡ aac56d4e-54e7-11eb-2d8a-1f21c386ef8d md"""### References @@ -437,7 +430,7 @@ md"""### References # ╠═d84d16c2-5447-11eb-0caf-6d099ef176a7 # ╠═d9ec41a0-5448-11eb-09f9-ffbb2a896a64 # ╠═03e26dea-5449-11eb-38dc-957ea73db154 -# ╠═58a1294c-544c-11eb-27ca-8512bc3d5461 +# ╟─58a1294c-544c-11eb-27ca-8512bc3d5461 # ╠═b38b9410-544e-11eb-220b-5746f897b5f4 # ╠═d58d6d84-544e-11eb-17b8-91723456fc15 # ╠═5a6dcdc8-5451-11eb-2a2f-cbc4f35844c0 @@ -451,5 +444,5 @@ md"""### References # ╠═520b2d00-5457-11eb-349f-3bec665738fd # ╠═fef7edba-54dd-11eb-3025-35fe9ffae6ac # ╟─fe88958e-54e5-11eb-12bc-01ad625d85c5 -# ╠═e6ec4364-54eb-11eb-1bf6-83db426cd32f -# ╟─aac56d4e-54e7-11eb-2d8a-1f21c386ef8d +# ╟─e6ec4364-54eb-11eb-1bf6-83db426cd32f +# ╟─aac56d4e-54e7-11eb-2d8a-1f21c386ef8d \ No newline at end of file diff --git a/docs/ultima-online.html b/docs/ultima-online.html index fc194435..96a250cb 100644 --- a/docs/ultima-online.html +++ b/docs/ultima-online.html @@ -301,7 +301,7 @@

    Chapter 11 Ultima online

    11.1 The Ultima Online Catastrophe

    -

    Ultima online is a fantasy massively multiplayer online role-playing game (MMORPG) created by Richard Garriott between 1995 and 1997, when it was realesed.

    +

    Ultima online is a fantasy massively multiplayer online role-playing game (MMORPG) created by Richard Garriott between 1995 and 1997, when it was released.

    The game consisted of a medieval fantasy world in which each player could build their own character. What was interesting and disruptive was that all players interacted with each other, and what one did had repercussions on the general map. So, the game was “live” in the sense that if two people were fighting in one area and another one came in, the latter could see that fight. Also, the warriors had to hunt and look for resources to get points and improve their skills and again, if a treasure was discovered, or an animal was hunted, it would no longer be available for the rest.

    During the development process of the game, Garriott and his team realized that, due to the massiveness of the game, there was going to be a moment when they would not be able to create content at the same speed as the players were consuming it. So they decided to automate the process.

    After a lot of work, one of the ideas they came up with was to generate a “Virtual Ecosystem.” This was a really incredible idea in which a whole ecosystem in harmony was simulated inside the game. For example, if an area started to grow grass, the herbivorous animals would come and start eating it. If many animals arrived, they would surely end up eating all the food and would have to go look for other places, it could even happen that some of them were not lucky and died on the way, starving. In the same way, the carnivorous animals (that is, the predators of the herbivores) would strive to hunt as many animals as they could, but if in doing so they killed a significant number of them, food would become scarce causing them to die as well. In this way, as in “real” nature, a beautiful balance was generated.

    @@ -318,14 +318,14 @@

    11.1.1 The Lotka-Volterra model f

    The population at time \(t\) multiplies at both rates because if the population is zero there can be no births or deaths. This leads us to the simplest ecological model, in which per capita growth is the difference between the birth rate and the mortality rate.

    11.1.1.1 Parentheses on differential equations

    -

    Before anyone freaks out, lets talk a little bit about that strange notation.

    -

    As we said above, the prey´s population will grow proportionally to the birth rate and the actual population. And we also said that the population will shrink proportional to the mortality rate and its actual population. Can you realize that we are describing change?

    -

    So that is exactly what the equation is saying! You can read that horrendous \(d\) as change! So, the entire term \(\frac{dPrey}{dt}=\) is just saying “The change of the pupulation over time (that´s why the \(dt\) term is deviding there) is equal to…” and that´s it!

    -

    This can be a difficult concept to understand because we are very used to work with absolute values. But sometimes (In fact, very often) it is much more easier to describe change over absolute values. And this is one of this cases. But, for now, lets leave this up to here, we will take it up again in the next chapter.

    +

    Before anyone freaks out, let's talk a little bit about that strange notation.

    +

    As we said above, the prey's population will grow proportionally to the birth rate and the actual population. And we also said that the population will shrink proportional to the mortality rate and its actual population. Can you realize that we are describing change?

    +

    So that is exactly what the equation is saying! You can read that horrendous \(d\) as change! So, the entire term \(\frac{dPrey}{dt}=\) is just saying “The change of the population over time (that's why the \(dt\) term is dividing there) is equal to…” and that's it!

    +

    This can be a difficult concept to understand because we are very used to work with absolute values. But sometimes (In fact, very often) it is much easier to describe change over absolute values. And this is one of these cases. But, for now, let's leave this up to here, we will take it up again in the next chapter.

    11.1.1.2 Returning to LotkaVolterra

    -

    But the model we are looking for have to explain the interaction between the two species. To do so, we must include the Pradator Population in order to modify the mortality rate of the Prey, leaving us with:

    +

    But the model we are looking for has to explain the interaction between the two species. To do so, we must include the Predator Population in order to modify the mortality rate of the Prey, leaving us with:

    \(\frac{dPrey}{dt} = Prey*(b_{prey} - m_{prey}*Pred)\)

    In a similar way we can think the interaction on the side of the predator, were the mortality rate would be constant and the birth rate will depend upon the Prey population:

    \(\frac{dPred}{dt} = Pred*(b_{pred}*Prey - m_{pred})\)

    @@ -333,7 +333,7 @@

    11.1.1.2 Returning to LotkaVolter

    11.1.1.3 SciML to simulate population dynamics

    -
    #Let´s define our Lotka-Volterra model
    +
    #Let's define our Lotka-Volterra model
     
     function lotka_volterra(du,u,p,t)
       prey, pred  = u
    @@ -424,7 +424,7 @@ 

    11.1.1.4 Obtaining the model from

    11.1.1.5 Visualizing the results

    -

    As always, it is very interesting to be able to observe the uncertainty that Bayesianism provides us within our model. Let´s go for it!

    +

    As always, it is very interesting to be able to observe the uncertainty that Bayesianism provides us within our model. Let's go for it!

    First we should make a smaller sampling of the distributions of each parameter so that the number of models we plot does not become a problem when visualizing:

    begin
         birth_prey_ = sample(collect(get(posterior, :birth_prey)[1]), 100)
    @@ -432,7 +432,7 @@ 

    11.1.1.5 Visualizing the results< birth_pred_ = sample(collect(get(posterior, :birth_pred)[1]), 100) mort_pred_ = sample(collect(get(posterior, :mort_pred)[1]), 100) end;

    -

    And now let’s solve the system of differential equations for each of the combinations of parameters that we form, saving them in solutions so that later we can use this array in the plotting. You can scroll left and see the solution to the 101 models we propouse (Notice that we add one final model using the mean of each parameter)

    +

    And now let’s solve the system of differential equations for each of the combinations of parameters that we form, saving them in solutions so that later we can use this array in the plotting. You can scroll left and see the solution to the 101 models we propose (Notice that we add one final model using the mean of each parameter)

    begin
         solutions = []
         for i in 1:length(birth_prey_)
    @@ -518,7 +518,7 @@ 

    11.1.1.6 The virtual catastrophe<
    plot(sol_crazy_players, legend=false)

    This sad story ends with the whole beautiful virtual ecosystem, planned for 3 years, destroyed in seconds. The animals of the medieval world that Garriott and his team had imagined had to be eliminated… In case you want to know more about this, you can listen to the story from the mouth of the protagonist himself here

    -

    But like every difficult moment, this one also left great lessons. From that moment on, the games started to been tested with real people during the whole development process. The idea that you could predict the behavior of millions of players was finished, and they started to test instead.

    +

    But like every difficult moment, this one also left great lessons. From that moment on, the games started to be tested with real people during the whole development process. The idea that you could predict the behavior of millions of players was finished, and they started to test instead.

    This was the beginning of a very Bayesian way of thinking, in which we start with a priori hypotheses that are tested with reality to modify the old beliefs, and gain a deeper understanding of what is really happening.

    It makes sense, doesn’t it? After all, getting comfortable with our beliefs never is a very good option, and going out into the world to learn new things seem like a more interesting one.

    From c00e34de0c701f17f24d4cf426bf95154021a4ca Mon Sep 17 00:00:00 2001 From: Pedro Fontana Date: Wed, 12 May 2021 00:51:15 -0300 Subject: [PATCH 8/8] correct typos --- 11_ultima_online.Rmd | 6 +++--- docs/ultima-online.html | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/11_ultima_online.Rmd b/11_ultima_online.Rmd index 0c99e96c..9156779c 100644 --- a/11_ultima_online.Rmd +++ b/11_ultima_online.Rmd @@ -55,7 +55,7 @@ As we said above, the prey's population will grow proportionally to the birth ra So that is exactly what the equation is saying! You can read that horrendous $d$ as change! So, the entire term $\frac{dPrey}{dt}=$ is just saying "The change of the population over time (that's why the $dt$ term is dividing there) is equal to..." and that's it! -This can be a difficult concept to understand because we are very used to work with absolute values. But sometimes (In fact, very often) it is much more easier to describe change over absolute values. And this is one of these cases. But, for now, let's leave this up to here, we will take it up again in the next chapter. +This can be a difficult concept to understand because we are very used to work with absolute values. But sometimes (In fact, very often) it is much easier to describe change over absolute values. And this is one of these cases. But, for now, let's leave this up to here, we will take it up again in the next chapter. #### Returning to LotkaVolterra @@ -329,11 +329,11 @@ plot(sol_crazy_players, legend=false) This sad story ends with the whole beautiful virtual ecosystem, planned for 3 years, destroyed in seconds. The animals of the medieval world that Garriott and his team had imagined had to be eliminated... In case you want to know more about this, you can listen to the story from the mouth of the protagonist himself [here](https://www.youtube.com/watch?v=KFNxJVTJleE&ab_channel=ArsTechnica) -But like every difficult moment, this one also left great lessons. From that moment on, the games started to been tested with real people during the whole development process. The idea that you could predict the behavior of millions of players was finished, and they started to test instead. +But like every difficult moment, this one also left great lessons. From that moment on, the games started to be tested with real people during the whole development process. The idea that you could predict the behavior of millions of players was finished, and they started to test instead. This was the beginning of a very Bayesian way of thinking, in which we start with a priori hypotheses that are tested with reality to modify the old beliefs, and gain a deeper understanding of what is really happening. -It makes sense, doesn't it? After all, getting comfortable with our beliefs never is a very good option, and going out into the world to learn new things seem like a more interesting one. +It makes sense, doesn't it? After all, getting comfortable with our beliefs is never a very good option, and going out into the world to learn new things seems like a more interesting one. ## Summary diff --git a/docs/ultima-online.html b/docs/ultima-online.html index 96a250cb..e56a3eeb 100644 --- a/docs/ultima-online.html +++ b/docs/ultima-online.html @@ -520,7 +520,7 @@

    11.1.1.6 The virtual catastrophe<

    This sad story ends with the whole beautiful virtual ecosystem, planned for 3 years, destroyed in seconds. The animals of the medieval world that Garriott and his team had imagined had to be eliminated… In case you want to know more about this, you can listen to the story from the mouth of the protagonist himself here

    But like every difficult moment, this one also left great lessons. From that moment on, the games started to be tested with real people during the whole development process. The idea that you could predict the behavior of millions of players was finished, and they started to test instead.

    This was the beginning of a very Bayesian way of thinking, in which we start with a priori hypotheses that are tested with reality to modify the old beliefs, and gain a deeper understanding of what is really happening.

    -

    It makes sense, doesn’t it? After all, getting comfortable with our beliefs never is a very good option, and going out into the world to learn new things seem like a more interesting one.

    +

    It makes sense, doesn’t it? After all, getting comfortable with our beliefs is never a very good option, and going out into the world to learn new things seems like a more interesting one.