add DenseUnbiased layer
This commit is contained in:
parent
5cd4e8d1c1
commit
b6fe7f711e
1 changed files with 27 additions and 0 deletions
|
@ -62,6 +62,33 @@ class Dense(Layer):
|
||||||
return dY @ self.coeffs.f.T
|
return dY @ self.coeffs.f.T
|
||||||
|
|
||||||
|
|
||||||
|
class DenseUnbiased(Layer):
|
||||||
|
serialized = {
|
||||||
|
'W': 'coeffs',
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, dim, init=init_he_uniform, reg_w=None):
|
||||||
|
super().__init__()
|
||||||
|
self.dim = int(dim)
|
||||||
|
self.output_shape = (dim,)
|
||||||
|
self.coeffs = self._new_weights('coeffs', init=init,
|
||||||
|
regularizer=reg_w)
|
||||||
|
|
||||||
|
def make_shape(self, parent):
|
||||||
|
shape = parent.output_shape
|
||||||
|
self.input_shape = shape
|
||||||
|
assert len(shape) == 1, shape
|
||||||
|
self.coeffs.shape = (shape[0], self.dim)
|
||||||
|
|
||||||
|
def forward(self, X):
|
||||||
|
self.X = X
|
||||||
|
return X @ self.coeffs.f
|
||||||
|
|
||||||
|
def backward(self, dY):
|
||||||
|
self.coeffs.g += self.X.T @ dY
|
||||||
|
return dY @ self.coeffs.f.T
|
||||||
|
|
||||||
|
|
||||||
# more
|
# more
|
||||||
|
|
||||||
class Conv1Dper(Layer):
|
class Conv1Dper(Layer):
|
||||||
|
|
Loading…
Add table
Reference in a new issue