def random(d_shape, Q_shape, sp_shape, dim, rank=None): if rank is None: rank = dim ndim = len(d_shape) temp = np.random.normal(size=Q_shape + (dim, rank)) Q, _ = array_map(np.linalg.qr, [temp], ndim) d = np.random.gamma(1., 1., size=d_shape + (rank, )) sp = np.random.gamma(1., 1., size=sp_shape) return FixedEigMatrix(d, Q, sp)
def random(d_shape, Q_shape, sp_shape, dim, rank=None): if rank is None: rank = dim ndim = len(d_shape) temp = np.random.normal(size=Q_shape + (dim, rank)) Q, _ = array_map(np.linalg.qr, [temp], ndim) d = np.random.gamma(1., 1., size=d_shape + (rank,)) sp = np.random.gamma(1., 1., size=sp_shape) return FixedEigMatrix(d, Q, sp)
def pinv(self): try: return FullMatrix(array_map(my_inv, [self._S], self.ndim)) except np.linalg.LinAlgError: return FullMatrix(array_map(np.linalg.pinv, [self._S], self.ndim))
def full(self): S = array_map(np.diag, [self._s], self.ndim) return FullMatrix(S)
def to_eig(self): d, Q = array_map(np.linalg.eigh, [self._S], self.ndim) return FixedEigMatrix(d, Q, 0)
def sqrt_dot(self, x): L = array_map(np.linalg.cholesky, [self._S + 1e-10 * np.eye(self.dim)], self.ndim) return dot(L, x)
def conv(self, other): other = other.full() P = array_map(my_inv, [self._S + other._S], self.ndim) return FullMatrix(dot(self._S, dot(P, other._S)))
def inv(self): return FullMatrix(array_map(np.linalg.inv, [self._S], self.ndim))
def inv(self): return FullMatrix(array_map(my_inv, [self._S], self.ndim))
def logdet(self): _, ld = array_map(np.linalg.slogdet, [self._S], self.ndim) return ld