Skip to content

Commit

Permalink
add plot in introduction
Browse files Browse the repository at this point in the history
  • Loading branch information
vituri committed Jul 27, 2024
1 parent fa819f2 commit 06847ee
Show file tree
Hide file tree
Showing 8 changed files with 1,402 additions and 254 deletions.
465 changes: 465 additions & 0 deletions .jupyter_cache/executed/92eb2f6c7e8c6dd52a2e0f759d52a6fe/base.ipynb

Large diffs are not rendered by default.

563 changes: 563 additions & 0 deletions .jupyter_cache/executed/e30a6e8fe7d08c970fc893851d731117/base.ipynb

Large diffs are not rendered by default.

Binary file modified .jupyter_cache/global.db
Binary file not shown.
10 changes: 7 additions & 3 deletions _freeze/index/execute-results/html.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ format:
max-width: 90vw
preview-links: true
# code-fold: true
toc-depth: 4
number-depth: 3
toc-expand: true
code-tools: true
grid:
sidebar-width: 300px
Expand Down
563 changes: 327 additions & 236 deletions docs/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
"href": "index.html#why-julia-for-topological-data-analysis",
"title": "TDA Workshop - EBT 2024",
"section": "1.1 Why Julia for topological data analysis?",
"text": "1.1 Why Julia for topological data analysis?\nIn a world ruled by Python (and, in some areas, R), why use an exquisite and new language like Julia in this workshop? You can find some good reasons in the book Julia Data Science, but I will give some in the context of topology:\n\n\n\n\n\n\nReason 1\n\n\n\nJulia is fast. You won’t need to use another language to make some expensive computation.\n\n\nLet’s say you read about a new algorithm to calculate the Vietoris-Rips. If you are a R/Python user, your algorithm won’t be written in R/Python simply because R/Python is slow. Fast code in R/Python is written in C, C++, Fortran or Rust; this is called the two language problem. Julia solves this because with enought knowledge about the compiler and the language, you will get performance nearly as good as if it was written in C. Optimize Julia code is not a trivial task, but is way easier than learning another language just to get good performance in some functions.\n\n\n\nThe famous deep learning package torch in Python has its core written mostly in C++. Python is just a “glue” interface.\n\n\n\n\n\nThe deep learning package Flux.jl is 100% written in Julia.\n\n\n\n\n\n\n\n\nReason 2\n\n\n\nIt is easy to use another language inside Julia.\n\n\nEven though Julia is fast and has a robust ecosystem, Python and R have many more packages already good-to-go. You can use them easily with tools like PythonCall or RCall.\n\n\n\n\n\n\nReason 3\n\n\n\nJulia looks like mathematics and has an elegant syntax.\n\n\n\nBeing able to mix LaTeX symbols with code can make the code way more readable.\n\nYou can find many nice examples on BeautifulAlgorithms.jl. Below are some common Julia code:\n\n# calculate the intersection of two vectors/sets\n[1, 2] ∩ [2, 3, 4]\n\n1-element Vector{Int64}:\n 2\n\n\n\n# check if a value is in a vector/set\n1 ∉ [2, 3]\n\ntrue\n\n\n\n# define a function in one line\nf(r) = π*r^2\n\nf(3)\n\n28.274333882308138\n\n\n\n# Euler's identity\nℯ^(im * π) + 1 |> round\n\n0.0 + 0.0im\n\n\n\n# calculating the pairwise-distance between points in a set\nX = [1, 2, 3, 4]\nd(x, y) = abs(x - y)\n[d(xᵢ, xⱼ) for xᵢ ∈ X, xⱼ ∈ X]\n\n4×4 Matrix{Int64}:\n 0 1 2 3\n 1 0 1 2\n 2 1 0 1\n 3 2 1 0\n\n\n\nEasily apply a function to all elements of a vector/set:\n\n\nx = [1, 2, 3, 4]\n\n# broadcast\nsin.(x)\n\n4-element Vector{Float64}:\n 0.8414709848078965\n 0.9092974268256817\n 0.1411200080598672\n -0.7568024953079282\n\n\n\n# mapping\nmap(sin, x)\n\n4-element Vector{Float64}:\n 0.8414709848078965\n 0.9092974268256817\n 0.1411200080598672\n -0.7568024953079282\n\n\n\n# list comprehension\n[sin(x_i) for x_i ∈ x]\n\n4-element Vector{Float64}:\n 0.8414709848078965\n 0.9092974268256817\n 0.1411200080598672\n -0.7568024953079282\n\n\n\nYou can compose functions in the reading order\n\nInstead of writing\n\nsin(cos(1))\n\n0.5143952585235492\n\n\nyou can “pipe” the functions as in\n\n1 |> cos |> sin\n\n0.5143952585235492\n\n\n\nJulia is a functional programming language with type hierarchy, which means that we have “categories” (types) and “functors” (functions) mapping between the types; moreover, its polimorphism means that the functions depend on the type of its arguments.\n\nFor example, suppose you want to define the norm of a vector:\n\nx = [1, 2, 3]\n\n# define the norm of a Vector of Numbers\nnorm(x::Vector{<:Number}) = x.^2 |> sum |> sqrt\nnorm(x)\n\n3.7416573867739413\n\n\nYou can also define the norm of a function \\(f\\) as the approximate integral of \\(|f|\\) on the interval \\([0, 1]\\):\n\nstep_size = 0.0001\nnorm(f::Function) = [abs(f(x) * step_size) for x ∈ 0:step_size:1] |> sum\nnorm(sin)\n\n0.45973976729801924\n\n\nwhich is very close to\n\nabs(cos(1) - cos(0))\n\n0.45969769413186023\n\n\nWhy not define the norm of a text as the amount of characters?\n\nnorm(s::AbstractString) = length(s)\nnorm(\"Hello!\")\n\n6",
"text": "1.1 Why Julia for topological data analysis?\nIn a world ruled by Python (and, in some areas, R), why use an exquisite and new language like Julia in this workshop? You can find some good reasons in the book Julia Data Science, but I will give some in the context of topology:\n\n1.1.1 Speed\n\n\n\n\n\n\nJulia is fast. You won’t need to use another language to make some expensive computation.\n\n\n\nLet’s say you read about a new algorithm to calculate the Vietoris-Rips. If you are a R/Python user, your algorithm won’t be written in R/Python simply because R/Python is slow. Fast code in R/Python is written in C, C++, Fortran or Rust; this is called the two language problem. Julia solves this because with enought knowledge about the compiler and the language, you will get performance nearly as good as if it was written in C. Optimize Julia code is not a trivial task, but is way easier than learning another language just to get good performance in some functions.\n\n\n\nThe famous deep learning package torch in Python has its core written mostly in C++. Python is just a “glue” interface.\n\n\n\n\n\nThe deep learning package Flux.jl is 100% written in Julia.\n\n\n\n\n1.1.2 Use other languages\n\n\n\n\n\n\nIt is easy to use another language inside Julia.\n\n\n\nEven though Julia is fast and has a robust ecosystem, Python and R have many more packages already good-to-go. You can use them easily with tools like PythonCall or RCall.\n\n\n1.1.3 Mathematical syntax\n\n\n\n\n\n\nJulia looks like mathematics and has an elegant syntax.\n\n\n\n\nLaTeX symbols\nBeing able to mix LaTeX symbols with code can make the code way more readable.\nYou can find many nice examples on BeautifulAlgorithms.jl. Below are some common Julia code:\n\n# calculate the intersection of two vectors/sets\n[1, 2] ∩ [2, 3, 4]\n\n1-element Vector{Int64}:\n 2\n\n\n\n# check if a value is in a vector/set\n1 ∉ [2, 3]\n\ntrue\n\n\n\n# define a function in one line\nf(r) = π*r^2\n\nf(3)\n\n28.274333882308138\n\n\n\n# Euler's identity\nℯ^(im * π) + 1 |> round\n\n0.0 + 0.0im\n\n\n\n# calculating the pairwise-distance between points in a set\nX = [1, 2, 3, 4]\nd(x, y) = abs(x - y)\n[d(xᵢ, xⱼ) for xᵢ ∈ X, xⱼ ∈ X]\n\n4×4 Matrix{Int64}:\n 0 1 2 3\n 1 0 1 2\n 2 1 0 1\n 3 2 1 0\n\n\n\n\nBroadcasting\nEasily apply a function to all elements of a vector/set:\n\nx = [1, 2, 3, 4]\n\n# broadcast\nsin.(x)\n\n4-element Vector{Float64}:\n 0.8414709848078965\n 0.9092974268256817\n 0.1411200080598672\n -0.7568024953079282\n\n\n\n# mapping\nmap(sin, x)\n\n4-element Vector{Float64}:\n 0.8414709848078965\n 0.9092974268256817\n 0.1411200080598672\n -0.7568024953079282\n\n\n\n# list comprehension\n[sin(x_i) for x_i ∈ x]\n\n4-element Vector{Float64}:\n 0.8414709848078965\n 0.9092974268256817\n 0.1411200080598672\n -0.7568024953079282\n\n\n\n\nPiping\nYou can compose functions in the reading order. Instead of writing:\n\nsin(cos(1))\n\n0.5143952585235492\n\n\nyou can “pipe” the functions as in:\n\n1 |> cos |> sin\n\n0.5143952585235492\n\n\n\n\nFunctional programming\nJulia is a functional programming language with type hierarchy, which means that we have “categories” (ie. types) and “functors” (ie. functions) mapping between the types; moreover, its polimorphism means that the functions depend on the type of its arguments.\nFor example, suppose you want to define the norm of a vector:\n\nx = [1, 2, 3]\n\n# define the norm of a Vector of Numbers\nnorm(x::Vector{<:Number}) = x.^2 |> sum |> sqrt\nnorm(x)\n\n3.7416573867739413\n\n\nYou can also define the norm of a function \\(f\\) as the approximate integral of \\(|f|\\) on the interval \\([0, 1]\\):\n\n# norm on [0, 1]\nnorm(f::Function; step_size = 0.0001) = \n [f(x) * step_size for x ∈ 0:step_size:1] .|> \n abs |> sum\n\nsquare = x -> x^2\n \nnorm(square)\n\n0.33338333500000006\n\n\nwhich is very close to the real definite integral.\nPS: plotting is also as easy as:\n\nusing Plots;\nplot(square, 0:0.1:1)\n\n\n\n\n \n \n \n\n\n\n \n \n \n\n\n\n \n \n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nWhy not define the norm of a text as the amount of characters?\n\nnorm(s::AbstractString) = length(s)\nnorm(\"Hello!\")\n\n6",
"crumbs": [
"<span class='chapter-number'>1</span>  <span class='chapter-title'>Introduction</span>"
]
Expand Down
50 changes: 36 additions & 14 deletions index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ jupyter: julia-1.10

