Skip to content
Snippets Groups Projects
Commit 755d794d authored by Vedrana Andersen Dahl's avatar Vedrana Andersen Dahl
Browse files

Create QUIZ_week8_solution.ipynb

parent 8ca30062
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` python
import math
x = -120
# hidden layer with ReLu
h1 = max(-10 - 0.1 * x, 0)
h2 = max(0.15 * x, 0)
# output layer
y1_hat = 4 + 0.5 * h1
y2_hat = 2.1 * h1 + 0.2 * h2
# softmax
y1 = math.exp(y1_hat) / (math.exp(y1_hat) + math.exp(y2_hat))
y2 = math.exp(y2_hat) / (math.exp(y1_hat) + math.exp(y2_hat))
# loss
loss = -math.log(y2) # since we know it belongs to class 2
# partial derivative, we know that t2 = 1
dLdw22 = h1 * (y1 - 0)
```
%% Cell type:code id: tags:
``` python
print(f'{y1 = }')
print(f'{loss = }')
print(f'{dLdw22 = }')
```
%% Output
y1 = 0.6899744811276124
loss = 1.1711006659477776
dLdw22 = 1.3799489622552248
%% Cell type:code id: tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment