From 81f6e72da02239f1f9ead5b67433bfc18ad3d367 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Thu, 16 Feb 2017 19:21:24 -0800 Subject: [PATCH] . --- optim_nn.py | 25 ++++++++++++++++++++++--- optim_nn_core.py | 19 ------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/optim_nn.py b/optim_nn.py index 3a4d330..b445227 100644 --- a/optim_nn.py +++ b/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. diff --git a/optim_nn_core.py b/optim_nn_core.py index 3beacc6..3a42042 100644 --- a/optim_nn_core.py +++ b/optim_nn_core.py @@ -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: