Last active
May 19, 2020 05:03
-
-
Save vamc-stash/3e25838f9d7cc496e23260e5fee2ab17 to your computer and use it in GitHub Desktop.
Forward Propagation
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
def linear_forward(z, w, b): | |
Z = z.dot(w) | |
Z = Z + b | |
stash = (z,w,b) | |
return Z,stash | |
def activation_function(activation, z): | |
if activation == "relu": | |
a = np.maximum(0,z) | |
stash = z | |
elif activation == "sigmoid": | |
a = 1/(1+np.exp(-1*z)) | |
stash = z | |
return a,stash | |
def forward_pass(X, params): | |
stashes = [] | |
A = X | |
L = len(params) // 2 | |
for l in range(1,L): | |
Z_prev = A | |
Z,linear_stash = linear_forward(Z_prev,params['W'+str(l)],params['b'+str(l)]) | |
A,activation_stash = activation_function("relu",Z) | |
stash = (linear_stash,activation_stash) | |
stashes.append(stash) | |
Z_,linear_stash = linear_forward(A,params['W'+str(L)],params['b'+str(L)]) | |
A_,activation_stash = activation_function("sigmoid",Z_) | |
stash = (linear_stash,activation_stash) | |
stashes.append(stash) | |
return A_,stashes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment