Skip to content

Commit e23ad06

Browse files
committed
update code
1 parent 9c285c5 commit e23ad06

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

content/linear-algebra.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Linear algebra
1515
- 35 min teaching
1616
- 25 min exercises
1717

18+
.. callout::
19+
20+
The code in this lession is written for Julia v1.11.2.
21+
1822
Vectors and matrices in Julia
1923
-----------------------------
2024

content/regression.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Regression and time-series prediction
1515
- 90 min teaching
1616
- 60 min exercises
1717

18+
.. callout::
19+
20+
The code in this lession is written for Julia v1.11.2.
21+
1822
Linear regression with synthetic data
1923
-------------------------------------
2024

@@ -545,7 +549,7 @@ The mean pressure data field seems to contain some unreasonably large values. Le
545549
546550
using DataFrames, CSV, Plots, Statistics
547551
548-
# data_path = "C:/Users/davidek/julia_kurser/DailyDelhiClimateTrain.csv"
552+
# data_path = "C:/Users/davidek/julia_kurser/2025-02/DailyDelhiClimateTrain.csv"
549553
# full path to data files
550554
# uploaded in julia-for-hpda/content/data
551555
df_train = CSV.read(data_path, DataFrame)
@@ -602,7 +606,7 @@ Background on neural networks can be found here :download:`download slides </sli
602606
using MLJ: shuffle, partition
603607
using Flux: train!
604608
605-
# data_path = "C:/Users/davidek/julia_kurser/DailyDelhiClimateTrain.csv"
609+
# data_path = "C:/Users/davidek/julia_kurser/2025-02/DailyDelhiClimateTrain.csv"
606610
df = CSV.read(data_path, DataFrame)
607611
608612
# clean up data, drop rows
@@ -660,12 +664,11 @@ Background on neural networks can be found here :download:`download slides </sli
660664
Dense(10, 1, init=init, bias=true)
661665
)
662666
663-
loss(tX, ty) = Flux.Losses.mse(model(tX'), ty')
667+
loss(model, tX, ty) = Flux.Losses.mse(model(tX'), ty')
664668
665669
data = [(X_train, y_train)]
666670
667-
ps = Flux.params(model)
668-
opt = ADAM(0.01) # learning rate 0.01
671+
opt_state = Flux.setup(Adam(0.01), model) # learning rate 0.01
669672
670673
train_loss = []
671674
test_loss = []
@@ -675,7 +678,7 @@ Background on neural networks can be found here :download:`download slides </sli
675678
# replace the rest of the code from here with snippet below
676679
677680
for epoch in 1:n_epochs
678-
train!(loss, ps, data, opt)
681+
train!(loss, model, data, opt_state)
679682
ltrain = sqrt(loss(X_train, y_train))
680683
ltest = sqrt(loss(X_test, y_test))
681684
push!(train_loss, ltrain)

0 commit comments

Comments
 (0)