Created
May 18, 2017 17:06
-
-
Save bartvm/b5ee493a0bcd62764d6f524b66531c94 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Linear: | |
def __init__(self, in_dim, out_dim): | |
self.params = { | |
'W': np.random.rand(in_dim, out_dim) | |
'b': np.random.rand(out_dim) | |
} | |
def run(self, x): | |
return sigmoid(self.params['W'] @ x + self.params['b']) | |
def forward(layer, x): | |
y = layer.run(x) | |
layer = Linear(20, 10) | |
grad(forward, wrt=layer.params['W'])(layer, np.random.rand(20)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment