Skip to content

Commit

Permalink
Merge branch 'update-2024-winter'
Browse files Browse the repository at this point in the history
  • Loading branch information
VaclavMacha committed Sep 22, 2024
2 parents f12e1dc + 12a4d1d commit 3f50e0a
Show file tree
Hide file tree
Showing 64 changed files with 419 additions and 1,335 deletions.
51 changes: 25 additions & 26 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,33 @@ mv(download("$(site)icons/favicon.ico"), assetsdir("favicon.ico"); force)

# outline
installation = [
"Julia + Visual Studio Code" => "./installation/vscode.md",
"Git" => "./installation/git.md",
"Installation" => "./installation/installation.md",
"Quickstart guide" => "./installation/tutorial.md",
]

lecture_01 = [
"Variables" => "./lecture_01/variables.md",
"Elementary functions" => "./lecture_01/operators.md",
"Strings" => "./lecture_01/strings.md",
"Arrays" => "./lecture_01/arrays.md",
"Data structures" => "./lecture_01/data_structures.md",
]

lecture_02 = [
"Arrays" => "./lecture_02/arrays.md",
"Tuples and named tuples" => "./lecture_02/tuples.md",
"Dictionaries" => "./lecture_02/dictionaries.md",
"Funcion basics" => "./lecture_02/functions.md",
"Conditional evaluations" => "./lecture_02/conditions.md",
"Loops and iterators" => "./lecture_02/loops.md",
"Soft local scope" => "./lecture_02/scope.md",
"Exercises" => "./lecture_02/exercises.md",
]

lecture_03 = [
"Conditional evaluations" => "./lecture_03/conditions.md",
"Loops and iterators" => "./lecture_03/loops.md",
"Soft local scope" => "./lecture_03/scope.md",
"Exercises" => "./lecture_03/exercises.md",
"Standard library" => "./lecture_03/standardlibrary.md",
"Package manager" => "./lecture_03/pkg.md",
"Plots.jl" => "./lecture_03/Plots.md",
"DataFrames.jl" => "./lecture_03/DataFrames.md",
"Other useful packages" => "./lecture_03/otherpackages.md",
"Interaction with other languages" => "./lecture_03/interaction.md",
]

