def get_response_content(fs): # read the points and edges points, edges = read_points_and_edges(fs.graph_data) # define edge weights if fs.weighted: np_points = [np.array(p) for p in points] dists = [np.linalg.norm(np_points[j] - np_points[i]) for i, j in edges] weights = [1.0 / d for d in dists] else: weights = [1.0 for e in edges] # get the width and height of the drawable area of the image width = fs.total_width - 2*fs.border height = fs.total_height - 2*fs.border if width < 1 or height < 1: msg = 'the image dimensions do not allow for enough drawable area' raise HandlingError(msg) # define the point colors using the unweighted graph Fiedler loadings L = edges_to_laplacian(edges, weights) G = np.linalg.pinv(L) X = Euclid.dccov_to_points(G) points = [(-p[0] if fs.flip else p[0], p[1]) for p in X] x_coords, y_coords = zip(*points) colors = valuations_to_colors(x_coords) # draw the image ext = Form.g_imageformat_to_ext[fs.imageformat] info = ImageInfo(fs.total_width, fs.total_height, fs.border, ext) try: return get_image_string(points, edges, colors, fs.black, info) except CairoUtil.CairoUtilError as e: raise HandlingError(e)
def get_response_content(fs): # read the points and edges points, edges = read_points_and_edges(fs.graph_data) # define edge weights if fs.weighted: np_points = [np.array(p) for p in points] dists = [np.linalg.norm(np_points[j] - np_points[i]) for i, j in edges] weights = [1.0 / d for d in dists] else: weights = [1.0 for e in edges] # get the width and height of the drawable area of the image width = fs.total_width - 2 * fs.border height = fs.total_height - 2 * fs.border if width < 1 or height < 1: msg = 'the image dimensions do not allow for enough drawable area' raise HandlingError(msg) # define the point colors using the unweighted graph Fiedler loadings L = edges_to_laplacian(edges, weights) G = np.linalg.pinv(L) X = Euclid.dccov_to_points(G) points = [(-p[0] if fs.flip else p[0], p[1]) for p in X] x_coords, y_coords = zip(*points) colors = valuations_to_colors(x_coords) # draw the image ext = Form.g_imageformat_to_ext[fs.imageformat] info = ImageInfo(fs.total_width, fs.total_height, fs.border, ext) try: return get_image_string(points, edges, colors, fs.black, info) except CairoUtil.CairoUtilError as e: raise HandlingError(e)
def get_response_content(fs): # Collect the image format information. border_info = BorderInfo(fs.border_x, fs.border_y) axis_info = AxisInfo(fs.flip_x, fs.flip_y, fs.show_x, fs.show_y) # read the points and edges points, edges = read_points_and_edges(fs.graph_data) # define edge weights if fs.weighted: np_points = [np.array(p) for p in points] dists = [np.linalg.norm(np_points[j] - np_points[i]) for i, j in edges] weights = [1.0 / d for d in dists] else: weights = [1.0 for e in edges] # define the point colors using the graph Fiedler loadings L = edges_to_laplacian(edges, weights) G = np.linalg.pinv(L) X = Euclid.dccov_to_points(G) points = [(p[0], p[1]) for p in X] xs, ys = zip(*points) colors = valuations_to_colors(xs) # Get the image. ext = Form.g_imageformat_to_ext[fs.imageformat] image_info = ImageInfo(fs.width, fs.height, fs.black, fs.show_edges, fs.show_labels, axis_info, border_info, ext) return get_image_string(xs, ys, colors, edges, image_info)
def get_response_content(fs): locations = get_locations() np_locs = [np.array(p) for p in locations] edges = get_edges() npoints = len(locations) # start writing the response np.set_printoptions(linewidth=200) out = StringIO() # print the layout data print >> out, 'POINTS' for i, (x, y) in enumerate(locations): print >> out, i, x, y print >> out, 'EDGES' for i, j in edges: print >> out, i, j print >> out # show the unweighted adjacency matrix UA = np.zeros((npoints, npoints)) for i, j in edges: UA[i, j] = 1 UA[j, i] = 1 print >> out, 'unweighted adjacency matrix:' print >> out, UA print >> out # show the unweighted laplacian matrix UL = Euclid.adjacency_to_laplacian(UA) print >> out, 'unweighted laplacian matrix:' print >> out, UL print >> out # show the weighted adjacency matrix WA = np.zeros((npoints, npoints)) for i, j in edges: d = np.linalg.norm(np_locs[i] - np_locs[j]) / math.sqrt(2.0) w = 1.0 / d WA[i, j] = w WA[j, i] = w print >> out, 'weighted adjacency matrix:' print >> out, WA print >> out # show the weighted laplacian matrix WL = Euclid.adjacency_to_laplacian(WA) print >> out, 'weighted laplacian matrix:' print >> out, WL print >> out # remove the two internal nodes by schur complementation ntips = 4 schur_L = SchurAlgebra.schur_helper(WL, 2) X = Euclid.dccov_to_points(np.linalg.pinv(schur_L)) print >> out, 'schur graph layout:' print >> out, 'POINTS' for i, v in enumerate(X): print >> out, i, v[0], v[1] print >> out, 'EDGES' for i in range(ntips): for j in range(i+1, ntips): print >> out, i, j # return the response return out.getvalue()
def get_response_content(fs): locations = get_locations() np_locs = [np.array(p) for p in locations] edges = get_edges() npoints = len(locations) # start writing the response np.set_printoptions(linewidth=200) out = StringIO() # print the layout data print >> out, 'POINTS' for i, (x, y) in enumerate(locations): print >> out, i, x, y print >> out, 'EDGES' for i, j in edges: print >> out, i, j print >> out # show the unweighted adjacency matrix UA = np.zeros((npoints, npoints)) for i, j in edges: UA[i, j] = 1 UA[j, i] = 1 print >> out, 'unweighted adjacency matrix:' print >> out, UA print >> out # show the unweighted laplacian matrix UL = Euclid.adjacency_to_laplacian(UA) print >> out, 'unweighted laplacian matrix:' print >> out, UL print >> out # show the weighted adjacency matrix WA = np.zeros((npoints, npoints)) for i, j in edges: d = np.linalg.norm(np_locs[i] - np_locs[j]) / math.sqrt(2.0) w = 1.0 / d WA[i, j] = w WA[j, i] = w print >> out, 'weighted adjacency matrix:' print >> out, WA print >> out # show the weighted laplacian matrix WL = Euclid.adjacency_to_laplacian(WA) print >> out, 'weighted laplacian matrix:' print >> out, WL print >> out # remove the two internal nodes by schur complementation ntips = 4 schur_L = SchurAlgebra.schur_helper(WL, 2) X = Euclid.dccov_to_points(np.linalg.pinv(schur_L)) print >> out, 'schur graph layout:' print >> out, 'POINTS' for i, v in enumerate(X): print >> out, i, v[0], v[1] print >> out, 'EDGES' for i in range(ntips): for j in range(i + 1, ntips): print >> out, i, j # return the response return out.getvalue()
def get_response_content(fs): # use a default border; actually this is ignored border_info = BorderInfo(10, 10) # Collect the image format information. axis_info = AxisInfo(fs.flip_x, fs.flip_y, fs.show_x, fs.show_y) # read the points and edges points, edges = read_points_and_edges(fs.graph_data) # define edge weights if fs.weighted: np_points = [np.array(p) for p in points] dists = [np.linalg.norm(np_points[j] - np_points[i]) for i, j in edges] weights = [1.0 / d for d in dists] else: weights = [1.0 for e in edges] # create the full laplacian L = edges_to_laplacian(edges, weights) if fs.schur: # remove internal nodes by schur complementation index_to_degree = edges_to_node_degrees(edges) internal_indices = set(i for i, d in enumerate(index_to_degree) if d > 1) L_schur = SchurAlgebra.mschur(L, internal_indices) L_final = L_schur else: L_final = L # define the point colors using the graph Fiedler loadings G = np.linalg.pinv(L_final) X = Euclid.dccov_to_points(G) points = [(p[0], p[1]) for p in X] xs, ys = zip(*points) colors = valuations_to_colors(xs) # draw the image ext = Form.g_imageformat_to_ext[fs.imageformat] image_info = ImageInfo(fs.width, fs.height, fs.black, fs.show_labels, axis_info, border_info, ext) return get_image_string(xs, ys, colors, edges, image_info, fs.scale)