In a world ruled by Python (and, in some areas, R), why use an exquisite and new language like Julia in this workshop? You can find some good reasons in the book [Julia Data Science](https://juliadatascience.io/programmers), but I will give some in the context of topology:

::: {.callout-tip title="Reason 1"}
### Speed

::: {.callout-tip title="" appearance="simple"}

Julia is fast. You won't need to use another language to make some expensive computation.

Expand All @@ -25,21 +27,27 @@ Let's say you read about a new algorithm to calculate the Vietoris-Rips. If you

![The deep learning package [`Flux.jl`](https://github.com/FluxML/Flux.jl) is 100% written in Julia.](images/intro/flux.png)

::: {.callout-tip title="Reason 2"}
### Use other languages

::: {.callout-tip title="" appearance="simple"}

It is easy to use another language inside Julia.

:::

Even though Julia is fast and has a robust ecosystem, Python and R have many more packages already good-to-go. You can use them easily with tools like [PythonCall](https://github.com/JuliaPy/PythonCall.jl) or [RCall](https://github.com/JuliaInterop/RCall.jl).

::: {.callout-tip title="Reason 3"}
### Mathematical syntax

::: {.callout-tip title="" appearance="simple"}

Julia looks like mathematics and has an elegant syntax.

:::

1) Being able to mix LaTeX symbols with code can make the code way more readable.
#### LaTeX symbols

Being able to mix LaTeX symbols with code can make the code way more readable.

You can find many nice examples on [BeautifulAlgorithms.jl](https://github.com/mossr/BeautifulAlgorithms.jl). Below are some common Julia code:

Expand Down Expand Up @@ -72,7 +80,9 @@ d(x, y) = abs(x - y)
[d(xᵢ, xⱼ) for xᵢ ∈ X, xⱼ ∈ X]
```

2) Easily apply a function to all elements of a vector/set:
#### Broadcasting

Easily apply a function to all elements of a vector/set:

```{julia}
x = [1, 2, 3, 4]
Expand All @@ -91,21 +101,23 @@ map(sin, x)
[sin(x_i) for x_i ∈ x]
```

3) You can compose functions in the reading order
#### Piping

Instead of writing
You can compose functions in the reading order. Instead of writing:

```{julia}
sin(cos(1))
```

you can "pipe" the functions as in
you can "pipe" the functions as in:

```{julia}
1 |> cos |> sin
```

4) Julia is a functional programming language with type hierarchy, which means that we have "categories" (types) and "functors" (functions) mapping between the types; moreover, its polimorphism means that the functions depend on the type of its arguments.
#### Functional programming

Julia is a [functional programming language](https://en.wikipedia.org/wiki/Functional_programming) with type hierarchy, which means that we have "categories" (ie. types) and "functors" (ie. functions) mapping between the types; moreover, its polimorphism means that the functions depend on the type of its arguments.

For example, suppose you want to define the norm of a vector:

Expand All @@ -120,24 +132,34 @@ norm(x)
You can also define the norm of a function $f$ as the approximate integral of $|f|$ on the interval $[0, 1]$:

```{julia}
step_size = 0.0001
norm(f::Function) = [abs(f(x) * step_size) for x ∈ 0:step_size:1] |> sum
norm(sin)
# norm on [0, 1]
norm(f::Function; step_size = 0.0001) =
[f(x) * step_size for x ∈ 0:step_size:1] .|>
abs |> sum
square = x -> x^2
norm(square)
```

which is very close to
which is very close to the real definite integral.

PS: plotting is also as easy as:

```{julia}
abs(cos(1) - cos(0))
using Plots;
plot(square, 0:0.1:1)
```


Why not define the norm of a text as the amount of characters?

```{julia}
norm(s::AbstractString) = length(s)
norm("Hello!")
```


## Why TDA?

Topological Data Analysis is a very curious field of mathematics that apply tools from topology and algebraic topology in the study of datasets. By "datasets", we almost always mean "finite metric space".
Expand Down

0 comments on commit 06847ee

Please sign in to comment.