def orthogonal(shape, scale=1.1, name=None): flat_shape = (shape[0], np.prod(shape[1:])) a = np.random.normal(0.0, 1.0, flat_shape) u, _, v = np.linalg.svd(a, full_matrices=False) q = u if u.shape == flat_shape else v # pick the one with the correct shape q = q.reshape(shape) return sharedX(scale * q[:shape[0], :shape[1]], name=name)
def identity(shape, scale=1.0, name=None): if len(shape) != 2 or shape[0] != shape[1]: raise Exception("Identity matrix initialization can only be used for 2D square matrices") else: return sharedX(scale * np.identity(shape[0]), name=name)
def normal(shape, scale=0.05, name=None): return sharedX(np.random.randn(*shape) * scale, name=name)
def uniform(shape, scale=0.05, name=None): return sharedX(np.random.uniform(low=-scale, high=scale, size=shape), name=name)