【发布时间】:2020-11-04 06:36:25
【问题描述】:
我有一个使用字典的转换矩阵
{'hex1': {'hex2': 1.0},
'hex2': {'hex4': 0.4, 'hex7': 0.2, 'hex6': 0.2, 'hex1': 0.2},
'hex4': {'hex3': 1.0},
'hex3': {'hex6': 0.3333333333333333, 'hex2': 0.6666666666666666},
'hex6': {'hex1': 0.3333333333333333,
'hex4': 0.3333333333333333,
'hex5': 0.3333333333333333},
'hex7': {'hex6': 1.0},
'hex5': {'hex3': 1.0}}
显示从某个十六进制到另一个十六进制的概率(例如,hex1 的概率为 1 到 hex2,hex2 的概率为 0.4 到 hex4)。
取起点和终点,我想找到概率最高的路径。
代码结构如下所示
def find_most_probable_path(start_hex, end_hex, max_path):
path = compute for maximum probability path from start_hex to end_hex
return path
其中 max_path 是要遍历的最大十六进制数。如果 max_path 中没有路径,则返回空/null。此外,如果在到达结束十六进制之前回到起始十六进制,则丢弃路径。
例如
find_most_probable_path(hex2, hex3, 5)
>> "hex2,hex4,hex3"
输出可以是十六进制列表或只是连接的字符串。
【问题讨论】:
标签: python python-3.7 markov-chains