def add_tree(): # construct the matrices to be used for the eigendecomposition lfdo = ProofDecoration.tree_string_to_LFDO(g_tree_string) lfdi = ProofDecoration.LFDO_to_LFDI(lfdo) # we need the ordered ids themselves to to construct the edges tree = NewickIO.parse(g_tree_string, FelTree.NewickTree) ordered_ids = ProofDecoration.tree_to_leaf_first_ids(tree) index_edges = get_index_edges(tree, ordered_ids) # define the points X, Y, Z = get_grant_proposal_points_b(lfdi) # draw the image draw_3d_tree(X, Y, Z, index_edges) draw_crossings(X, Y, Z, index_edges)
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_response_content(fs): # define the requested physical size of the images (in pixels) physical_size = (640, 480) # construct the matrices to be used for the eigendecomposition lfdo = ProofDecoration.tree_string_to_LFDO(fs.tree_string) lfdi = ProofDecoration.LFDO_to_LFDI(lfdo) # we need the ordered ids themselves to to construct the edges tree = NewickIO.parse(fs.tree_string, FelTree.NewickTree) ordered_ids = ProofDecoration.tree_to_leaf_first_ids(tree) index_edges = get_index_edges(tree, ordered_ids) # define the points points = get_grant_proposal_points_b(lfdi) # draw the image ext = Form.g_imageformat_to_ext[fs.imageformat] return get_animation_frame(ext, physical_size, fs.scale, index_edges, points)
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