我想传递 COD、DB、Wounds 和 Medical 的值来计算概率。
我已经将 XPCE 代码编写为 GUI,如下所示。
list:-
new(D,dialog('Enter Evidence')),
send_list(D,append,
[new(COD,menu(cause_of_death,choice)),
new(DB,menu(dead_body,cycle)),
new(Wounds,menu(wound_and_injuries,cycle)),
new(Medical,menu(medical_evidence,cycle)),
new(_,button('OK',message(@prolog,prob,COD?selection,DB?selection,Wounds?selection,Medical?selection)))]),
send_list(COD,append,[suicide,homicide]),
findall(X,db_evidence(X),Y),
send_list(DB, append,Y),
findall(E,i_evidence(E),F),
send_list(Wounds, append,F),
findall(G,m_evidence(G),H),
send_list(Medical, append,H),
get(D,confirm, Answer),
get(Answer, element(1), A),
get(A, selection, AV),
get(Answer, element(2), B),
get(B, selection, BV),
get(Answer, element(3), C),
get(C, selection, CV),
Q = [AV, BV, CV],
db_evidence(hanging_dead_body).
i_evidence(offensive_injuries).
i_evidence(head_injuries).
i_evidence(markings).
m_evidence('state of mind').
m_evidence(traces_of_anaesthetic).
我计算概率的序言代码如下:
prob( COD,Q, P) :-
delete( Y, Q, Cond),
% predecessor( X, Y), !, % Y is a descendant of X
prob( X, Cond, Px),
prob( Y, [X | Cond], PyGivenX),
prob( Y, Cond, Py),
P is Px * PyGivenX / Py, % Assuming Py > 0
p(hanging_dead_body, 0.1).
p(offensive_injuries,0.05).
p(head_injuries, 0.5).
p(markings,0.2).
p('state of mind',0.1).
p(traces_of_anaesthetic,0.3).
% suicidal table
p( suicide, [hanging_dead_body,markings,traces_of_anaesthetic], 0.8).
结果应显示 P=概率的计算值。如果我的代码很混乱,我很抱歉。也许我对序言中的变量很陌生。请帮助我..谢谢你。