This commit is contained in:
Connor Olding 2017-02-16 19:21:24 -08:00
parent 4ac04baa1f
commit 81f6e72da0
2 changed files with 22 additions and 22 deletions

View file

@ -1,11 +1,11 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# BIG TODO: ensure numpy isn't upcasting to float64 *anywhere*.
# this is gonna take some work.
# external packages required for full functionality: # external packages required for full functionality:
# numpy scipy h5py sklearn dotmap # numpy scipy h5py sklearn dotmap
# BIG TODO: ensure numpy isn't upcasting to float64 *anywhere*.
# this is gonna take some work.
from optim_nn_core import * from optim_nn_core import *
from optim_nn_core import _check, _f from optim_nn_core import _check, _f
@ -48,6 +48,25 @@ class SomethingElse(ResidualLoss):
# Parametric Layers {{{1 # Parametric Layers {{{1
class DenseOneLess(Dense):
def init(self, W, dW):
super().init(W, dW)
ins, outs = self.input_shape[0], self.output_shape[0]
assert ins == outs, (ins, outs)
def F(self, X):
np.fill_diagonal(self.coeffs, 0)
self.X = X
Y = X.dot(self.coeffs) + self.biases
return Y
def dF(self, dY):
dX = dY.dot(self.coeffs.T)
self.dcoeffs[:] = self.X.T.dot(dY)
self.dbiases[:] = dY.sum(0, keepdims=True)
np.fill_diagonal(self.dcoeffs, 0)
return dX
class LayerNorm(Layer): class LayerNorm(Layer):
# paper: https://arxiv.org/abs/1607.06450 # paper: https://arxiv.org/abs/1607.06450
# my implementation may be incorrect. # my implementation may be incorrect.

View file

@ -455,25 +455,6 @@ class Dense(Layer):
self.dbiases[:] = dY.sum(0, keepdims=True) self.dbiases[:] = dY.sum(0, keepdims=True)
return dX return dX
class DenseOneLess(Dense):
def init(self, W, dW):
super().init(W, dW)
ins, outs = self.input_shape[0], self.output_shape[0]
assert ins == outs, (ins, outs)
def F(self, X):
np.fill_diagonal(self.coeffs, 0)
self.X = X
Y = X.dot(self.coeffs) + self.biases
return Y
def dF(self, dY):
dX = dY.dot(self.coeffs.T)
self.dcoeffs[:] = self.X.T.dot(dY)
self.dbiases[:] = dY.sum(0, keepdims=True)
np.fill_diagonal(self.dcoeffs, 0)
return dX
# Models {{{1 # Models {{{1
class Model: class Model: