Inward & Outward Facing Fast Random Projections.

Fast Random Projections Using the Walsh–Hadamard Transform and Sign-Flips

Good afternoon everyone. Today, I want to walk you through a fast and elegant way to construct random projections, using the Walsh–Hadamard transform combined with simple sign-flip operations.

 Background – Why Random Projections?

Random projections are a powerful tool in machine learning and signal processing. They help reduce dimensionality, spread information evenly, and preserve distances in high-dimensional space — all while avoiding the cost of storing large dense random matrices.

Traditionally, a random projection is implemented as:

y=Rx

where RR is a dense random matrix. The drawback? Computing RxRx is O(n2)O(n^2) in time and storage.

We can do better.

The HD Construction

Here’s the idea:
Let HH be the Walsh–Hadamard matrix, and DD be a diagonal matrix whose entries are random ±1\pm 1. Then:

y=HDxy = H D x

This is a fast random projection because:


  • It is a random change of basis transform rather that the structured change of basis of the Walsh-Hadamard matrix alone.

  • Applying DD is just a pattern of sign flips — O(n)O(n) time.

  • Applying HH can be done in O(nlogn)O(n \log n) time via the Fast Walsh–Hadamard Transform (FWHT).

  • No multiplications are needed; only additions, subtractions, and sign changes.


Orthogonality and Inverse

An important property: each row of HDH D is still orthogonal. And both HH and DD are self-inverse:

H1=H,D1=DH^{-1} = H, \quad D^{-1} = D

So the inverse of y=HDx is:

x=DHy

Here’s the derivation:

y=HDxx=DH(HDx)=D(I)Dx=DDx=Ix=xy = H D x \quad \Rightarrow \quad x = D H (H D x) = D (I) D x = D D x = I x = x

Inward vs Outward Facing Projections

Interestingly, HDxH D x and DHxD H x behave differently:

  • Inward-facing projection: HDxH D x spreads out the data evenly — a change in one cordinate in x is spread to all coordinates in HDx.

  • Outward-facing projection: DHxD H x first applies HH which can concentrate energy into fewer coordinates, then just flips signs.


Why Outward Facing is Useful for Backpropagation

Suppose you apply y=DHxy = D H x as the final step in a neural network’s forward pass.
During backpropagation, the error vector must be multiplied by the inverse:

(DH)1=HD

So the error signal is automatically redistributed using an inward-facing projection — ensuring the gradient flows back in a randomized but well-spread manner. This can improve robustness and reduce overfitting tendencies.


Multiple-Stage Projections for Sparse Data

For dense data, a single HDH D works well.
But for sparse data, one stage might not sufficiently mix the information. We can chain multiple stages:

HD1HD2,orHD1HD2HD3H D_1 H D_2, \quad \text{or} \quad H D_1 H D_2 H D_3

Each DiD_i is an independent random diagonal ±1\pm 1 matrix. This compounding improves mixing for sparse inputs.


Self-Inverse Random Projections

We can even design self-inverse projections:

y=DHDx

The inverse is:

u=DHDyu=xu = D H D y \quad \Rightarrow \quad u = x

This is handy when you need the forward and backward transforms to be identical — for example, in certain symmetric network architectures.

For sparse input data, one option is:

y=D1HD2HD1x

which retains self-inverse properties while enhancing mixing.


Summary

  • HDH D gives a fast, orthogonal, low-storage random projection.

  • HDxH D x is inward-facing — great for forward mixing.

  • DHxD H x is outward-facing — great for preparing error signals in backprop.

  • Multi-stage and self-inverse versions extend these ideas for sparse data.

In short, combining the Walsh–Hadamard transform with sign flips is a simple but extremely versatile trick for machine learning and signal processing.

Closing

This method gives you O(nlogn)O(n \log n) projections without storing large random matrices, while keeping all the nice orthogonality properties of dense random projections.
It’s a tool worth adding to your mental toolbox for efficient high-dimensional transformations.

Thank you.

Comments

Popular posts from this blog

Neon Bulb Oscillators

23 Circuits you can Build in an Hour - Free Book

Q Multiplier Circuits