我正在尝试创建一个允许自定义infer_non_adjust.query()
功能的 Tkinter GUI。
我的意思是使用下拉菜单来选择不同的证据,然后单击运行将运行“新”功能。
这是我遇到错误消息的代码,目前我只是测试它以查看它是如何工作的。但是它似乎无法识别 variable.get,只需在主函数中替换视图而不是 variable.get 就可以正常工作。
"OPTIONS = [
"view",
] #etc
master = Tk()
variable = StringVar(master)
variable.set(OPTIONS[0]) # default value
w = OptionMenu(master, variable, *OPTIONS)
w.pack()
def ok():
print (infer_non_adjust.query(variables=[variable.get()], evidence={"PoisonTree": 1}))
button = Button(master, text="OK", command=ok)
button.pack()
mainloop()"
我收到以下错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\joshp\anaconda3\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:\Users\joshp\OneDrive\Documents\untitled0.py", line 177, in ok
print (infer_non_adjust.query(variables=[variable.get()], evidence={"PoisonTree": 1}))
File "C:\Users\joshp\anaconda3\lib\site-packages\pgmpy\inference\ExactInference.py", line 257, in query
return self._variable_elimination(
File "C:\Users\joshp\anaconda3\lib\site-packages\pgmpy\inference\ExactInference.py", line 198, in _variable_elimination
return factor_product(*final_distribution).normalize(inplace=False)
File "C:\Users\joshp\anaconda3\lib\site-packages\pgmpy\factors\base.py", line 66, in factor_product
raise NotImplementedError(
NotImplementedError: All the args are expected to be instances of the same factor class.
任何有关此操作或替代方法的帮助将不胜感激,感谢您的时间。