哈希函数的学习算法整理

前言

如果你对这篇文章感兴趣,可以点击「【访客必读 - 指引页】一文囊括主页内所有高质量博客」,查看完整博客分类与对应链接。


概述

哈希函数学习的两个步骤:

  • 转为二进制编码:可以先降维成实数,再转为二进制,也可以直接学习一个二进制编码;
  • 学习哈希映射函数:基于二进制编码设计或学习哈希方式,使得相似元素靠近,不相似元素远离。

根据哈希函数性质,可做如下分类:

  • 数据无关的方法 (Data-Independent Methods)
    • 特点:哈希函数与训练集无关,通常为随机投影或手动构造
    • 举例:Locality-sensitive hashing (LSH), Shift invariant kernel hashing (SIKH), MinHash;
  • 数据相关的方法 (Data-Dependent Methods)
    • 特点:哈希函数通过训练集学习得到
    • 分类:单模态哈希(无监督 / 有监督)、基于排序的方法(监督信息为排序序列)、多模态哈希、深度哈希

无监督哈希 (Unsupervised Hashing)

问题定义:

  • 输入:特征向量 { x i } \{\mathbf{x}_i\} { xi},对应矩阵 X \mathbf{X} X
  • 输出:二进制编码 { b i } \{\mathbf{b}_i\} { bi},对应矩阵 B \mathbf{B} B,相似的特征对应相似的编码

PCA Hashing (PCAH)

选取矩阵 X X ⊤ \mathbf{X X}^\top XX 最大的 m m m 个特征向量,组成投影矩阵 W ∈ R d × m \mathbf{W}\in \mathbb{R}^{d\times m} WRd×m,并定义哈希函数为:
h ( x ) = sgn ⁡ ( W ⊤ x ) . h(\mathbf{x})=\operatorname{sgn}\left(\mathbf{W}^\top \mathbf{x}\right). h(x)=sgn(Wx).

Spectral Hashing (SH)

min ⁡ { y i }     ∑ i j W i j ∥ y i − y j ∥ 2  s.t.    y i ∈ { − 1 , 1 } k ∑ i y i = 0 1 n ∑ i y i y i ⊤ = I \begin{aligned} \mathop{\min}\limits_{\left\{\mathbf{y}_i\right\}} \ \ \ & \sum_{i j} W_{i j}\left\|\mathbf{y}_i-\mathbf{y}_j\right\|^2 \\ \text { s.t.} \ \ \ & \mathbf{y}_i \in\{-1,1\}^k \\ &\sum_i \mathbf{y}_i=0 \\ &\frac{1}{n} \sum_i \mathbf{y}_i \mathbf{y}_i^\top=\mathbf{I} \end{aligned} { yi}min    s.t.   ijWijyiyj2yi{ 1,1}kiyi=0n1iyiyi=I

其中 W i j W_{ij} Wij x i \mathbf{x}_i xi x j \mathbf{x}_j xj 的相似度,第二个约束意味着所有数据映射后,每一位上 1 1 1 − 1 -1 1 的数量相同,第三个约束意味着不同位之间没有关联。上述优化问题为整数规划,难以求解,可将 y i ∈ { − 1 , 1 } k \mathbf{y}_i \in\{-1,1\}^k yi{ 1,1}k 约束取消,对问题进行放松,并将求得的 { y i } \{\mathbf{y}_i\} { yi} 每一位通过 sgn ⁡ \operatorname{sgn} sgn 函数映射,得到最终的二进制编码。

Anchor Graph Hashing (AGH)

X \mathbf{X} X 使用 k-means 聚类,得到 { u j ∈ R d } j = 1 m \{\mathbf{u}_j\in \mathbb{R}^d\}_{j=1}^m { ujRd}j=1m,重新定义矩阵 Z ∈ R n × m \mathbf{Z}\in \mathbb{R}^{n\times m} ZRn×m
Z i j = { exp ⁡ ( − D 2 ( x i , u j ) / t ) ∑ j ′ ∈ J i exp ⁡ ( − D 2 ( x i , u j ′ ) / t ) , ∀ j ∈ J i 0 ,  otherwise  Z_{i j}=\left\{\begin{array}{l} \frac{\exp \left(-\mathcal{D}^2\left(\mathbf{x}_i, \mathbf{u}_j\right) / t\right)}{\sum_{j^{\prime} \in\mathcal{J}_i } \exp \left(-\mathcal{D}^2\left(\mathbf{x}_i, \mathbf{u}_{j^{\prime}}\right) / t\right)}, \forall j \in \mathcal{J}_i \\ 0, \text { otherwise } \end{array}\right. Zij= jJiexp(D2(xi,uj)/t)exp(D2(xi,uj)/t),jJi0, otherwise 

其中 J i \mathcal{J}_i Ji 为一个下标集合,对应 { u j ∈ R d } j = 1 m \{\mathbf{u}_j\in \mathbb{R}^d\}_{j=1}^m { ujRd}j=1m s s s 个离 x i \mathbf{x}_i xi 最近的点的下标。定义哈希函数为:
h ( x ) = sign ⁡ ( W ⊤ z ( x ) ) , h(\mathbf{x})=\operatorname{sign}\left(W^\top z(\mathbf{x})\right), h(x)=sign(Wz(x)),

其中 W = n Λ − 1 / 2 V Σ − 1 / 2 W=\sqrt{n} \Lambda^{-1 / 2} V \Sigma^{-1 / 2} W=n Λ1/2VΣ1/2 Λ = diag ⁡ ( Z ⊤ 1 ) \Lambda=\operatorname{diag}\left(Z^\top\mathbf{1}\right) Λ=diag(Z1) V V V Σ \Sigma Σ 由矩阵 Λ − 1 / 2 Z ⊤ Λ − 1 / 2 \Lambda^{-1 / 2} Z^\top \Lambda^{-1 / 2} Λ1/2ZΛ1/2 的特征向量和特征值组成。该方法整体目标与 Spectral Hashing 一致,但通过引入 Anchor,使问题求解得到了加速,时间复杂度从 O ( n 3 ) O(n^3) O(n3) 降至为 O ( n m 2 ) O(nm^2) O(nm2)。具体细节可参照原论文


有监督哈希 (Supervised Hashing)

问题定义:

  • 输入:特征向量 { x i } \{\mathbf{x}_i\} { xi},对应矩阵 X \mathbf{X} X,类别向量 { y i } \{\mathbf{y}_i\} { yi},对应矩阵 Y \mathbf{Y} Y
  • 输出:二进制编码 { b i } \{\mathbf{b}_i\} { bi},对应矩阵 B \mathbf{B} B,相同类别对应相似编码

常见算法如下所示,具体信息见参考资料,此处不再展开。

在这里插入图片描述


基于排序的方法 (Ranking-based Methods)

该部分属于有监督哈希一类,不过监督信息从标记变为了排序信息,例如三元组 ( x , x + , x − ) \left(x, x^{+}, x^{-}\right) (x,x+,x)。该部分涉及的常见算法如下:

在这里插入图片描述


参考资料

猜你喜欢

转载自blog.csdn.net/qq_41552508/article/details/129187566