Skip to content

Commit 3f50e0a

Browse files
committed
Merge branch 'update-2024-winter'
2 parents f12e1dc + 12a4d1d commit 3f50e0a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+419
-1335
lines changed

docs/make.jl

+25-26
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,33 @@ mv(download("$(site)icons/favicon.ico"), assetsdir("favicon.ico"); force)
1212

1313
# outline
1414
installation = [
15-
"Julia + Visual Studio Code" => "./installation/vscode.md",
16-
"Git" => "./installation/git.md",
15+
"Installation" => "./installation/installation.md",
1716
"Quickstart guide" => "./installation/tutorial.md",
1817
]
1918

2019
lecture_01 = [
2120
"Variables" => "./lecture_01/variables.md",
2221
"Elementary functions" => "./lecture_01/operators.md",
2322
"Strings" => "./lecture_01/strings.md",
23+
"Arrays" => "./lecture_01/arrays.md",
24+
"Data structures" => "./lecture_01/data_structures.md",
2425
]
2526

2627
lecture_02 = [
27-
"Arrays" => "./lecture_02/arrays.md",
28-
"Tuples and named tuples" => "./lecture_02/tuples.md",
29-
"Dictionaries" => "./lecture_02/dictionaries.md",
28+
"Funcion basics" => "./lecture_02/functions.md",
29+
"Conditional evaluations" => "./lecture_02/conditions.md",
30+
"Loops and iterators" => "./lecture_02/loops.md",
31+
"Soft local scope" => "./lecture_02/scope.md",
32+
"Exercises" => "./lecture_02/exercises.md",
3033
]
3134

3235
lecture_03 = [
33-
"Conditional evaluations" => "./lecture_03/conditions.md",
34-
"Loops and iterators" => "./lecture_03/loops.md",
35-
"Soft local scope" => "./lecture_03/scope.md",
36-
"Exercises" => "./lecture_03/exercises.md",
36+
"Standard library" => "./lecture_03/standardlibrary.md",
37+
"Package manager" => "./lecture_03/pkg.md",
38+
"Plots.jl" => "./lecture_03/Plots.md",
39+
"DataFrames.jl" => "./lecture_03/DataFrames.md",
40+
"Other useful packages" => "./lecture_03/otherpackages.md",
41+
"Interaction with other languages" => "./lecture_03/interaction.md",
3742
]
3843

