.
This commit is contained in:
parent
4ac04baa1f
commit
81f6e72da0
2 changed files with 22 additions and 22 deletions
25
optim_nn.py
25
optim_nn.py
|
@ -1,11 +1,11 @@
|
|||
#!/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:
|
||||
# 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 _check, _f
|
||||
|
||||
|
@ -48,6 +48,25 @@ class SomethingElse(ResidualLoss):
|
|||
|
||||
# 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):
|
||||
# paper: https://arxiv.org/abs/1607.06450
|
||||
# my implementation may be incorrect.
|
||||
|
|
|
@ -455,25 +455,6 @@ class Dense(Layer):
|
|||
self.dbiases[:] = dY.sum(0, keepdims=True)
|
||||
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
|
||||
|
||||
class Model:
|
||||
|
|
Loading…
Reference in a new issue