Skip to content

Instantly share code, notes, and snippets.

@angadsinghsandhu
Created December 1, 2020 05:17
Show Gist options
  • Save angadsinghsandhu/c5a4f505ad03f1f43382f20574d2c1c9 to your computer and use it in GitHub Desktop.
Save angadsinghsandhu/c5a4f505ad03f1f43382f20574d2c1c9 to your computer and use it in GitHub Desktop.
Forward Propagation
# Forward Propagation Logic
def forwardprop(self):
# dynamically calculating first layer
exec("self.z1 = np.dot( self.w1, self.z0 ) + self.b1")
# dynamically calculating the "a" of layer
exec("self.a1 = self.sigmoid(self.z1)")
# dynamically calculating all other layers
for i in range(2, self.num_layers + 1):
# dynamically calculating "z"
cmd1 = "self.z{} = np.dot( self.w{}, self.a{} ) + self.b{}".format(
i, i, i-1, i)
# dynamically calculating the "a" of layers
cmd2 = "self.a{} = self.sigmoid(self.z{})".format(i, i)
# executing code
exec(cmd1)
exec(cmd2)
# returning output
temp = []
exec("temp.append(self.a{}[0][0])".format(self.num_layers))
return temp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment