An orthogonal matrix has $\frac{n(n-1)}{2}$ degrees of freedom.
Does there exist a function that maps $\frac{n(n-1)}{2}$ variables to the $n^2$ parameter orthogonal matrix?
And can such a function be differentiable?
The actual objective behind this problem is to feed some input through a random orthogonal matrix and obtain some result which is then fed through a loss function and the gradients are used to optimize the orthogonal matrix. Currently the approach I'm using is imposing a $L_1(W W^T - I)$ penalty to approximate this - but note how this doesn't prevent $W$ from being non-orthogonal just nudges it in that direction.
An $n \times n$ orthogonal matrix is a matrix whose rows (or columns, if you prefer) form an orthonormal basis of $\mathbb R^n$. You might start with $n$ random vectors and use Gram-Schmidt to orthonormalize them. If you run into numerical difficulty (because one of your vectors is too close to the linear span of the previous ones), choose a new random vector to replace it.