Skip to content

Instantly share code, notes, and snippets.

@vamc-stash
Last active May 19, 2020 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vamc-stash/3e25838f9d7cc496e23260e5fee2ab17 to your computer and use it in GitHub Desktop.
Save vamc-stash/3e25838f9d7cc496e23260e5fee2ab17 to your computer and use it in GitHub Desktop.
Forward Propagation
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