Linearize a sign function

285 Views Asked by At

Let's say I have some matrix, $M$, of real numbers, and I apply the $\text{sign}$ function to it, such that $m_{i,j} > 0$ gets mapped to $+1$ and $m_{i,j} \le 0$ gets mapped to $-1$. Let's call this resulting matrix, $M_B$. I am binarizing $M$ so that I can implement the convolution operation with another binarized matrix, $K$, using simple XNOR logic:

$$R_B = \text{sign}(M) \circledast \text{sign}(K)$$

Let's say $M$ changes only slightly in the next time step. If $\Delta M$ is maintained in real numbers and $K$ is also in real numbers, then:

$$R = (M + \Delta M) \circledast K = M \circledast K + \Delta M \circledast K$$

What this means is that if I have the result from the previous time step ($M \circledast K$), all I need to do now is $\Delta M \circledast K$ and add the result from the previous time step. This results in massive saving in computation, particularly if $\Delta M$ is very sparse.

But now, since I am binarizing:

$$R_B = \text{sign}(M + \Delta M) \circledast \text{sign}(K) \neq \text{sign}(M) \circledast \text{sign}(K) + \text{sign}(\Delta M) \circledast \text{sign}(K)$$

As can be seen, because of the non-linearity of the $\text{sign}$ function, I can no longer just do $\text{sign}(\Delta M) \circledast \text{sign}(K)$ and add it to the result from the previous time step. What I can do at the moment is either:

  1. preform the full convolution $\text{sign}(M + \Delta M) \circledast \text{sign}(K)$ or
  2. do $\Delta = \text{sign}(M + \Delta M) - \text{sign}(M)$ and then $\Delta \circledast \text{sign}(K)$ and add this to the result from the previous time step.

For case 1, I am doing computations all over again without taking advantage of the fact that the matrix is not changing much.

For case 2, I need to store $M$ from the previous time step (in real numbers) instead of just the result of the convolution, which is a lot if I want to implement this in hardware.

My question is, what can I do to make:

$$\text{sign}(M + \Delta M) \circledast \text{sign}(K) \approx \text{sign}(M) \circledast \text{sign}(K) + \text{sign}(\Delta M) \circledast \text{sign}(K)$$