def logdet(self): d, s = self._d, self._s_perp fsh = full_shape([d.shape, s.shape]) logdet = np.zeros(fsh) for idx in itertools.product(*map(range, fsh)): d_idx, s_idx = broadcast(idx, d.shape), broadcast(idx, s.shape) logdet[idx] = np.log(d[d_idx]).sum() + \ (self.dim - d[d_idx].size) * np.log(s[s_idx]) return logdet
def __init__(self, mu, Sigma, Z=0.): mu, Sigma, Z = match_shapes([('mu', mu, 1), ('Sigma', Sigma, 0), ('Z', Z, 0)]) self._mu = mu self._Sigma = Sigma self._Z = Z self.dim = mu.shape[-1] self.ndim = mu.ndim - 1 self.shape = full_shape([Sigma.shape, mu.shape[:-1], Z.shape]) self.shape_str = '%s mu=%s Z=%s %s' % (Sigma.__class__, mu.shape, Z.shape, Sigma.shape_str)
def __init__(self, d, Q, s_perp, dim): BaseMatrix.__init__(self) d, Q, s_perp = match_shapes([('d', d, 0), ('Q', Q, 0), ('s_perp', s_perp, 0)]) self._d = d self._Q = Q self.dim = dim self.ndim = d.ndim self._s_perp = s_perp self.shape = full_shape([d.shape, Q.shape, s_perp.shape]) self.shape_str = 'd=%s Q=%s s_perp=%s' % (d.shape, Q.shape, s_perp.shape)
def _QDQ_x(Q, d, x): fsh = full_shape([x.shape[:-1], Q.shape, d.shape]) prod = np.zeros(fsh + (x.shape[-1], )) for full_idx in itertools.product(*map(range, fsh)): Q_idx = broadcast(full_idx, Q.shape) d_idx = broadcast(full_idx, d.shape) x_idx = broadcast(full_idx, x.shape[:-1]) curr_d, curr_Q = d[d_idx], Q[Q_idx] curr_x = x[x_idx + (slice(None), )] curr_QTx = np.dot(curr_Q.T, curr_x) prod[full_idx + (slice(None), )] = np.dot(curr_Q, curr_d * curr_QTx) return prod
def __init__(self, J, Lambda, Z): J, Lambda, Z = match_shapes([('J', J, 1), ('Lambda', Lambda, 0), ('Z', Z, 0)]) self._J = J self._Lambda = Lambda self._Z = Z self.shape = full_shape([J.shape[:-1], Lambda.shape, Z.shape]) self.ndim = J.ndim - 1 self.dim = J.shape[-1] self.shape_str = '%s J=%s Z=%s %s' % (Lambda.__class__, J.shape, Z.shape, Lambda.shape_str) self.mutable = False
def __init__(self, d, Q, s_perp): BaseMatrix.__init__(self) d, Q, s_perp = match_shapes([('d', d, 1), ('Q', Q, 2), ('s_perp', s_perp, 0)]) self._d = d self._Q = Q self.dim = Q.shape[-2] self.rank = Q.shape[-1] self.ndim = Q.ndim - 2 self.shape = full_shape([d.shape[:-1], Q.shape[:-2], s_perp.shape]) self._s_perp = s_perp self.shape_str = 'd=%s Q=%s s_perp=%s' % (d.shape, Q.shape, s_perp.shape)
def full(self): S = np.zeros( full_shape([self._d.shape, self._Q.shape]) + (self.dim, self.dim)) for idx in itertools.product(*map(range, S.shape[:-2])): d_idx, Q_idx = broadcast(idx, self._d.shape), broadcast( idx, self._Q.shape) d, Q = self._d[d_idx], self._Q[Q_idx] S[idx + (Ellipsis, )] = np.dot(Q * d, Q.T) sp_idx = broadcast(idx, self._s_perp.shape) sp = self._s_perp[sp_idx] S[idx + (Ellipsis, )] += (np.eye(self.dim) - np.dot(Q, Q.T)) * sp return FullMatrix(S)
def __init__(self, Lambda, J_diff, Z_diff, X): Lambda, J_diff, X = match_shapes([('Lambda', Lambda, 0), ('J_diff', J_diff, 1), ('X', X, 1)]) self._Lambda = Lambda self._J_diff = J_diff.copy() self._Z_diff = Z_diff.copy() self._X = X.copy() self.dim = self._J_diff.shape[-1] self.ndim = self._J_diff.ndim - 1 self.shape = full_shape( [Lambda.shape, J_diff.shape[:-1], X.shape[:-1]]) self.shape_str = '%s J_diff=%s X=%s %s' % ( Lambda.__class__, J_diff.shape, X.shape, Lambda.shape_str)