【发布时间】:2020-04-08 11:10:49
【问题描述】:
我正在从事一个主要基于逻辑编程的项目。我预先定义了程序用来计算概率的相关规则和事实,然后将这些概率附加到数据中并输入到进一步的机器学习模型中。计算概率的程序可以很容易地在 prolog 中定义如下,例如:
has_lot_work(daniel, 8). %number of lets say urgent tasks
has_lot_work(david, 3).
stress(X, P) :- has_lot_work(X, P2), P is P2 / 100.
to_smoke(X, Prob) :- stress(X, P1), friends(Y, X), influences(Y, X, P2), smokes(Y), Prob is P1 + P2.
to_have_asthma(X, 0.3) :- smokes(X). %30 percent of current smokers get asthma
to_have_asthma(X, Prob) :- to_smoke(X, P2), Prob is P2 * 0.25. %25 percent of smokers-to-be will get asthma
friends(X, Y) :- friend(X, Y).
friends(X, Y) :- friend(Y, X).
influences(X, Y, 0.4) :- friends(X, Y). %friends influence each other by 40 percent
friend(peter, david).
friend(peter, rebecca).
friend(daniel, rebecca).
smokes(peter).
smokes(rebecca).
在示例中,我感兴趣的是计算某人吸烟 (to_smoke(Who, Prob)) 和患哮喘 (to_have_asthma(Who, Prob)) 的概率。 我使用 python 来获取和清理数据以及之后的 ML 模型,所以我也想在 python 中应用这个逻辑。但是找不到进行这种逻辑计算的方法,也找不到正确的方法将 python 与 prolog 连接起来而不会出现错误和问题。
【问题讨论】:
-
请简要说明。很难理解你的问题。举一些例子更好地理解...
标签: python prolog logic-programming