%%%
%%%   Blood Type program
%%%
%%% Copyright (C) 1997
%%%   SATO Taisuke and KAMEYA Yoshitaka,
%%%      Dept. of Computer Science, Tokyo Institute of Technology

% extracts teacher data from file "blood.dat".

% learning process will start by
% | ?- learn.

% Statistical model:
bloodtype(a) :- genotype(a,a); genotype(a,o); genotype(o,a).
bloodtype(b) :- genotype(b,b); genotype(b,o); genotype(o,b).
bloodtype(o) :- genotype(o,o).
bloodtype(ab):- genotype(a,b); genotype(b,a).

genotype(X,Y) :- gene(dad,X), gene(mum,Y).

gene(P,a) :- bsw(1,P,1).
gene(P,b) :- bsw(1,P,0),bsw(2,P,1).
gene(P,o) :- bsw(1,P,0),bsw(2,P,0).

% Control declarations:
target(bloodtype,1).
data('blood.dat').

% Utility program:

% print the distribution of bloodtype
print_blood :- 
    prob(bloodtype(a),TA),prob(bloodtype(b),TB),
    prob(bloodtype(o),TO),prob(bloodtype(ab),TAB),
    format("Pb(Type = A) = ~6f",[TA]),nl,
    format("Pb(Type = B) = ~6f",[TB]),nl,
    format("Pb(Type = O) = ~6f",[TO]),nl,
    format("Pb(Type =AB) = ~6f",[TAB]),nl.

% print the distribution of gene
print_gene :-
    prob(gene(dad,a),GA),prob(gene(dad,b),GB),prob(gene(dad,o),GO),
    format("Pb(Gene = A) = ~6f",[GA]),nl,
    format("Pb(Gene = B) = ~6f",[GB]),nl,
    format("Pb(Gene = O) = ~6f",[GO]),nl.

% sample_japanese(N,L) :- 
%      L is sampled Japanese list with size N
sample_japanese(N,[X|Y]) :-
	N > 0,
	sample(bloodtype(X)),
	N1 is N-1,
	sample_japanese(N1,Y).
sample_japanese(0,[]).