lecture_04 = [
Expand All @@ -45,24 +50,19 @@ lecture_04 = [
]

lecture_05 = [
"Standard library" => "./lecture_05/standardlibrary.md",
"Plots.jl" => "./lecture_05/Plots.md",
"DataFrames.jl" => "./lecture_05/DataFrames.md",
"Other useful packages" => "./lecture_05/otherpackages.md",
"Interaction with other languages" => "./lecture_05/interaction.md",
"Abstract and composite types" => "./lecture_05/compositetypes.md",
"Generic programming" => "./lecture_05/currencies.md",
]

lecture_06 = [
"Abstract and composite types" => "./lecture_06/compositetypes.md",
"Generic programming" => "./lecture_06/currencies.md",
"Files and modules" => "./lecture_06_07/modules.md",
"Package development" => "./lecture_06_07/develop.md",
]

lecture_07 = [
"Files and modules" => "./lecture_07/modules.md",
"Package manager" => "./lecture_07/pkg.md",
"Package development" => "./lecture_07/develop.md",
]


lecture_08 = [
"Introduction to continuous optimization" => "./lecture_08/theory.md",
"Gradients" => "./lecture_08/gradients.md",
Expand Down Expand Up @@ -120,19 +120,18 @@ makedocs(;
"Home" => "index.md",
"Why Julia?" => "why.md",
"Installation" => installation,
"1: Variables and basic operators" => lecture_01,
"2: Data structures" => lecture_02,
"3: Control flow" => lecture_03,
"1: Basics I" => lecture_01,
"2: Basics II" => lecture_02,
"3: Packages" => lecture_03,
"4: Functions and methods" => lecture_04,
"5: Packages" => lecture_05,
"6: Type system and generic programming" => lecture_06,
"7: Code organization" => lecture_07,
"5: Type system and generic programming" => lecture_05,
"6: Code organization I" => lecture_06,
"7: Code organization II" => lecture_07,
"8: Optimization" => lecture_08,
"9: Regression and classification" => lecture_09,
"10: Neural networks I." => lecture_10,
"11: Neural networks II." => lecture_11,
"12: Statistics" => lecture_12,
"13: Ordinary differential equations" => lecture_13,
],
)

Expand Down
4 changes: 2 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ gr()
```

Welcome to our course *Julia for Optimization and Learning*. This course consists of two parts:
- *Basics of Julia*: [Julia](https://julialang.org/) is a fast programming language for scientific computing. Designed and developed at MIT, it quickly keeps gaining popularity and scored rank 22 among programming languages in the [PYPL rating](https://pypl.github.io/PYPL.html) (as of September 2021).
- *Basics of Julia*: [Julia](https://julialang.org/) is a fast programming language for scientific computing. Designed and developed at MIT, it quickly keeps gaining popularity and scored rank 25 among programming languages in the [PYPL rating](https://pypl.github.io/PYPL.html) (as of September 2024).
- *Applications*: The second part of the course will be dedicated to applications. The main emphasis will given to machine learning, but we will also go through statistics and differential equations.

This course is taught at the [Czech Technical University](https://www.cvut.cz/en/) in Prague. It is part of the [prg.ai minor](https://prg.ai/minor/), a study programme combining top courses from four faculties of two Prague universities.
Expand All @@ -30,7 +30,7 @@ The main goals of the course are the following:

Selected examples of what you will be able to write at the end of the course include:
- *Efficient coding*: The following plot can be created in twenty lines of code
![](lecture_03/juliaset.gif)
![](lecture_02/juliaset.gif)
- *Numerical techniques*: You will learn many techniques to minimize functions
![](lecture_08/anim1.gif)
- *Neural networks*: And apply techniques to train neural networks
Expand Down
38 changes: 0 additions & 38 deletions docs/src/installation/git.md

This file was deleted.

Binary file removed docs/src/installation/gitinstall_1.png
Binary file not shown.
Binary file removed docs/src/installation/gitinstall_2.png
Binary file not shown.
Binary file removed docs/src/installation/gitinstall_3.png
Binary file not shown.
Binary file removed docs/src/installation/gitsettings_1.png
Binary file not shown.
Binary file removed docs/src/installation/gitsettings_2.png
Binary file not shown.
51 changes: 51 additions & 0 deletions docs/src/installation/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
## Installation

There are multiple ways how to install Julia and it's version manager Juliaup. We recommend to follow the [official documentation](https://julialang.org/downloads/):

- **Windows** users can install Julia and also Juliaup directly from [Windows Store](https://apps.microsoft.com/detail/9njnww8pvkmn?hl=cs-cz&gl=CZ) or equivalently use the following command

```powershell
winget install julia -s msstore
```

- **Linux** and **MacOS** users can install Julia and also Juliaup by running the following command

```shell
curl -fsSL https://install.julialang.org | sh
```

Once finished, the `julia` and `juliaup` commands should be available via command line interface.

!!! info "Other installation options:"
For more options how to install Julia and Juliaup, see the [Juliaup Github repository](https://github.com/JuliaLang/juliaup).

For the upcoming course, we recommend to install Julia version 1.10 and set is as a default Julia. It can be done in the following way

```shell
> juliaup add 1.10

> juliaup default 1.10
Configured the default Julia version to be '1.10'.
```

### Git

[Git](https://git-scm.com/) is a distributed version control system for tracking changes in any set of text files. It is designed for coordinating work among cooperating programmers during software development. Git installer can be download from the official [download page](https://git-scm.com/downloads). Download the proper installer, run it and follow the instructions. Before using Git, we need to make the necessary settings. It can be done easily using command line interface the two following commands

```shell
> git config --global user.name "<your_username>"

> git config --global user.email "<your_email_adress>"
```

The commands above set the user name and email for Git. Because Git is designed for collaboration between multiple people, this information is used to track who made which changes.

!!! info "GitHub Account:"
The Julia package system is based on Git, and the Julia project is hosted on [GitHub](https://github.com/). GitHub is a service that provides internet hosting for software development and version control using Git. We use GitHub to host all the materials and final projects in this course. Therefore, every student needs to create a GitHub account to be able to finish the course. It can be done in a few steps on the official [GitHub page](https://github.com/).

### Visual Studio Code

It is possible to write Julia codes in any text editor, and run them directly from the terminal. However, it is usually better to use an IDE that provides additional features such as syntax highlighting, or code suggestions. We recommend using [Visual Studio Code](https://code.visualstudio.com/), a free source-code editor made by Microsoft. It supports many programming languages (Julia, Python, LaTex, ...) via extensions. The editor is available at the official [download page](https://code.visualstudio.com/download). Download the proper installer, run it and follow the instructions.

To use the VS Code as an IDE for Julia, we have to install the [Julia extension](https://marketplace.visualstudio.com/items?itemName=julialang.language-julia). It can be done directly from the VS Code. Open the `Extension MarketPlace` by pressing the button in the `Activity bar` (the left bar). Type `julia` in the search bar and select the Julia extension. Then press the `Install` button to install the extension. For more information see the [official documentation](https://www.julia-vscode.org/docs/stable/#)

52 changes: 0 additions & 52 deletions docs/src/installation/vscode.md

This file was deleted.

Binary file removed docs/src/installation/vscodeext_1.png
Binary file not shown.
Binary file removed docs/src/installation/vscodeext_2.png
Binary file not shown.
Binary file removed docs/src/installation/vscodeext_3.png
Binary file not shown.
Binary file removed docs/src/installation/vscodeext_4.png
Binary file not shown.
Binary file removed docs/src/installation/vscodeinstall_1.png
Binary file not shown.
Binary file removed docs/src/installation/vscodeinstall_2.png
Binary file not shown.
Binary file removed docs/src/installation/vscodeinstall_3.png
Binary file not shown.
Binary file removed docs/src/installation/vscodeinstall_4.png
Binary file not shown.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,125 @@ julia> a, b, c = t
julia> println("The values stored in the tuple are: a = $a, b = $b")
The values stored in the tuple are: a = 1, b = 2.0
```
```

## Dictionaries

Dictionaries are mutable, unordered (random order) collections of pairs of keys and values. The syntax for creating a dictionary is:

```jldoctest dicts
julia> d = Dict("a" => [1, 2, 3], "b" => 1)
Dict{String, Any} with 2 entries:
"b" => 1
"a" => [1, 2, 3]
```

Another possibility is to use symbols instead of strings as keys.

```jldoctest dicts
julia> d = Dict(:a => [1, 2, 3], :b => 1)
Dict{Symbol, Any} with 2 entries:
:a => [1, 2, 3]
:b => 1
```

!!! info "Symbol vs String:"
The use of `Symbol` type might be preferable in certain cases, since its core representation is different. The string `"foo"` is a string literal and evaluates to the string "foo". On the other hand, `Symbol` is a construct used internally to represent a variable in [metaprogramming](https://docs.julialang.org/en/v1/manual/metaprogramming/). Thanks to its internal representation, some operations (like comparison `==`) can be faster on Symbols than on Strings.

It is possible to use almost any type as a key in a dictionary. Note the element types in the dictionary, when Julia tries to infer the best type to represent keys and values.

```jldoctest dicts
julia> d_test = Dict(1 => "a", 2.0 => "b", 3.0f0 => "c")
Dict{Real, String} with 3 entries:
2.0 => "b"
3.0 => "c"
1 => "a"
```

!!! info "Ambiguous key values:"
Be aware of using correct keys. In this definition, since both key values are essentially the same, the resulting dictionary has only one key with the last value.

```jldoctest dicts
julia> d_test = Dict(1 => "a", 1.0 => "b", 1.0f0 => "c")
Dict{Real, String} with 1 entry:
1.0 => "c"
```

Dictionary's elements can be accessed via square brackets and a key.

```jldoctest dicts
julia> d[:a]
3-element Vector{Int64}:
1
2
3
```

If the key does not exist in the dictionary, an error will occur if we try to access it.

```jldoctest dicts
julia> d[:c]
ERROR: KeyError: key :c not found
julia> haskey(d, :c)
false
```

The `haskey` function checks whether the dictionary has the `:c` key. To avoid such errors, we can use the `get` function that accepts three arguments: a dictionary, key, and a default value for this key, which is returned if the key does not exist in the dictionary.

```jldoctest dicts
julia> get(d, :c, 42)
42
```

There is also an in-place version of the `get` function. The `get!` function adds the default value to the dictionary if the key does not exist.

```jldoctest dicts
julia> get!(d, :c, 42)
42
julia> get!(d, :d, ["hello", "world"])
2-element Vector{String}:
"hello"
"world"
julia> d
Dict{Symbol, Any} with 4 entries:
:a => [1, 2, 3]
:b => 1
:d => ["hello", "world"]
:c => 42
```

Unwanted keys from the dictionary can be removed by the `delete!` function.

```jldoctest dicts
julia> delete!(d, :d)
Dict{Symbol, Any} with 3 entries:
:a => [1, 2, 3]
:b => 1
:c => 42
julia> haskey(d, :d)
false
```

An alternative is the `pop!` function, which removes the key from the dictionary, and returns the value corresponding to it.

```jldoctest dicts
julia> pop!(d, :c)
42
julia> haskey(d, :c)
false
```

Optionally, it is possible to add a default value for a given key to the `pop!` function, which is returned if the key does not exist in the given dictionary.

```jldoctest dicts
julia> haskey(d, :c)
false
julia> pop!(d, :c, 444)
444
```
Loading

0 comments on commit 3f50e0a

Please sign in to comment.