chaos-moon / paper_daily

One paper a day, keep laziness away.
MIT License
6 stars 3 forks source link

[explore] Hyper-Dimensional Computing 系列 #16

Open yaoyz96 opened 1 year ago

yaoyz96 commented 1 year ago

Hyper-Dimensional Computing

Hyper-Dimensional Computing (HDC) 属于一种新的 Brain-inspired computing paradigm。

HDC 特点:

HDC 技术难点:

HDC 通用做法:

VoiceHD

VoiceHD: Hyperdimensional Computing for Efficient Speech Recognition, ICRC 2017. [paper]

Contribution

VoiceHD 模型包含两部分:

  1. Encoder:将 frequency domain 的 voice signal 映射到 $D$ 维 binary hypervector。
  2. Memory:存储 learned pattern(i.e. class prototype)

Encoder

frequency domain 的 voice signal 包含 $n$ 个 input frequency bins,每个 bin 的信号振幅(signal amplitude)为 $\{ -1,1 \}$。为了实现高维映射,Encoder 需要考虑每个 frequency bin 及其信号振幅。

Encoder 对原始 voice signal 的映射过程为:

signal 中每个 frequency bin 的 channel ID hypervector 与其对应的 level hypervector 进行 element-wise 相乘。其中 level hypervector 根据 frequency bin 的振幅从 $M$ 个 level 中选择。

Encoder 对 signal 中所有 frequency bin 执行这样的映射,最后使用 bundling operation 将所有 frequency bin hypervector 共同输出一个 voice hypervector:

$$ S_1^i=[L_m ID_1+...+L_m ID_N], m \in [1,M] $$

其中 $S_1^i$ 表示第 $i$ 个类别中的一个 signal hypervector。

具体地,bundling operation 为 component-wise majority function $[hypervector]$,其计数 hypervector 中每个维度上 1 的个数,若超过半数的 elemets 都为 1,则该维度输出 1,反之为 0。

最后生成 class prototype:

将所有属于同一个 class 的 voice hypervector 进行 bundling,假设同属一个 class 有 $K$ 个 voice hypervector,则 class prototype 为(注意这里 $[]$ 仍为 bundling operation):

$$ C_i = [S_1^i + S_2^i + ... + S_K^i] $$

raw voice information 需要经过预处理变换到 frequency domain,预处理技术比如 Mel-frequency cepstral coefficients (MFCCs)

continuous item memory 原论文: Hyperdimensional biosignal processing: A case study for emg-based hand gesture recognition, ICRC 2016. Hyperdimensional computing for noninvasive brain–computer interfaces: Blind and one-shot classification of eeg error-related potentials, BICT 2017. P.S. continuous item memory 在连续标量范围已知的情况下效率较高。

Memory:

所有 class prototype 写入辅助 memory 中,作为 learned patterns。用于之后对 unseen voice signal 的分类。

Pipeline:

2023-05-08_111147

思考:

  1. voice signal 需要 $N$ 个 channel ID($N$ 个 frequency bins),是否所有 signal 都公用一套 channel ID?对于图像来说,frequency channel 是否可以拓展到 feautre map channel?
  2. level hypervector 考虑了 voice channel 的振幅,那么图像还用不用考虑 level?

ReHD

Locality-Based Encoder and Model Quantization for Efficient Hyper-Dimensional Computing, 2022. [paper]

在图像分类任务上提出 ReHD,重构 HDC 中的 encoding、training、inference 阶段,提升运算效率的同时,保持较高精度。

Contribution

ReHD 模型包含三个部分:

  1. encoding:encoding module 将数据映射到 binary high-dimensional space
  2. training:
  3. inference:使用 cosine similarity 对新样本进行分类

高维映射过程:

原始 $n$ 维 feature vector $\mathbf{F} = \{ f_1, f_2, ..., f_n \}$,经过 encoding module 映射到 $d$ 维的 hypervector $\mathbf{H} = \{ h_1, h_2, ..., h_d \}$(d>>n)。映射过程分为三步:

  1. 为每个 feature position 分配一个 unique channel ID,每个 channel ID 都是一个 hypervector,通过随机生成得到。这里 feautre position 表示 $f_i$,随机生成 channel ID 时,通过保证任意两个 ID 之间的相似度满足: $\delta(ID_i, ID_j)<5000, for D=10000, i \neq j$,保证它们之间两两正交
  2. 根据 feature value,生成 level hypervectors。通过计算所有 feature point 的最大值 $v{max}$ 和最小值 $v{min}$,将值区间分为 $M$ 个 level,每个 level 对应一个 hypervector $L$,因此所有 level hypervector 表示为 $L=\{ L_1,...,L_M \}$
  3. 编码 feature vector:将 feature vector 的 channel ID 与对应的 level hypervector 进行 element-wise 相乘。一个 $n$ 维度的 feature vector 要映射为 $d$ 维度的 hypervector 可以表示为:

