本文整理汇总了Python中Euclid.dccov_to_points方法的典型用法代码示例。如果您正苦于以下问题:Python Euclid.dccov_to_points方法的具体用法?Python Euclid.dccov_to_points怎么用?Python Euclid.dccov_to_points使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Euclid
的用法示例。
在下文中一共展示了Euclid.dccov_to_points方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_response_content
# 需要导入模块: import Euclid [as 别名]
# 或者: from Euclid import dccov_to_points [as 别名]
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)
示例2: get_response_content
# 需要导入模块: import Euclid [as 别名]
# 或者: from Euclid import dccov_to_points [as 别名]
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)
示例3: get_response_content
# 需要导入模块: import Euclid [as 别名]
# 或者: from Euclid import dccov_to_points [as 别名]
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()
示例4: get_response_content
# 需要导入模块: import Euclid [as 别名]
# 或者: from Euclid import dccov_to_points [as 别名]
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)