-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpy5.py
More file actions
36 lines (28 loc) · 880 Bytes
/
py5.py
File metadata and controls
36 lines (28 loc) · 880 Bytes
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
import math
# An exmaple output from the outer layer of the neural network
softmax_output = [0.7, 0.1, 0.2]
# Ground truth
target_output = [1, 0, 0]
loss = -(math.log(softmax_output[0])*target_output[0] +
math.log(softmax_output[1])*target_output[1] +
math.log(softmax_output[2])*target_output[2])
print(loss)
# target_output[1] and [2] are 0, so anything multiplied by them is 0
# target_output[0] is = 1 (since target_output is a one-hot target) and
# anything multiplied by 1 is itself, thus:
loss_simple = -math.log(softmax_output[0])
print(loss_simple)
print('-------')
# print(math.log(0))
print(math.log(1.))
print(math.log(0.95))
print(math.log(0.9))
print(math.log(0.8))
print('...')
print(math.log(0.2))
print(math.log(0.1))
print(math.log(0.05))
print(math.log(0.01))
# Testing the Natural Log
print(math.log(5.2))
print(2.718281829**1.64866)