$$ \mathbf{H} = [L_m ID_1 + L_m ID_2 + ... + L_m * ID_n], m \in [1,M] $$

和 VoiceHD 的做法一样,需要 channel ID hypervector 和 level hypervector,只不过 VoicdeHD 的 channel 是 frequency bin,level 为信号振幅的分级;ReHD 的 channel 为 feature channel,level 为 feature value 的范围。

对于 projection,作者分析了三种方式:

2023-05-08_190251

(1)Random Projection

原始 $n$ 维 feature vector $\mathbf{F} = \{ f_1, f_2, ..., f_n \}$,为了将其映射到 $d$ 维的 hypervector $\mathbf{H} = \{ h_1, h_2, ..., h_d \}$(d>>n),需要通过映射矩阵(Projection Matrix)进行映射。

Random Projection Matrix 每行是一个 $n$ 维的 bipolar vectors $\mathbf{P}_i$: $\{ -1,1 \}^n$,共 $d$ 行。映射矩阵可以表示为 $\{ \mathbf{P}_1, \mathbf{P}_2, ..., \mathbf{P}_d \}, \mathbf{P}_i \in \{-1,1 \}^n$。

通过 feautre vector $\mathbf{F} = \{ f_1, f_2, ..., f_n \}$ 与映射矩阵 $\{ \mathbf{P}_1, \mathbf{P}_2, ..., \mathbf{P}_d \}$ 相乘,可以得到 $d$ 维的 hypervector。其中,hypervector 第 $i$ 个数据点的值为: $h_i = sign(\mathbf{P}_i \cdot \mathbf{F})$,sign 为符号函数,将值映射到 +1 或 -1。

假设,feautre vector 维度 $n = 500$,要将其编码到高维 $d = 4000$,则 projection matrix 维度为 $d \times n$,执行 projection matrix 和 feature vector 的矩阵相乘,需要运算 $d \times n$ 次。计算复杂度为 $O(nd)$。

(2)Sparse Random Projection

上面的 random projection 可以通过稀疏化 projection matrix 来提升计算效率。

sparse projection matrix 的每一行仅随机生成 s% 不为 0 的数,其余所有置 0。比如若 s=5%,那么相比 dense 方案,每行仅有 $0.05 \times n$ 个不为 0 的元素。

这样的矩阵计算复杂度为 $O(snd)$,但仍然需要随机访问这些不为 0 的数据。

(3)Locality-Based Sparse Random Projection

为了去除随机访问,作者提出基于局部的稀疏映射方案。

具体做法:为映射矩阵每一行选择 $s \times n$ 个不为 0 的值,其中, $\mathbf{P}_1$ 不为 0 的值下标为 $[1...s \times n]$, $\mathbf{P}_2$ 对应 $[2...s \times n + 1]$,以此类推,直到 $\mathbf{P}_d$ 对应最后 $s \times n$ 个数(类似于滑动窗口)。

此方案将 projection matrix 简化为了一个 $d$ 维的 dense random projection vector。这样就能够以可预测的方式访问 projection matrix。

具体计算过程:

将 feature vector $\mathbf{F} = \{ f_1, f_2, ..., f_n \}$ 复制 $x$ 次,使其维度等于目标维度 $d$。比如 feautre vector 维度 $n = 500$,要将其编码到高维 $d = 4000$,则需要复制 8次。

随机生成一个 $d$ 维的 projection vector $\mathbf{P}$,通过一个大小为 $N$ 的窗口在两个 vector 上进行滑动,计算 $\mathbf{H}$ 中的每个元素:

$$ h_1 = sign(f_1 p_1 + f2 p_2 + f_N * p_N) $$

滑动窗口每次滑动一个位置,依次生成 $h_i$:

$$ h_i = sign(f_i pi + f{i+1} p{i+1} + f{i+N} * p_{i+N}) $$