- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我已经为我使用 NetworkX 在 Python 中构建的图形实现了一个未加权的随机游走函数。下面是我处理随机游走的程序片段。在我的程序的其他地方,我有一个创建图形的方法,还有一个模拟我编写的各种自定义图形测试方法的方法。其中一种图测试方法从图中随机选择两个节点,并在它们之间随机游走。从这个随机游走中计算的两件事是命中时间(从起点到终点遍历的链接数)和通勤时间(从起点到终点再回到起点的遍历链接数) ).
def unweighted_random_walk(starting_point,ending_point, graph):
'''
starting_point: String that represents the starting point in the graph
ending_point: String that represents the ending point in the graph
graph: A NetworkX Graph object
'''
##Begin the random walk
current_point=starting_point
#current_node=graph[current_point]
current_point_neighors=graph.neighbors(current_point)
hitting_time=0
#Determine the hitting time to get to an arbitrary neighbor of the
#starting point
while current_point!=ending_point:
#pick one of the edges out of the starting_node with equal probs
possible_destination=current_point_neighbors[random.randint(0,current_point_neighors)]
current_point=possible_destination
current_point_neighbors=graph.neighbors(current_point)
hitting_time+=1
return hitting_time
我的随机游走代码非常简单,因为我只是选择随机节点直到到达终点。但是,当我尝试运行几次随机游走时(我想我有时需要运行一百万次),当前的实现速度非常慢。
我的问题是:有没有什么方法可以使用 Hadoop MapReduce 来并行化此处针对此随机游走进行的某些操作?有没有更好的方法让我进行随机游走?
最佳答案
我看不出 map-reduce 对您有何帮助。它用于具有两部分操作的地方:第一部分是可以对许多不同数据元素独立执行的计算,第二部分以某种方式组合所有这些结果。也许有一种聪明的方法可以使用 map-reduce 来帮助进行这种随机游走,但我没有看到。
您的随机游走是完全随机的:它可能以许多循环结束,甚至在继续之前在相同的两个节点之间来回跳跃。也许您想以某种方式限制它,这样您就没有那么大的搜索空间?
关于python - MapReduce、Python 和 NetworkX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1694237/
我正在尝试对网络上的投票动态进行建模,并希望能够在 NetworkX 中创建一个图表,在其中我可以在节点上迭代投票过程,让它们的颜色变化对应于它们的投票“标签”。 我已设法获得此代码以查看每个节点的属
我无法计算简单 NetworkX 加权图的中心性。 这是正常的还是我做错了什么? 我使用简单的 add_edge(c[0],c[1],weight = my_values) 添加边,其中c[0],c[
我想在函数调用 d(n) 之前比较 networkx.Graph 对象 n 的状态(有副作用)之后与国家合作。 有一些可变的对象节点属性,例如 n.node[0]['attribute'],我想对其进
我正在使用 NetworkX 生成一些噪声数据的图表。我想通过删除虚假分支来“清理”图表,并希望避免重新发明轮子。 例如,链接的图片显示了一组示例图形,作为由灰线连接的彩色节点。我想修剪白框指示的节点
我目前正在尝试制定一种算法来在图中查找派系,幸运的是我从 Networkx 找到了一个函数的文档,该函数就是这样做的。不幸的是,变量名有点简洁,我很难理解代码的每一部分的作用。 这里是 find_cl
我正在尝试使用 NetworkX 在两个节点之间添加平行边,但由于以下错误而失败。我究竟做错了什么? import networkx as nx import graphviz g1 = nx.Mul
我希望将 Pajek 数据集转换为 networkx Graph()。数据集来自哥斯达黎加Family Ties 。我正在使用非常方便的 networkx.read_pajek(pathname) 函
我在networkx中有一个巨大的图,我想从每个节点获取深度为2的所有子图。有没有一种好的方法可以使用networkx中的内置函数来做到这一点? 最佳答案 正如我在评论中所说,networkx.ego
我希望将 Pajek 数据集转换为 networkx Graph()。数据集来自哥斯达黎加Family Ties 。我正在使用非常方便的 networkx.read_pajek(pathname) 函
我在使用以下代码时遇到问题。边连接节点。但是是否有可能有一个定向网络,如果一个“人”跟随一个“人”,但它只是一种方式,在边缘有箭头或方向。 plt.figure(figsize=(12, 12)) #
我正在 Windows 机器上使用 Python 3,尽管付出了很多努力,但仍未能安装 pygraphviz。单独讨论。 我有networkx和graphviz模块...是否有一个范例可以在netwo
我正在使用《Python 自然语言处理》一书(“www.nltk.org/book”)自学 Python 和 NLTK。 我在 NetworkX 上被困在第 4 章第 4 部分第 8 部分。当我尝试运
下面是我的代码: import networkx as nx for i in range(2): G = nx.DiGraph() if i==0: G.add_ed
我正在使用 deap 符号回归示例问题中的这段代码,图形显示正常,但我希望节点扩展为圆角矩形以适合文本 自动 . (我不想只是通过反复试验来指定节点大小)。我该怎么做? # show tree imp
我正在尝试使用 networkx 读取 gml 文件(很简单吧?),除非我尝试读取文件时出现错误“networkx.exception.NetworkXError: cannot tokenize u
如何按厚度在networkx中绘制N> 1000个节点的加权网络?如果我有一个源、目标节点和每个边的权重的 .csv 列表,我正在考虑使用该方法: for i in range(N) G.add_ed
我希望 networkx 在我的定向中找到绝对最长的路径, 无环图。 我知道 Bellman-Ford,所以我否定了我的图长度。问题: networkx 的 bellman_ford() 需要一个源节
我在图中有一个节点,它充当一种“临时连接器”节点。我想删除该节点并更新图中的边,以便其所有直接前辈都指向其直接后继者。 在 networkx 中是否有内置功能可以做到这一点,还是我需要推出自己的解决方
我有两张彩色图表。我想确定它们是否同构,条件是同构必须保留顶点颜色。 networkx 中是否有算法可以做到这一点? 这些图是无向且简单的。 最佳答案 检查documentation对于is_isom
我有一组起点-终点坐标,我想计算它们之间的最短路径。 我的起点-终点坐标有时位于一条长直线道路的中间。但是,OSMnx/networkx 计算的最短路径不会考虑中间边到最近节点的路径。 OSMnx 或
我是一名优秀的程序员,十分优秀!