Package initialization
"utf-8"
Scientific computing with Julia
David Widmann (@devmotion )
Uppsala University, Sweden
American University in Bulgaria, 17 February 2022
About me
👨🎓 PhD student at the Department of Information Technology and the Centre for Interdisciplinary Mathematics (CIM) in Uppsala
BSc and MSc in Mathematics (TU Munich)
Human medicine (LMU and TU Munich)
👨🔬 Research topic: "Uncertainty-aware deep learning"
I.e., statistics, probability theory, machine learning, and computer science
💻 Julia programming, e.g.,
SciML, in particular DelayDiffEq.jl
Outline
We will see examples from and I will discuss my relation to
SciML (a lot)
Turing (a bit)
my research (a bit)
This is a very opinionated choice, there are many other great packages and organizations in Julia for scientific computing.
Note
I use Julia a lot and generally I am very satisfied with it. But this means:
I am quite biased
You will hear mostly good things about Julia in this talk
Please interrupt me at any time if you have a question 🙂
"Why we created Julia"
Bezanson, Karpinski, Shah, and Edelman (2012):
In short, because we are greedy.
We want a language that's open source, with a liberal license.
We want the speed of C with the dynamism of Ruby.
We want something as usable for general programming as Python, as easy for statistics as R, as natural for string processing as Perl, as powerful for linear algebra as Matlab, as good at gluing programs together as the shell.
Something that is dirt simple to learn, yet keeps the most serious hackers happy.
We want it interactive and we want it compiled.
Why we use Julia, 10 years later
Why do I use Julia?
I was curious and excited early on:
a, supposedly fast and cool, programming language! 🎉
that is open source 📖
and has a nice math-like syntax 😍
At TUM I had to learn and use MATLAB and R...
...but I used the opportunity and tried to work and become familiar with it for a course project during my Erasmus exchange in Uppsala.
Initial contributions
I had noticed some things that were missing and maybe could be improved.
After I was done with my exchange year, I had some time and started to make my first small contributions.
Barabási-Albert random graphs
First PR (archived, use Graphs.jl nowadays)
barabasi_albert(n, k)
Create a Barabási–Albert model random graph with n
vertices. It is grown by adding new vertices to an initial graph with k
vertices. Each new vertex is attached with k
edges to k
different vertices already present in the system by preferential attachment. Initial graphs are undirected and consist of isolated vertices by default.
Optional Arguments
is_directed=false
: if true, return a directed graph.complete=false
: if true, use a complete graph for the initial graph.seed=-1
: set the RNG seed.
Examples
julia> barabasi_albert(50, 3)
{50, 141} undirected simple Int64 graph
julia> barabasi_albert(100, Int8(10), is_directed=true, complete=true, seed=123)
{100, 990} directed simple Int8 graph
barabasi_albert(n::Integer, n0::Integer, k::Integer)
Create a Barabási–Albert model random graph with n
vertices. It is grown by adding new vertices to an initial graph with n0
vertices. Each new vertex is attached with k
edges to k
different vertices already present in the system by preferential attachment. Initial graphs are undirected and consist of isolated vertices by default.
Optional Arguments
is_directed=false
: if true, return a directed graph.complete=false
: if true, use a complete graph for the initial graph.seed=-1
: set the RNG seed.
Examples
julia> barabasi_albert(10, 3, 2)
{10, 14} undirected simple Int64 graph
julia> barabasi_albert(100, Int8(10), 3, is_directed=true, seed=123)
{100, 270} directed simple Int8 graph
Weighted sampling without replacement
efraimidis_aexpj_wsample_norep!([rng], a::AbstractArray, wv::AbstractWeights, x::AbstractArray)
Implementation of weighted sampling without replacement using Efraimidis-Spirakis A-ExpJ algorithm.
Reference: Efraimidis, P. S., Spirakis, P. G. "Weighted random sampling with a reservoir." Information Processing Letters, 97 (5), 181-185, 2006. doi:10.1016/j.ipl.2005.11.003.
Noting k=length(x)
and n=length(a)
, this algorithm takes
SciML
Excerpt from the NumFOCUS project page:
SciML is an open source software organization created to unify the packages for scientific machine learning. This includes the development of modular scientific simulation support software, such as differential equation solvers, along with the methodologies for inverse problems and automated model discovery. By providing a diverse set of tools with a common interface, we provide a modular, easily-extendable, and highly performant ecosystem for handling a wide variety of scientific simulations.
SciML tools are used by many organizations, such as (but not limited to!) the CliMA: Climate Modeling Alliance, the New York Federal Reserve Bank, the Julia Robotics community, Pumas-AI: Pharmaceutical Modeling and Simulation, and the Brazilian National Institute for Space Research (INPE).
Disclaimer: I am a Github admin and member of the steering council of SciML, so I'm definitely biased 🙃
Ordinary differential equation (ODE): Lotka-Volterra model
Differential equation model of predator-prey interaction:
lotkavolterra! (generic function with 1 method)
Problem formulation with initial value, integration time span, and default parameters:
ODEProblem with uType Vector{Float64} and tType Float64. In-place: true
timespan: (0.0, 10.0)
u0: 2-element Vector{Float64}:
1.0
1.0
Solve problem:
timestamp | value1 | value2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Float64 | Float64 | Float64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 | 0.0 | 1.0 | 1.0 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 | 0.0776085 | 1.04549 | 0.857668 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3 | 0.232645 | 1.17587 | 0.63946 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4 | 0.429119 | 1.41968 | 0.456996 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5 | 0.679082 | 1.87672 | 0.324733 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6 | 0.944405 | 2.58825 | 0.263363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7 | 1.26746 | 3.86071 | 0.279446 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
8 | 1.61929 | 5.75081 | 0.522007 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
9 | 1.98698 | 6.81498 | 1.91778 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
10 | 2.26409 | 4.393 | 4.19467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5.0744
0.391435
plot_lotkavolterra (generic function with 1 method)
Different parameter choices:
Note
Many more details and explanations can be found in the official documentation. If you notice that anything is missing, unclear, or incorrect, it's great if you open an issue or pull request! 🙏
Why don't we always use Euler's method?
Reference: Blog by Chris Rackauckas
A chaotic model of random neural networks (reference solution, computed with a high-order algorithm and very low tolerance):
A corresponding work-precision diagram:
Whenever someone in 2019 uses more code to internally implement a quick and dirty solver instead of running standard codes, a baby sheds a tear. It's not just about error or speed (or even accuracy: libraries undergo lots of tests!), it's about how much error you get with a certain speed. Euler's method (and even RK4) just don't scale well if you need non-trivial error on most equations.
Only ODEs?!
Supported equations include
Discrete equations (function maps, discrete stochastic (Gillespie/Markov) simulations)
Ordinary differential equations (ODEs)
Split and Partitioned ODEs (Symplectic integrators, IMEX Methods)
Stochastic ordinary differential equations (SODEs or SDEs)
Stochastic differential-algebraic equations (SDAEs)
Random differential equations (RODEs or RDEs)
Differential algebraic equations (DAEs)
Delay differential equations (DDEs)
Neutral, retarded, and algebraic delay differential equations (NDDEs, RDDEs, and DDAEs)
Stochastic delay differential equations (SDDEs)
Experimental support for stochastic neutral, retarded, and algebraic delay differential equations (SNDDEs, SRDDEs, and SDDAEs)
Mixed discrete and continuous equations (Hybrid Equations, Jump Diffusions)
(Stochastic) partial differential equations ((S)PDEs) (with both finite difference and finite element methods)
My relation to SciML
I wrote my master thesis about a mathematical model of quorum sensing of P. putida.
Note
Often biological processes do not occur instantaneously but with some delay.
Here lactonase activity is regulated by PpuR-AHL complex with a specific time delay:
Experimental data and numerical simulations:
doi:10.3390/app6050149 (adapted from doi:10.1007/s00216-014-8063-6)
Simulation with MATLAB (dde23)
Simulation with DelayDiffEq.jl
Similar issues with default settings:
Decreasing the step size improves the solution (also in MATLAB):
But this increases the number of steps and hence makes the computation slower! 😢
I really wanted to perform computations both efficiently and accurate.
So I decided to
work with Julia and improve DelayDiffEq
add support for more and also stiff methods based on the vast amount of existing methods for ODEs,
add callbacks that preserve domain constraints
Stiff methods
Methods such as MethodOfSteps(Rosenbrock23())
can solve the DDE without restricting the step size:
A simpler example: Mackey-Glass equation
Model of circulating blood cells
Given by
Blood cells are destroyed at rate
Their production rate depends on concentration
since[t]here is a significant delay
between the initiation of cellular production in the bone marrow and the release of mature cells into the blood
mackeyglass (generic function with 1 method)
mackeyglass_history (generic function with 1 method)
DDEProblem with uType Float64 and tType Float64. In-place: false
timespan: (0.0, 600.0)
u0: 0.5
Define DDE problem with
Only differential equations?!
Core components are
Differential Equation Solving
Physics-Informed Model Discovery and Learning
Bridges to Python and R
Compiler-Assisted Model Analysis and Sparsity Acceleration
ML-Assisted Tooling for Model Acceleration
Differentiable Scientific Data Structures and Simulators
Tools for Accelerated Algorithm Development and Research
Parameter estimation
Some noisy data:
SciML supports many different packages for local and global optimization such as Optim.jl, LeastSquaresOptim.jl, JuMP, and any package that implements the MathProgBase interface such as NLOpt.jl.
The default evoluationary optimization algorithm in the package BlackBoxOptim.jl yields the following optimal parameters:
1.5002
0.999047
2.99465
1.00247
Optimized trajectories:
Neural ODEs
Example 1
Neural ODE:
Example 2
Physics-informed neural ODE model (or rather biology-informed in this case):
Probabilistic modelling
We only know noisy (i.e., slightly incorrect) number of predator and prey for some days but not parameters.
Idea: model uncertainty of unknown parameters with probability distributions
Bayesian approach
Model uncertainty with conditional probability
of unknown parameters
E.g.,
: unknown parameters , , , , and that we want to infer : number of observed predator and prey
Bayes' theorem
Conditional probability
Workflow
Choose model
e.g., describes how daily cases of newly infected individuals depend on parameters
Choose prior
should incorporate initial beliefs and knowledge about
e.g.,
, , , , and are non-negative
Compute
⚠️ Issue
Often it is not possible to compute
Discrete approximation
Idea: Approximate
where
This implies that
and more generally
number of samples:
Probabilistic programming
Source: Lecture slides
Developing probabilistic models and inference algorithms is a time-consuming and error-prone process.
Probabilistic model written as a computer program
Automatic inference (integral part of the programming language)
Advantages:
Fast development of models
Expressive models
Widely applicable inference algorithms
Turing
Turing is a probabilistic programming language (PPL).
General design
Probabilistic models are implemented as a Julia function
One may use any Julia code inside of the model
Random variables and observations are declared with the
~
operator:@model function mymodel(x, y)...# random variable `a` with prior distribution `dist_a`a ~ dist_a...# observation `y` with data distribution `dist_y`y ~ dist_y...endPPL is implemented in DynamicPPL.jl, including
@model
macroTuring.jl integrates and reexports different parts of the ecosystem such as the PPL, inference algorithms, and tools for automatic differentiation
Bayesian inference of Lotka-Volterra model with Turing
A probabilistic model of the noisy observations of the Lotka-Volterra model:
where
It can be implemented in the Turing probabilistic programming language (PPL):
bayesian_lotkavolterra (generic function with 2 methods)
Prior distribution of trajectories
Markov chain Monte Carlo
seriestype density has been moved to StatsPlots. To use: `Pkg.add("StatsPlots"); using StatsPlots`
seriestype density has been moved to StatsPlots. To use: `Pkg.add("StatsPlots"); using StatsPlots`
seriestype density has been moved to StatsPlots. To use: `Pkg.add("StatsPlots"); using StatsPlots`
seriestype density has been moved to StatsPlots. To use: `Pkg.add("StatsPlots"); using StatsPlots`
seriestype density has been moved to StatsPlots. To use: `Pkg.add("StatsPlots"); using StatsPlots`
seriestype density has been moved to StatsPlots. To use: `Pkg.add("StatsPlots"); using StatsPlots`
seriestype density has been moved to StatsPlots. To use: `Pkg.add("StatsPlots"); using StatsPlots`
seriestype density has been moved to StatsPlots. To use: `Pkg.add("StatsPlots"); using StatsPlots`
seriestype density has been moved to StatsPlots. To use: `Pkg.add("StatsPlots"); using StatsPlots`
seriestype density has been moved to StatsPlots. To use: `Pkg.add("StatsPlots"); using StatsPlots`
seriestype density has been moved to StatsPlots. To use: `Pkg.add("StatsPlots"); using StatsPlots`
seriestype density has been moved to StatsPlots. To use: `Pkg.add("StatsPlots"); using StatsPlots`
seriestype density has been moved to StatsPlots. To use: `Pkg.add("StatsPlots"); using StatsPlots`
seriestype density has been moved to StatsPlots. To use: `Pkg.add("StatsPlots"); using StatsPlots`
seriestype density has been moved to StatsPlots. To use: `Pkg.add("StatsPlots"); using StatsPlots`
seriestype density has been moved to StatsPlots. To use: `Pkg.add("StatsPlots"); using StatsPlots`
seriestype density has been moved to StatsPlots. To use: `Pkg.add("StatsPlots"); using StatsPlots`
seriestype density has been moved to StatsPlots. To use: `Pkg.add("StatsPlots"); using StatsPlots`
seriestype density has been moved to StatsPlots. To use: `Pkg.add("StatsPlots"); using StatsPlots`
seriestype density has been moved to StatsPlots. To use: `Pkg.add("StatsPlots"); using StatsPlots`
Found initial step size
0.00625
Found initial step size
0.025
The current proposal will be rejected due to numerical error(s).
true
false
false
false
The current proposal will be rejected due to numerical error(s).
true
false
false
false
The current proposal will be rejected due to numerical error(s).
true
false
false
false
Found initial step size
0.05
Found initial step size
0.05
The current proposal will be rejected due to numerical error(s).
true
false
false
false
The current proposal will be rejected due to numerical error(s).
true
false
false
false
Posterior distribution of trajectories
Other frameworks
Again, the presentation is biased since I am part of the Turing team as well 🙃
However, SciML supports other PPLs (such as Stan) and "manual" (approximate) Bayesian inference with, e.g., DynamicHMC.jl and ApproxBayes.jl as well.
Example: COVID-19 replication study
Links: Blog post, Github repo
There is a lot more...
Many features of SciML and Turing and background information are not covered in this presentation.
Check out the SciML webpage https://sciml.ai, the Turing webpage https://turing.ml, and the documentation of the Julia packages.
You can also find a more detailed talks about DelayDiffEq, probabilistic modelling with Turing, and other research with Julia on my webpage: https://www.widmann.dev