所谓的确定二值化,指使用一种固定的方式将实值转为二值(+1或-1),转换公式为:
xb=Sign(x)={+1 if x≥0−1 otherwise x^{b}=\operatorname{Sign}(x)= \begin{cases}+1 & \text { if } x \geq 0 \\ -1 & \text { otherwise }\end{cases} xb=Sign(x)={+1−1 if x≥0 otherwise
而所谓的随机二值化的转换公式为:
xb={+1 with probability p=σ(x)−1 with probability 1−p x^{b}= \begin{cases}+1 & \text { with probability } p=\sigma(x) \\ -1 & \text { with probability } 1-p\end{cases} xb={+1−1 with probability p=σ(x) with probability 1−p
其中的σ\sigmaσ指 “hard sigmoid” 函数,具体为:
σ(x)=clip(x+12,0,1)=max(0,min(1,x+12)) \sigma(x)=\operatorname{clip}\left(\frac{x+1}{2}, 0,1\right)=\max \left(0, \min \left(1, \frac{x+1}{2}\right)\right) σ(x)=clip(2x+1,0,1)=max(0,min(1,2x+1))
尽管随机二值化看起来更吸引人,但是在具体实现的时候需要硬件产生随机位,因此,除了某些特定的实验以外,文章主要采用确定二值化的方式。