3944
lecture_04 = [
@@ -45,24 +50,19 @@ lecture_04 = [
4550
]
4651

4752
lecture_05 = [
48-
"Standard library" => "./lecture_05/standardlibrary.md",
49-
"Plots.jl" => "./lecture_05/Plots.md",
50-
"DataFrames.jl" => "./lecture_05/DataFrames.md",
51-
"Other useful packages" => "./lecture_05/otherpackages.md",
52-
"Interaction with other languages" => "./lecture_05/interaction.md",
53+
"Abstract and composite types" => "./lecture_05/compositetypes.md",
54+
"Generic programming" => "./lecture_05/currencies.md",
5355
]
5456

5557
lecture_06 = [
56-
"Abstract and composite types" => "./lecture_06/compositetypes.md",
57-
"Generic programming" => "./lecture_06/currencies.md",
58+
"Files and modules" => "./lecture_06_07/modules.md",
59+
"Package development" => "./lecture_06_07/develop.md",
5860
]
5961

6062
lecture_07 = [
61-
"Files and modules" => "./lecture_07/modules.md",
62-
"Package manager" => "./lecture_07/pkg.md",
63-
"Package development" => "./lecture_07/develop.md",
6463
]
6564

65+
6666
lecture_08 = [
6767
"Introduction to continuous optimization" => "./lecture_08/theory.md",
6868
"Gradients" => "./lecture_08/gradients.md",
@@ -120,19 +120,18 @@ makedocs(;
120120
"Home" => "index.md",
121121
"Why Julia?" => "why.md",
122122
"Installation" => installation,
123-
"1: Variables and basic operators" => lecture_01,
124-
"2: Data structures" => lecture_02,
125-
"3: Control flow" => lecture_03,
123+
"1: Basics I" => lecture_01,
124+
"2: Basics II" => lecture_02,
125+
"3: Packages" => lecture_03,
126126
"4: Functions and methods" => lecture_04,
127-
"5: Packages" => lecture_05,
128-
"6: Type system and generic programming" => lecture_06,
129-
"7: Code organization" => lecture_07,
127+
"5: Type system and generic programming" => lecture_05,
128+
"6: Code organization I" => lecture_06,
129+
"7: Code organization II" => lecture_07,
130130
"8: Optimization" => lecture_08,
131131
"9: Regression and classification" => lecture_09,
132132
"10: Neural networks I." => lecture_10,
133133
"11: Neural networks II." => lecture_11,
134134
"12: Statistics" => lecture_12,
135-
"13: Ordinary differential equations" => lecture_13,
136135
],
137136
)
138137

docs/src/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ gr()
1111
```
1212

1313
Welcome to our course *Julia for Optimization and Learning*. This course consists of two parts:
14-
- *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).
14+
- *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).
1515
- *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.
1616

1717
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.
@@ -30,7 +30,7 @@ The main goals of the course are the following:
3030

3131
Selected examples of what you will be able to write at the end of the course include:
3232
- *Efficient coding*: The following plot can be created in twenty lines of code
33-
![](lecture_03/juliaset.gif)
33+
![](lecture_02/juliaset.gif)
3434
- *Numerical techniques*: You will learn many techniques to minimize functions
3535
![](lecture_08/anim1.gif)
3636
- *Neural networks*: And apply techniques to train neural networks

docs/src/installation/git.md

-38
This file was deleted.
-119 KB
Binary file not shown.
-96.6 KB
Binary file not shown.
-87.4 KB
Binary file not shown.
-155 KB
Binary file not shown.
-38.2 KB
Binary file not shown.

docs/src/installation/installation.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
## Installation
2+
3+
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/):
4+
5+
- **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
6+
7+
```powershell
8+
winget install julia -s msstore
9+
```
10+
11+
- **Linux** and **MacOS** users can install Julia and also Juliaup by running the following command
12+
13+
```shell
14+
curl -fsSL https://install.julialang.org | sh
15+
```
16+
17+
Once finished, the `julia` and `juliaup` commands should be available via command line interface.
18+
19+
!!! info "Other installation options:"
20+
For more options how to install Julia and Juliaup, see the [Juliaup Github repository](https://github.com/JuliaLang/juliaup).
21+
22+
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
23+
24+
```shell
25+
> juliaup add 1.10
26+
27+
> juliaup default 1.10
28+
Configured the default Julia version to be '1.10'.
29+
```
30+
31+
### Git
32+
33+
[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
34+
35+
```shell
36+
> git config --global user.name "<your_username>"
37+
38+
> git config --global user.email "<your_email_adress>"
39+
```
40+
41+
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.
42+
43+
!!! info "GitHub Account:"
44+
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/).
45+
46+
### Visual Studio Code
47+
48+
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.
49+
50+
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/#)
51+

docs/src/installation/vscode.md

-52
This file was deleted.

docs/src/installation/vscodeext_1.png

-365 KB
Binary file not shown.

docs/src/installation/vscodeext_2.png

-232 KB
Binary file not shown.

docs/src/installation/vscodeext_3.png

-119 KB
Binary file not shown.

docs/src/installation/vscodeext_4.png

-242 KB
Binary file not shown.
-83.4 KB
Binary file not shown.
-148 KB
Binary file not shown.
-58.7 KB
Binary file not shown.
-76.3 KB
Binary file not shown.
File renamed without changes.

docs/src/lecture_02/tuples.md docs/src/lecture_01/data_structures.md

+122-1
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,125 @@ julia> a, b, c = t
116116
117117
julia> println("The values stored in the tuple are: a = $a, b = $b")
118118
The values stored in the tuple are: a = 1, b = 2.0
119-
```
119+
```
120+
121+
## Dictionaries
122+
123+
Dictionaries are mutable, unordered (random order) collections of pairs of keys and values. The syntax for creating a dictionary is:
124+
125+
```jldoctest dicts
126+
julia> d = Dict("a" => [1, 2, 3], "b" => 1)
127+
Dict{String, Any} with 2 entries:
128+
"b" => 1
129+
"a" => [1, 2, 3]
130+
```
131+
132+
Another possibility is to use symbols instead of strings as keys.
133+
134+
```jldoctest dicts
135+
julia> d = Dict(:a => [1, 2, 3], :b => 1)
136+
Dict{Symbol, Any} with 2 entries:
137+
:a => [1, 2, 3]
138+
:b => 1
139+
```
140+
141+
!!! info "Symbol vs String:"
142+
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.
143+
144+
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.
145+
146+
```jldoctest dicts
147+
julia> d_test = Dict(1 => "a", 2.0 => "b", 3.0f0 => "c")
148+
Dict{Real, String} with 3 entries:
149+
2.0 => "b"
150+
3.0 => "c"
151+
1 => "a"
152+
```
153+
154+
!!! info "Ambiguous key values:"
155+
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.
156+
157+
```jldoctest dicts
158+
julia> d_test = Dict(1 => "a", 1.0 => "b", 1.0f0 => "c")
159+
Dict{Real, String} with 1 entry:
160+
1.0 => "c"
161+
```
162+
163+
Dictionary's elements can be accessed via square brackets and a key.
164+
165+
```jldoctest dicts
166+
julia> d[:a]
167+
3-element Vector{Int64}:
168+
1
169+
2
170+
3
171+
```
172+
173+
If the key does not exist in the dictionary, an error will occur if we try to access it.
174+
175+
```jldoctest dicts
176+
julia> d[:c]
177+
ERROR: KeyError: key :c not found
178+
179+
julia> haskey(d, :c)
180+
false
181+
```
182+
183+
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.
184+
185+
```jldoctest dicts
186+
julia> get(d, :c, 42)
187+
42
188+
```
189+
190+
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.
191+
192+
```jldoctest dicts
193+
julia> get!(d, :c, 42)
194+
42
195+
196+
julia> get!(d, :d, ["hello", "world"])
197+
2-element Vector{String}:
198+
"hello"
199+
"world"
200+
201+
julia> d
202+
Dict{Symbol, Any} with 4 entries:
203+
:a => [1, 2, 3]
204+
:b => 1
205+
:d => ["hello", "world"]
206+
:c => 42
207+
```
208+
209+
Unwanted keys from the dictionary can be removed by the `delete!` function.
210+
211+
```jldoctest dicts
212+
julia> delete!(d, :d)
213+
Dict{Symbol, Any} with 3 entries:
214+
:a => [1, 2, 3]
215+
:b => 1
216+
:c => 42
217+
218+
julia> haskey(d, :d)
219+
false
220+
```
221+
222+
An alternative is the `pop!` function, which removes the key from the dictionary, and returns the value corresponding to it.
223+
224+
```jldoctest dicts
225+
julia> pop!(d, :c)
226+
42
227+
228+
julia> haskey(d, :c)
229+
false
230+
```
231+
232+
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.
233+
234+
```jldoctest dicts
235+
julia> haskey(d, :c)
236+
false
237+
238+
julia> pop!(d, :c, 444)
239+
444
240+
```

0 commit comments

Comments
 (0)