# A Contrastive Learning Method for the Visual Representation of 3D Point Clouds
## 2 Materials and Methods
### Self-Attention Point Cloud Capsule Network
#### 2.2.2 FM Routing Algorithm  
Taking the self-attention capsule layer \(u\) as the input of the FM routing layer, the FM routing algorithm does not need to iteratively calculate the parent capsule and its consistency with the prediction vector. Therefore, the FM routing algorithm is more efficient than the traditional dynamic routing and EM routing algorithms. Algorithm 2 provides the FM routing algorithm steps.  
Each capsule in the self-attention capsule layer is represented by \(u_{i}\), and the prediction vector \(u_{j\parallel i}\) of each capsule in the self-attention capsule layer is calculated. Assuming that the prediction vector set is \(\left[u_{j\parallel 0},u_{j\parallel 1}\ \ldots\ \ u_{j\parallel i}\right]\), the consistency between capsules is through  
Figure 3: Self-attention point cloud capsule network.  
the paired interaction between capsules in the same layer. The pairwise product expression is as shown in Formula (11):  
\[\widehat{p}_{j|i_{1}j_{2}}=\widehat{u}_{j|i_{1}}\odot\widehat{u}_{j|i_{2}} \tag{11}\]  
where the sum of each element of \(p_{j|i_{1},i_{2}}\) gives the size of the consistency and the direction and posture of the capsule \(p_{j}\). The pairwise interaction between all capsules in the self-attention capsule layer and the digital capsule \(p_{j}\) in the output layer can be expressed as:  
\[\begin{split}\widehat{H}_{j}&=\sum_{i_{1}=1}^{n} \sum_{i_{2}=i_{1}+1}^{n}\widehat{u}_{j|i_{1}}\odot\widehat{u}_{j|i_{2}}\\ &=\frac{1}{2}(\sum_{i=1}^{n}\widehat{u}_{j|i}\odot\sum_{i=1}^{n} \widehat{u}_{j|i}-\sum_{i=1}^{n}\widehat{u}_{j|i}\odot\widehat{u}_{j|i})\end{split} \tag{12}\]  
where \(n\) represents the total number of prediction vectors. Then, the capsule \(p_{j}\) is defined as:  
\[\widehat{p}_{j}=\text{softmax}(\sum_{f=1}^{K}\widehat{H}_{j,f}) \tag{13}\]  
The summation operation in Formula (12) may cause gradient explosion. Therefore, the prediction vector \(u_{j|i}\) is divided by \(\sqrt{n}\) for scaling to obtain Formula (14):  
\[\widehat{H}_{j}=\frac{1}{2n}(\sum_{i=1}^{n}\widehat{u}_{j|i}\odot\sum_{i=1}^{ n}\widehat{u}_{j|i}-\sum_{i=1}^{n}\widehat{u}_{j|i}\odot\widehat{u}_{j|i}) \tag{14}\]  
The orientation of the posture vector \(Q_{j}\) determines the entity's posture, direction, size, rotation, and other attributes. The posture vector \(Q_{j}\) is defined as:  
\[\widehat{Q}_{j}=\frac{\widehat{H}_{j}}{\left\|\widehat{H}_{j}\right\|} \tag{15}\]  
We use capsule \(p_{j}\) to determine which class is activated and by how much it has been activated. Combining all instances of \(p_{j}\) to get the digital capsule layer \(P\in\mathbb{R}^{64\times 64}\), the digital capsule layer is used as a feature to train the backbone network for contrastive loss.  
```
Input: Prediction vector \(u_{j|0},u_{j|1}\).... \(u_{j|i}\) Output:\(Q_{j}\), \(p_{j}\)
1:\(u_{j|i}\gets L2 Normalize\left(u_{j|i}\right)\)
2:\(H_{j}\leftarrow\frac{1}{2n}\left(\sum_{i=1}^{n}u_{j|i}\odot\sum_{i=1}^{n}u_{ j|i}-\sum_{i=1}^{n}u_{j|i}\odot u_{j|i}\right)\)
3:\(Q_{j}\leftarrow\frac{H_{j}}{\left\|\widehat{H}_{j}\right\|}\)
4:\(p_{j}\leftarrow\text{softmax}\left(\sum\limits_{f=1}^{K}H_{j,f}\right)\)
```  
**Algorithm 2** FM Routing Algorithm