2

我想传递 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=概率的计算值。如果我的代码很混乱,我很抱歉。也许我对序言中的变量很陌生。请帮助我..谢谢你。

4

2 回答 2

1

我不知道这是否是您想要的,但我编写了这段代码,当您单击 OK 时,它会为您提供对话框中选择的内容:

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.
于 2013-01-27T09:57:20.107 回答
1

您应该定义 prob/4 过程。例如

prob(COD,DB,Wounds,Medical) :-
    writeln([COD,DB,Wounds,Medical]).

我以这种方式更改了对话框

...
send_list(Medical,append,H),
send(D, open).

当我单击 OK prob/4 时,会使用实际选择进行调用。

于 2013-01-27T10:48:37.230 回答