Examples
- In the chapter 15 of the textbook, there is a belief network:
prob( [ X | Xs ], Cond, P) :- !,
prob( X, Cond, Px ),
prob( Xs, [ X | Cond ], PRest ),
P is Px * PRest.
prob( [], _, 1 ) :- !.
prob( X, Cond, 1 ) :-
member( X, Cond ), !.
prob( X, Cond, 0 ) :-
member( not X, Cond ), !.
prob( not X, Cond, P ) :- !,
prob( X, Cond, P0 ),
P is 1 - P0.
prob( X, Cond0, P ) :-
delete( Y, Cond0, Cond ),
predecessor( X, Y ), !,
prob( X, Cond, Px ),
prob( Y, [ X | Cond ], PyGivenX),
prob( Y, Cond, Py),
P is Px * PyGivenX / Py.
prob( X, Cond, P ) :-
p( X, P ), !.
prob( X, Cond, P ) :- !,
findall( CONDi, Pi ), p( X, CONDi, Pi ), CPlist,
sum_probs( CPlist, Cond, P ).
sum_probs( [], _, 0 ).
sum_probs( [ (COND1, P1 ) | CondsProbs ], COND, P ) :-
prob( COND1, COND, PC1 ),
sum_probs( CondsProbs, COND, PRest ),
P is P1 * PC1 + PRest.
predecessor ( X, not Y ) :- !,
predecessor( X, Y ).
predecessor( X, Z ) :-
parent( X, Y ),
predecessor( X, Y ).
member( X, [ X | _ ] ).
member( X, [ _ | L ] ) :-
member( X, L ).
delete ( X, [ X | L ], L ).
delete ( X, [ Y | L ], [ Y | L2 ] ) :-
delete ( X, L, L2 ).
parent( burglary, sensor ).
parent( lighting, sensor ).
parent( sensor, alarm ).
parent( sensor, call ).
p( burglary, 0.001 ).
p( lighting, 0.02).
p( sensor, [ burglary, lighting ], 0.9 ).
p( sensor, [ burglary, not lighting ], 0.9 ).
p( sensor, [ not burglary, lighting ], 0.1 ).
p( sensor, [ not burglary, not lighting ], 0.1 ).
p( alarm, [ sensor ], 0.95 ).
p( alarm, [ not sensor ] , 0.05 ).
p( call, [ sensor ] , 0.9 ).
p( call, [ not sensor ], 0.0 ).
|
|