Skip to content

Instantly share code, notes, and snippets.

@jbornschein
Created December 17, 2014 04:55
Show Gist options
  • Save jbornschein/3df7833ae75d9c5cbced to your computer and use it in GitHub Desktop.
Save jbornschein/3df7833ae75d9c5cbced to your computer and use it in GitHub Desktop.
Create an (semi-) orthogonal matrix
def orthogonal_matrix(n_lower, n_upper):
"""
Creates and returns an orthogonal weight matrix.
For non square matrices this will just ignire some degrees of freedom.
"""
R_lower, _ = np.linalg.qr( np.random.normal(size=(n_lower, n_lower)) )
R_upper, _ = np.linalg.qr( np.random.normal(size=(n_upper, n_upper)) )
n_min = min(n_lower, n_upper)
W = gain * np.dot(R_out[:,:n_min], R_in[:n_min,:])
return W
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment