Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Image classification
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bourry Malo
Image classification
Commits
46e8b4cc
Commit
46e8b4cc
authored
1 year ago
by
Bourry Malo
Browse files
Options
Downloads
Patches
Plain Diff
question 10 - une itération de la descente du gradient
parent
cfaf9737
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
mlp.py
+35
-0
35 additions, 0 deletions
mlp.py
with
35 additions
and
0 deletions
mlp.py
0 → 100644
+
35
−
0
View file @
46e8b4cc
import
numpy
as
np
import
math
def
learn_once_mse
(
w1
:
np
.
ndarray
,
b1
:
np
.
ndarray
,
w2
:
np
.
ndarray
,
b2
:
np
.
ndarray
,
data
:
np
.
ndarray
,
targets
:
np
.
ndarray
,
learning_rate
:
float
):
# Forward pass
N
=
np
.
size
(
data
,
0
)
a0
=
data
# the data are the input of the first layer
z1
=
np
.
matmul
(
a0
,
w1
)
+
b1
# input of the hidden layer
a1
=
1
/
(
1
+
math
.
exp
(
-
z1
))
# output of the hidden layer (sigmoid activation function)
z2
=
np
.
matmul
(
a1
,
w2
)
+
b2
# input of the output layer
a2
=
1
/
(
1
+
math
.
exp
(
-
z2
))
# output of the output layer (sigmoid activation function)
predictions
=
a2
# the predicted values are the outputs of the output layer
# Compute loss (MSE)
loss
=
np
.
mean
((
predictions
-
targets
)
**
2
)
print
(
loss
)
#Compute gradient dW
da2
=
2
/
N
*
(
a2
-
targets
)
dz2
=
da2
*
a2
*
(
1
-
a2
)
dw2
=
dz2
*
a1
db2
=
dz2
da1
=
dz2
*
np
.
sum
(
w2
,
axis
=
1
)
dz1
=
da1
*
a1
*
(
1
*
a1
)
dw1
=
dz1
*
a0
db1
=
dz1
w1
-=
learning_rate
*
dw1
w2
-=
learning_rate
*
dw2
b1
-=
learning_rate
*
db1
b2
-=
learning_rate
*
db2
return
w1
,
b1
,
w2
,
b2
,
loss
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