# Top Position Sensitive Ordinal Relation Preserving Bitwise Weight for Image Retrieval
## 2 Method
### Relaxation and Iterative Optimization  
In this section, we describe the process of learning hash and bitwise weight functions by minimizing loss function \(L(\cdot,\cdot)\). Different from the two-step mechanism, we design an iterative optimization mechanism that simultaneously learns parameters of hash and bitwise weight functions [9; 10]. As binary codes and indicator functions are discrete integer values, directly optimizing loss function \(L(\cdot,\cdot)\) becomes difficult. To fix this problem, we adopt a relaxation mechanism. First, we utilize _tanh_(\(\cdot\)) instead of the encoding function as shown in Equation (8), and the weighted Hamming distance is rewritten as in Equation (9):  
\[h_{c}(x)=\mathrm{sgn}({u_{c}}^{T}x)\approx\tanh({u_{c}}^{T}x), \tag{8}\]  
\[d_{wh}(x_{i},x_{j})=\frac{1}{2}(\sum_{c=1}^{r}w_{c}(x_{j})-\sum_{c=1}^{r}w_{c}( x_{j})\cdot h_{c}(x_{i})\cdot h_{c}(x_{j})). \tag{9}\]  
Secondly, we employ the sigmoid function to approximate the indicator function as in shown in Equation (10):  
\[I(d_{wh}(x_{i},x_{k})\leq d_{wh}(x_{i},x_{j}))\approx G(z)=\frac{1}{1+\exp(-z)}. \tag{10}\]  
The definition of z is shown in Equation (11):  
\[z=d_{wh}(x_{i},x_{k})-d_{wh}(x_{i},x_{j}). \tag{11}\]  
After the above relaxation procedure, we utilize a stochastic gradient descent algorithm to optimize the objective function in Equation (12):  
\[O=\sum_{i,j}L(x_{i},x_{j})=\sum_{i,j}\log(1+R_{E}(x_{i},x_{j})+R_{H}(x_{i},x_{ j})). \tag{12}\]  
For the parameter of the \(c\)-th hash function \(u_{c}\), the partial derivation of the objective function \(O\) is shown in Equation (13):  
\[ \begin{array}{rcl}\frac{\partial O}{\partial u_{c}}&=&\frac{R_{H}(x_{i},x_{ j})}{1+R_{E}(x_{i},x_{j})+R_{H}(x_{i},x_{j})}\cdot\frac{\partial R_{H}(x_{i},x_{ j})}{\partial u_{c}}\\ &=&\frac{R_{H}(x_{i},x_{j})}{1+R_{E}(x_{i},x_{j})+R_{H}(x_{i},x_{j})}\cdot\frac {\partial\sum_{k}G(d_{wh}(x_{i},x_{k})-d_{wh}(x_{i},x_{j}))}{\partial u_{c}}\\ &=&\frac{R_{H}(x_{i},x_{j})}{1+R_{E}(x_{i},x_{j})+R_{H}(x_{i},x_{j})}\cdot\sum _{k}\left(G(z)(1-G(z))\right)\cdot\big{[}\frac{\partial d_{wh}(x_{i},x_{k})}{ \partial u_{c}}-\frac{\partial d_{wh}(x_{i},x_{j})}{\partial u_{c}}\big{]} \end{array}  \tag{13}\]  
The partial derivation of the weighted Hamming distance is shown in Equation (14):  
\[\frac{\partial d_{wh}(x_{i},x_{k})}{\partial u_{c}}=\frac{w_{c}(x_{k})}{2} \cdot\big{[}(1-h_{c}^{2}(x_{i}))\circ h_{c}(x_{k})+(1-h_{c}^{2}(x_{k}))\circ h_ {c}(x_{i})\big{]}, \tag{14}\]  
where \(\circ\) represents the element-wise product. As a result, we can update the value of the parameter \(u_{c}\) shown in Equation (15):  
\[u_{c}=u_{c}-\lambda_{1}\frac{\partial O}{\partial u_{c}}. \tag{15}\]  
For \(v_{c}\) of the \(c\)-th bitwise weight function, the partial derivation of the objective function is shown in Equation (16):\[ \begin{array}{rcl}\frac{\partial Q}{\partial v_{c}}&=&\frac{R_{H}(x_{i}x_{j})}{1+R_ {c}(x_{i},x_{j})+R_{H}(x_{i},x_{j})}\cdot\frac{\partial R_{H}(x_{i}x_{j})}{ \partial v_{c}}\\ &=&\frac{R_{H}(x_{i}x_{j})}{1+R_{c}(x_{i},x_{j})+R_{H}(x_{i},x_{j})}\cdot\frac{ \frac{\partial T}{\kappa}(d_{\text{abs}}(x_{i}x_{k})-d_{\text{abs}}(x_{i}x_{j} ))}{\partial v_{c}}\\ &=&\frac{R_{H}(x_{i}x_{j})}{1+R_{c}(x_{i},x_{j})+R_{H}(x_{i},x_{j})}\cdot\frac {\sum_{k}\left(G(z)(1-G(z))\right)\cdot\left[\frac{\partial d_{\text{abs}}(x_{i }x_{k})}{\partial v_{c}}-\frac{\partial d_{\text{abs}}(x_{i}x_{j})}{\partial v _{c}}\right]}\\ &=&\frac{R_{H}(x_{i}x_{j})}{1+R_{c}(x_{i},x_{j})+R_{H}(x_{i},x_{j})}\cdot\frac {\sum_{k}\left(G(z)(1-G(z))\right)\cdot\left[\frac{\partial x_{k}}{2}(1-h_{c}( x_{i})h_{c}(x_{k}))-\frac{x_{j}}{2}(1-h_{c}(x_{i})h_{c}(x_{j}))\right]}\end{array}  \tag{16}\]  
As a result, we can update the parameter \(v_{c}\) shown in Equation (17):  
\[v_{c}=v_{c}-\lambda_{2}\frac{\partial O}{\partial v_{c}}. \tag{17}\]  
The details of the proposed TORBW method are shown in Algorithm 1. ```
0: Data set \(X\)=\(\{x_{1},\cdots,x_{n}\}\), the number of binary bits \(r\), and parameters \(\lambda_{1}\) and \(\lambda_{2}\).