# Python(C++)大尺度分层边值时变图统计推理并行算法

363 篇文章 24 订阅
75 篇文章 0 订阅

### 🎯要点

🎯分层结构制定生成模型 | 🎯贝叶斯模型选择程序 | 🎯分层结构图的信息性 | 🎯分层模型适应实值边协变量的网络 | 🎯分层模型适应时变网络，划分层对应于检测变化点 | 🎯定义两种版本随机块模型：🖊具有边缘协变量模型概率分布，分层图总似然 | 🖊独立分层模型分层图数学似然计算 | 🎯推理算法：大图形尺度并行计算算法，过滤暂时被遮蔽的节点和边

### 🍇Python交通图模拟

adjacency_matrix = nx.to_numpy_array(G)
assert degree_town_0 == len(G[0])
assert degree_town_0 == G.degree(0)
print(f"Town 0 is connected by {degree_town_0:.0f} roads.")

Town 0 is connected by 5 roads.


np.random.seed(1)
degree = G.degree(central_town)
print(f"Town {central_town} is our most central town. It has {degree} "
node_colors[central_town] = 'k'
nx.draw(G, with_labels=True, node_color=node_colors)
plt.show()

Town 3 is our most central town. It has 9 connecting roads.


second_town = sorted(G.nodes, key=lambda x: G.degree(x), reverse=True)[1]
second_degree = G.degree(second_town)
print(f"Town {second_town} has {second_degree} connecting roads.")

Town 12 has 8 connecting roads.


np.random.seed(1)
G.remove_edge(3, 9)
assert G.degree(3) == G.degree(12)
nx.draw(G, with_labels=True, node_color=node_colors)
plt.show()


np.random.seed(0)
def random_drive(num_stops=10):
town = np.random.choice(G.nodes)
for _ in range(num_stops):
town = np.random.choice(G[town])
destination = random_drive()
print(f"After driving randomly, the car has reached Town {destination}.")

After driving randomly, the car has reached Town 24.


import time
np.random.seed(0)
car_counts = np.zeros(len(G.nodes))
num_cars = 20000
start_time = time.time()
for _ in range(num_cars):
destination = random_drive()
car_counts[destination] += 1
central_town = car_counts.argmax()
traffic = car_counts[central_town]
running_time = time.time() - start_time
print(f"We ran a {running_time:.2f} second simulation.")
print(f"Town {central_town} has the most traffic.")
print(f"There are {traffic:.0f} cars in that town.")

We ran a 3.47 second simulation.
Town 12 has the most traffic.
There are 1015 cars in that town.


print(f"There are {car_counts[3]:.0f} cars in Town 3.")

There are 934 cars in Town 3.


probabilities = car_counts / num_cars
for i in [12, 3]:
prob = probabilities[i]
print(f"The probability of winding up in Town {i} is {prob:.3f}.")

The probability of winding up in Town 12 is 0.051.
The probability of winding up in Town 3 is 0.047.


#### 👉参阅、更新：计算思维 | 亚图跨际

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。