Add squashing as a pooling option
Issue Description
The vector-squashing operation as an element of capsule layer post-processing may already be added as a special case in GlobalPoolingLayer.java and PoolingType.java, to be eventually used for capsule networks.
Contributing
Currently I am trying to code it myself, but still being unfamiliar with the framework can't promise to implement it any time soon.
What exactly do you mean with vector-squashing? Can you add a link to a paper that you are trying to implement?
Vector squashing is a transition
v -> (||v||^2 / 1 + ||v||^2) * v / ||v||
Basically it is a substitution of pooling. You still split the output vector into regions (capsule results) but instead of drawing a single number you renormalize it.
The reference is this paper of Hilton et al. There were at least two half-hearted requests of implementing capsule layers on gitter.
From a brief look at the paper, I don't really think having it as a pooling option is the right thing. Usually pooling reduces multiple vectors to a single one. To be honest, it looks more like an activation function to me.
Well, basically, you are right, but then it's an nd4j issue, similar to ActivationSoftmax.
It shouldn't be too hard to add that as another activation function.
You might want to take a look at https://github.com/deeplearning4j/nd4j/pull/1372 where I've added the cube activation function. There where quite some changes since then, but it should give you an idea on what you'd need to do to add it.
So basically it is about making a class like Squash.java that implements BaseTransformOp. But then, looking at all the classes including Cube, I am curious where is the activation of the values are calculated. I mean, I went through most of the tree down to Op and DifferentialFunction but I don't fully understand where does the calculation of the activation happen.
UPD: it sure has to do with f() function, but I'm still not sure what exactly.
Yeah, based on the math posted above that looks like (a) an activation function, and/or (b) equivalently a general NDArray transform op (yes, like softmax). It probably makes sense to do both - with the IActivation using the transform op.
@KolyaIvankov as for where the actual math is calculated - it's all C++ (for performance reasons, and for CUDA support) https://github.com/deeplearning4j/libnd4j
@AlexDBlack @treo Seems to me it is both. IIUC, it is (a) an activation function, with x * x / (1 + x* x) as predecessor, but (b) like softmax is is not pointwise, but also (c) like pooling, it is not global, but rather splits the output vector in chunks and the transforms each chunk individually.
Iе is (c) that made me think of pooling, but since I am still not very much into nd4j, perhaps I misunderstand the problem.
Also, downloaded libnd4j, getting into. Thanks!
@KolyaIvankov take a look here please: https://github.com/deeplearning4j/libnd4j/blob/master/AddingNewOps.md