Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HPC_Machine_Learning_TP_Final
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
maxime.clercq
HPC_Machine_Learning_TP_Final
Commits
66c1bf48
Commit
66c1bf48
authored
5 years ago
by
Maxxhim
Browse files
Options
Downloads
Patches
Plain Diff
finish python files
parent
f94b6a32
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
nn.py
+4
-4
4 additions, 4 deletions
nn.py
optim.py
+7
-1
7 additions, 1 deletion
optim.py
with
11 additions
and
5 deletions
nn.py
+
4
−
4
View file @
66c1bf48
...
@@ -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 ------------------------
#######################################################################
#######################################################################
...
...
This diff is collapsed.
Click to expand it.
optim.py
+
7
−
1
View file @
66c1bf48
...
@@ -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 ------------------------
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment