Skip to content
Snippets Groups Projects
Commit 66c1bf48 authored by Maxxhim's avatar Maxxhim
Browse files

finish python files

parent f94b6a32
No related branches found
No related tags found
No related merge requests found
...@@ -94,7 +94,7 @@ class Linear: ...@@ -94,7 +94,7 @@ class Linear:
# TODO: Initialize the weights accordind to the description above. # TODO: Initialize the weights accordind to the description above.
# Ton't forget to wrap the data into a Variable. # Ton't forget to wrap the data into a Variable.
####################################################################### #######################################################################
self.W = None self.W = Variable(np.random.uniform(-np.sqrt(1/in_features), np.sqrt(1/in_features), (out_features, in_features)))
####################################################################### #######################################################################
# --------------------------- END OF YOUR CODE ------------------------ # --------------------------- END OF YOUR CODE ------------------------
####################################################################### #######################################################################
...@@ -104,7 +104,7 @@ class Linear: ...@@ -104,7 +104,7 @@ class Linear:
# TODO: Initialize the bias accordind to the description above. # TODO: Initialize the bias accordind to the description above.
# Ton't forget to wrap the data into a Variable. # Ton't forget to wrap the data into a Variable.
####################################################################### #######################################################################
self.b = None self.b = Variable(np.random.uniform(-np.sqrt(1/in_features), np.sqrt(1/in_features), (1, out_features)))
####################################################################### #######################################################################
# --------------------------- END OF YOUR CODE ------------------------ # --------------------------- END OF YOUR CODE ------------------------
####################################################################### #######################################################################
...@@ -116,7 +116,7 @@ class Linear: ...@@ -116,7 +116,7 @@ class Linear:
# TODO: Use the functional module to compute the first part of the # TODO: Use the functional module to compute the first part of the
# linear transfomation -> y = XW.T # linear transfomation -> y = XW.T
####################################################################### #######################################################################
y = None y = F.matmul(X, self.W.t())
####################################################################### #######################################################################
# --------------------------- END OF YOUR CODE ------------------------ # --------------------------- END OF YOUR CODE ------------------------
####################################################################### #######################################################################
...@@ -124,7 +124,7 @@ class Linear: ...@@ -124,7 +124,7 @@ class Linear:
####################################################################### #######################################################################
# TODO: If the bias is true add the bias. # TODO: If the bias is true add the bias.
####################################################################### #######################################################################
y = None y = y + self.b
####################################################################### #######################################################################
# --------------------------- END OF YOUR CODE ------------------------ # --------------------------- END OF YOUR CODE ------------------------
####################################################################### #######################################################################
......
...@@ -23,7 +23,7 @@ class Optimizer: ...@@ -23,7 +23,7 @@ class Optimizer:
class SGD(Optimizer): class SGD(Optimizer):
""" """
Applies the SGD update to the weights W = lr * W.grad. Applies the SGD update to the weights W = W - lr * W.grad.
""" """
def __init__(self, parameters, lr=1e-3): def __init__(self, parameters, lr=1e-3):
...@@ -37,6 +37,12 @@ class SGD(Optimizer): ...@@ -37,6 +37,12 @@ class SGD(Optimizer):
# to acces the data of parametes Variables: # to acces the data of parametes Variables:
# - self.parameters.params[key].data # - self.parameters.params[key].data
####################################################################### #######################################################################
w1 = self.parameters.params["layer1_W"]
w2 = self.parameters.params["layer2_W"]
w1.data -= self.lr * w1.grad
w2.data -= self.lr * w2.grad
pass pass
####################################################################### #######################################################################
# --------------------------- END OF YOUR CODE ------------------------ # --------------------------- END OF YOUR CODE ------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment