diff --git a/onn/layer.py b/onn/layer.py index ce91094..f8987f0 100644 --- a/onn/layer.py +++ b/onn/layer.py @@ -1,7 +1,6 @@ from .layer_base import * from .initialization import * from .float import * -from .regularizer import Regularizer # Nonparametric Layers {{{1 @@ -77,21 +76,6 @@ class Sum(Layer): return edges[0] # TODO: does this always work? -class ActivityRegularizer(Layer): - def __init__(self, reg): - super().__init__() - assert isinstance(reg, Regularizer), reg - self.reg = reg - - def forward(self, X): - self.X = X - self.loss = np.sum(self.reg.forward(X)) - return X - - def backward(self, dY): - return dY + self.reg.backward(self.X) - - class Dropout(Layer): def __init__(self, dropout=0.0): super().__init__() diff --git a/onn/regularizer.py b/onn/regularizer.py index 37887c3..eec9888 100644 --- a/onn/regularizer.py +++ b/onn/regularizer.py @@ -1,5 +1,6 @@ import numpy as np +from .layer import Layer from .float import * @@ -7,6 +8,21 @@ class Regularizer: pass +class ActivityRegularizer(Layer): + def __init__(self, reg): + super().__init__() + assert isinstance(reg, Regularizer), reg + self.reg = reg + + def forward(self, X): + self.X = X + self.loss = np.sum(self.reg.forward(X)) + return X + + def backward(self, dY): + return dY + self.reg.backward(self.X) + + class L1L2(Regularizer): def __init__(self, l1=0.0, l2=0.0): self.l1 = _f(l1)