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.