From 4ee218169152489075f123fc67c48000d81e5ebb Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Wed, 2 Aug 2017 11:28:41 +0000 Subject: [PATCH] add standalone Bias layer --- onn_core.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/onn_core.py b/onn_core.py index f1781d4..15a6f0a 100644 --- a/onn_core.py +++ b/onn_core.py @@ -825,6 +825,30 @@ class Cos(Layer): # Parametric Layers {{{1 +class Bias(Layer): + # TODO: support axes other than -1 and shapes other than 1D. + + serialized = { + 'b': 'biases', + } + + def __init__(self, init=init_zeros, reg_b=None): + super().__init__() + self.biases = self._new_weights('biases', init=init, regularizer=reg_b) + + def make_shape(self, parent): + shape = parent.output_shape + self.input_shape = shape + self.output_shape = shape + self.biases.shape = (self.dim,) + + def forward(self, X): + return X + self.biases.f + + def backward(self, dY): + self.biases.g += dY.sum(0) + return dY + class Dense(Layer): serialized = { 'W': 'coeffs',