我想传递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).
我的prolog代码计算概率如下:
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 =概率的计算值。如果我的代码很混乱,我很抱歉。也许我在prolog中玩变量很新。请帮帮我..谢谢。
答案 0 :(得分:1)
我不知道这是否是您想要的,但是我编写了这段代码,当您单击“确定”时,它会为您提供在对话框中选择的内容:
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(D, return,
[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, value, AV),
get(Answer, element(2), B),
get(B, value, BV),
get(Answer, element(3), C),
get(C, value, CV),
get(Answer, element(4), E),
get(E, value, EV),
Q = [AV, BV, CV, EV],
writeln(Q).
例如:
?- list.
[suicide,hanging_dead_body,offensive_injuries,state of mind]
true.
答案 1 :(得分:1)
您应该定义prob / 4过程。例如
prob(COD,DB,Wounds,Medical) :-
writeln([COD,DB,Wounds,Medical]).
我已经用这种方式改变了对话框
...
send_list(Medical,append,H),
send(D, open).
当我点击OK时,prob / 4会被实际选择调用。