我尝试使用以下代码来绘制 的度分布networkx.DiGraph G:
def plot_degree_In(G):
in_degrees = G.in_degree()
in_degrees=dict(in_degrees)
in_values = sorted(set(in_degrees.values()))
in_hist = [list(in_degrees.values()).count(x) for x in in_values]
plt.figure()
plt.grid(False)
plt.loglog(in_values, in_hist, 'r.')
#plt.loglog(out_values, out_hist, 'b.')
#plt.legend(['In-degree', 'Out-degree'])
plt.xlabel('k')
plt.ylabel('p(k)')
plt.title('Degree Distribution')
plt.xlim([0, 2*100**1])
Run Code Online (Sandbox Code Playgroud)
但后来我意识到这不是正确的做法,所以我将其更改为:
def plot_degree_dist(G):
degree_hist = nx.degree_histogram(G)
degree_hist = np.array(degree_hist, dtype=float)
degree_prob = degree_hist/G.number_of_nodes()
plt.loglog(np.arange(degree_prob.shape[0]),degree_prob,'b.')
plt.xlabel('k')
plt.ylabel('p(k)')
plt.title('Degree Distribution')
plt.show()
Run Code Online (Sandbox Code Playgroud)
但这给了我一个没有数据的空图。
我正在尝试为客户状态迁移制作有向图或桑基图(任何都可以)。数据如下所示,count 表示从当前状态迁移到下一个状态的用户数。
**current_state next_state count**
New Profile Initiated 37715
Profile Initiated End 36411
JobRecommended End 6202
New End 6171
ProfileCreated JobRecommended 5799
Profile Initiated ProfileCreated 4360
New NotOpted 3751
NotOpted Profile Initiated 2817
JobRecommended InterestedInJob 2542
IntentDetected ProfileCreated 2334
ProfileCreated IntentDetected 1839
InterestedInJob Applied 1671
JobRecommended NotInterestedInJob 1477
NotInterestedInJob ProfileCreated 1408
IntentDetected End 1325
NotOpted End 1009
InterestedInJob ProfileCreated 975
Applied IntentDetected 912
NotInterestedInJob IntentDetected 720
Applied ProfileCreated 701
InterestedInJob End 673
Run Code Online (Sandbox Code Playgroud)
我编写了一个构建 sankey 的代码,但该图不易阅读。寻找可读的有向图。这是我的代码:
df = pd.read_csv('input.csv')
x = …Run Code Online (Sandbox Code Playgroud) 这可能与功能数据结构有关,但我没有找到有关此主题的标签。
假设我有一个语法树类型Tree,它通过简单地共享公共子表达式来组织为 DAG。例如,
data Tree = Val Int | Plus Tree Tree
example :: Tree
example = let x = Val 42 in Plus x x
Run Code Online (Sandbox Code Playgroud)
然后,在这个语法树类型上,我有一个纯函数simplify :: Tree -> Tree,当给定 a 的根节点时,它Tree通过首先简化该根节点的子节点来简化整个树,然后处理根节点本身的操作。
由于simplify是纯函数,并且某些节点是共享的,因此我们希望不会simplify在这些共享节点上多次调用。
问题来了。整个数据结构是不变的,共享对程序员是透明的,因此似乎无法确定两个节点是否实际上是同一个节点。
在处理所谓的“打结”结构时也会出现同样的问题。通过打结,我们为原本无限的数据结构生成了有限的数据表示,例如let xs = 1 : xs in xs。这里xs本身是有限的,但调用map succ它并不一定会产生有限的表示。
这些问题可以归结为:当数据被组织在一个不变的有向图中时,我们如何避免重新访问同一个节点,做重复的工作,甚至在图恰好是循环的时候导致不终止?
我想到的一些想法:
Tree类型扩展为Tree a,使每个节点都拥有一个额外的a. 生成图形时,将每个节点与一个唯一a值相关联。尽管垃圾收集器可能随时移动任何堆对象,但内存地址应该在这里有效。STRef (Maybe Tree)在简化版本的每个节点中存储 …我需要在.NET应用程序中最多4维的稀疏矩阵.矩阵的大小(如果表示为.NET数组)可能会超过400MB.
该数组可能非常稀疏,我需要能够非常快速地实例化和处理它(尽管这不是不行).因此,我是在一个稀疏的数组库之后,从.NET 3.5(我相信使用来自Managed C++的BGL排除?)中可以使用尽可能密集的数据库,并支持快速随机访问索引.它必须可序列化为一些可以低成本缓存的密集格式.
.NET还存在这样的事情吗?FOSS?成熟?
TIA
安德鲁马修斯
我正在尝试分析一个应用程序,其中程序集引用应该是有向非循环图,但不是.还有一个相关的问题,即子组件引用了一个子组件的不同版本(想想Escher ......)
我想要做的是分析每个组件 - 子组件对,并建立一个错误的图片.
我需要一些关于什么是良好的数据结构的指导.我不太确定我可以构建一个不可变的那个,但是我不介意在内部将它变为可变,然后在最后转换为不可变的.
问题的另一部分是我应该使用什么样的算法来填充数据结构,然后用于"分析"问题.
我尝试了以下方法:
首先,我对给定边集中的所有边进行边收缩,以形成修改后的图.
然后我使用矩阵树定理从修改的图中计算生成树的总数.
我想知道这种方法是否正确以及是否有其他更好的方法.
提前道歉是我在滥用术语,并且对修改表示赞赏.我对有向图很着迷,但我从来没有数学/ cs背景来了解它们的真正含义,我只是喜欢技术,因为它制作了有用的图表.
我正在尝试创建一个Web应用程序功能,该功能将向浏览器呈现动态有向图.我最近发现了Canviz,这是一个基于cavas的xdot渲染器,我想使用它.
Canviz很棒,但它渲染xdot文件(显示?)包含所有复杂的定位逻辑
/* example xdot file */
digraph abstract {
graph [size="6,6"];
node [label="\N"];
graph [bb="0,0,1250,612",
_draw_="c 9 -#ffffffff C 9 -#ffffffff P 4 0 -1 0 612 1251 612 1251 -1 ",
xdotversion="1.2"];
S1 [pos="464,594", width="0.75", height="0.5", _draw_="c 9 -#000000ff e 464 594 27 18 ", _ldraw_="F 14.000000 11 -Times-Roman c 9 -#000000ff T 464 588 0 15 2 -S1 "];
10 [pos="409,522", width="0.75", height="0.5", _draw_="c 9 -#000000ff e 409 522 …Run Code Online (Sandbox Code Playgroud) 在计算机科学/软件工程中,有向图和有限状态机有什么区别?
我使用以下示例生成有向图
我想添加一个click事件,以便当用户单击某个节点时,将显示该节点的标题
到目前为止我做到了这一点
var circle = svg.append("svg:g").selectAll("circle")
.data(force.nodes())
.enter().append("svg:circle")
.attr("r", 6)
**.on("mouseup", disp)**
.call(force.drag);
;
function disp() {
alert("Display the heading of the node clicked here");
};
Run Code Online (Sandbox Code Playgroud)
请告诉我如何显示
我想使用networkx(如果您知道更好的框架,我也想采用其他框架)来创建节点位于固定位置的抓图。同时,图形的边缘不应重叠。
我之前的代码如下:
#!/usr/bin/env python3
import networkx as nx
import matplotlib.pyplot as plt
# Graph data
names = ['A', 'B', 'C', 'D', 'E']
positions = [(0, 0), (0, 1), (1, 0), (0.5, 0.5), (1, 1)]
edges = [('A', 'B'), ('A', 'C'), ('A', 'D'), ('A', 'E'), ('D', 'A')]
# Matplotlib figure
plt.figure('My graph problem')
# Create graph
G = nx.MultiDiGraph(format='png', directed=True)
for index, name in enumerate(names):
G.add_node(name, pos=positions[index])
labels = {}
for edge in edges:
G.add_edge(edge[0], edge[1])
labels[(edge[0], edge[1])] = '{} -> …Run Code Online (Sandbox Code Playgroud)