This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def cross_entropy(Y, P): | |
Y = np.float_(Y) | |
P = np.float_(P) | |
return -np.sum(Y * np.log(P) + (1 - Y) * np.log(1 - P)) | |
Y = [1, 0, 1, 1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def softmax(L): | |
expL = np.exp(L) | |
sumExpL = sum(expL) | |
result = [] | |
for i in expL: | |
result.append(i * 1.0 / sumExpL) | |
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
# What does numpy.random.seed() do? - https://stackoverflow.com/questions/21494489/what-does-numpy-random-seed0-do | |
np.random.seed(42) | |
def stepFunction(t): | |
if t >= 0: | |
return 1 | |
return 0 |