def get_grant_proposal_points_b(lfdi): M, p, q = lfdi.M, lfdi.p, lfdi.q G = -.5 * M GQ, GX, GXT, GP = ProofDecoration.get_corners(G, q, p) # Get the eigendecomposition of the leaf-only Gower matrix. ws, vs = EigUtil.eigh(GQ) S = np.diag(ws) U = np.vstack(vs).T USUT = np.dot(np.dot(U, S), U.T) if not np.allclose(USUT, GQ): raise ValueError('eigenfail') S_sqrt = np.diag(np.sqrt(ws)) X = np.dot(U, S_sqrt) # Find the imputed internal points. S_sqrt_pinv = np.linalg.pinv(S_sqrt) #W = np.dot(np.dot(S_sqrt_pinv, GX.T), U) try: W = np.dot(np.dot(GX.T, U), S_sqrt_pinv) except ValueError as e: arr = [GX.shape, U.shape, S_sqrt_pinv.shape] raise ValueError(', '.join(str(x) for x in arr)) # put them together and get only the first coordinates full_points = np.vstack([X, W]) X = full_points.T[0] Y = full_points.T[1] Z = full_points.T[2] return X, Y, Z
def get_grant_proposal_points_b(lfdi): M, p, q = lfdi.M, lfdi.p, lfdi.q G = -.5 * M GQ, GX, GXT, GP = ProofDecoration.get_corners(G, q, p) # Get the eigendecomposition of the leaf-only Gower matrix. ws, vs = EigUtil.eigh(GQ) S = np.diag(ws) U = np.vstack(vs).T USUT = np.dot(np.dot(U, S), U.T) if not np.allclose(USUT, GQ): raise ValueError('eigenfail') S_sqrt = np.diag(np.sqrt(ws)) X = np.dot(U, S_sqrt) # Find the imputed internal points. S_sqrt_pinv = np.linalg.pinv(S_sqrt) #W = np.dot(np.dot(S_sqrt_pinv, GX.T), U) try: W = np.dot(np.dot(GX.T, U), S_sqrt_pinv) except ValueError as e: arr = [ GX.shape, U.shape, S_sqrt_pinv.shape] msg = ', '.join(str(x) for x in arr) raise ValueError(msg) # put them together and get only the first coordinates full_points = np.vstack([X, W]) points = full_points.T[:2].T return points