I'm trying to make a custom regularizer in Keras and I need to be able to roll the coefficient array.
I know this may be impossible however any mechanism that can replicate this roll function would be extremely appreciated.
```
def __call__(self, x):
regularization = 0.
# Add components if they are given
if self.l1:
# \lambda ||x||
regularization += self.l1 * K.sum(K.abs(x))
if self.fuse:
# \lambda \sum{ |x - x_+1| }
regularization += self.fuse * K.sum(K.abs(x - np.roll(x, 1)))
if self.abs_fuse:
# \lambda \sum{ ||x| - |x_+1|| }
regularization += self.abs_fuse * K.sum(K.abs(K.abs(x) - K.abs(np.roll(x, 1))))
```
x? Ifxis a matrix then it's probably a bit weird. Callingnp.rollon a weight matrix will first flatten the matrix, shift the element linearly, and finally reshape it back to a matrix. Is this behavior exactly what you want, or is itnp.roll(x, 1, axis=1)?np.roll(x, 1, axis=1)gives the same result asnp.roll(x, 1)in this example butaxis=1is more explicit.