2

I want to pass the values of COD, DB, Wounds and Medical to calculate probability.

I've wrote the XPCE code as the GUI as below.

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).

my prolog code to calculate probability are as below:

 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).

The result should shows the calculated value of P=probability. i'm sorry if my code is quite confusing. maybe i'm quite new playing with variables in prolog. please help me..Thank u.

false
  • 10,264
  • 13
  • 101
  • 209
wana
  • 21
  • 2
  • Your code is not complete : code of list after **Q = [AV, BV, CV]**, code of prob after **P is Px * PyGivenX / Py**, may be typos, "," instead of "." ? – joel76 Jan 27 '13 at 09:31

2 Answers2

1

I don't know if this is what you want, but I wrote this code that gives you what is selected in the dialog box when you click 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).

For example :

 ?- list.
[suicide,hanging_dead_body,offensive_injuries,state of mind]
true.
joel76
  • 5,565
  • 1
  • 18
  • 22
  • thanx.but this is not the result i want. i want to calculate the probability result of P. anyway, thank u. – wana Jan 28 '13 at 02:41
1

You should define the prob/4 procedure. For instance

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

I've changed the dialog in this way

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

When I click OK prob/4 get called with actual choices.

CapelliC
  • 59,646
  • 5
  • 47
  • 90