# Towards Feasible Capsule Network for Vision Tasks
## 3 Methods  
### Preliminaries  
**Capsule Network**: In the context of CapsNets, the fundamental idea is to introduce capsules that encapsulate pose information along with other instantiation parameters, such as color and texture, for different parts or fragments of an object. This structure is characterized by being deep in width rather than height, resembling a parse tree [13] where each active capsule selects a parent capsule in the next layer. The underlying principle is that as the viewpoint of an object changes, the corresponding pose matrices should be coordinated to maintain the voting agreement. A CapsNet typically consists of three key components: a stack of convolutional layers responsible for extracting features, a primary capsule layer that transforms these features into capsule representations, and a stack of capsule layers that incorporate the routing mechanism. In CapsNets, capsules in a lower layer \(L_{i}\) (children) are routed to capsules in a higher layer \(L_{j}\) (parents), creating a connection between the two layers. In every layer, there are multiple capsules, each characterized by an instantiation parameter pose vector \(S_{i}\in\mathbb{R}^{P}\)[14] or matrix \(S_{i}\in\mathbb{R}^{P\times P}\), and an activation probability \(a_{i}\)[28]. The pose in each capsule encodes the relationship of an entity to the viewer, while the activation probability represents its presence. Using its pose matrix, \(S_{i}\), each lower-level capsule contributes a vote to determine the pose of a higher-level capsule. This is achieved by multiplying the pose with a trainable viewpoint-invariant transformation weight matrix. \[V_{j|i}=S_{i}W_{ij} \tag{1}\]In essence, the trainable weights, \(W_{ij}\), enable the capsules to learn affine transformations, allowing them to capture and represent the part-whole relations within the data. **Routing Methods**: Routing-by-agreement is a dynamic information flow through the network by determining connections between successive layers of capsules at runtime. Unlike traditional neural networks, where cross-layer connections are determined solely by network parameters, routing enables the adjustment of magnitudes and relevance from lower capsules to higher capsules, ensuring the activation of relevant higher-level counterparts and effective transmission of pattern information. The concept of routing can be likened to clustering logic [28; 49] where higher-level parent capsules receive votes from multiple lower-level child capsules within their receptive fields. However, capsule routing differs from regular clustering as each cluster has its own learnable viewpoint-invariant transformation matrix, enabling a unique perspective on the data and facilitating faster convergence by breaking symmetry. Different approaches to routing have been explored in CapsNets [16; 21; 22; 32; 49; 50; 54]. The pre-activation of a capsule, \(j\), is computed as the sum of the association coefficients, \(c_{ij}\), multiplied by the predictions, \(V_{j|i}\), of the lower-level capsules \(i\). \[S_{j}=\sum_{i}c_{ij}V_{j|i} \tag{2}\]  
These association coefficients are determined through iterative routings, with examples outlined below. 1. Dynamic routing [14]: The agreement is measured by cosine similarity, and the coupling coefficients are updated as follows: \[ \begin{split} c_{ij}\leftarrow\frac{e^{y_{ij}}}{\sum_{j}e^{y_{ ij}}}\\ b_{ij}\gets b_{ij}+\left\langle S_{j},V_{j|i}\right\rangle \end{split} \] (3)
2. EM routing [28]: This refers to using an EM algorithm to determine the coupling as a mixture coefficient with cluster assumption that the votes are distributed around a parent capsule. \[ \begin{split} c_{ij}\leftarrow\frac{a_{i}p_{j}}{\sum_{j}a_{i}p_{ j}}\\ p_{j}\leftarrow\frac{1}{\sqrt{\prod_{h}2\pi\left(\sigma_{j}^{h} \right)^{2}}}\text{exp}\left(-\frac{\sum_{h}\left(\frac{\sigma_{j}^{h}-S_{j}^ {h}}{2}\right)^{2}}{2\left(\sigma_{j}^{h}\right)^{2}}\right)\end{split}