-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtask4.py
48 lines (31 loc) · 923 Bytes
/
task4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Task 4
import numpy as np
from rsdl import Tensor
from rsdl.losses import loss_functions
X = Tensor(np.random.randn(100, 3))
coef = Tensor(np.array([-7, +3, -9]))
y = X @ coef + 6
# TODO: define w and b (y = w x + b) with random initialization ( you can use np.random.randn )
w = ...
b = ...
print(w)
print(b)
learning_rate = ...
batch_size = ...
for epoch in range(100):
epoch_loss = 0.0
for start in range(0, 100, batch_size):
end = start + batch_size
inputs = X[start:end]
# TODO: predicted
predicted = ...
actual = y[start:end]
# TODO: calcualte MSE loss
# TODO: backward
# hint you need to just do loss.backward()
epoch_loss += ...
# TODO: update w and b (Don't use 'w -= ' and use ' w = w - ...') (you don't need to use optim.SGD in this task)
w = ...
b = ...
print(w)
print(b)