2012-06-08 14:08:14 +01:00
|
|
|
#!/home/tgomes/bin/yap -L --
|
|
|
|
|
|
|
|
:- use_module(library(lists)).
|
|
|
|
:- use_module(library(random)).
|
|
|
|
|
|
|
|
|
|
|
|
:- initialization(main).
|
|
|
|
|
|
|
|
main :-
|
|
|
|
unix(argv(Args)),
|
|
|
|
nth(1, Args, EV), % percentage of evidence
|
|
|
|
nth(2, Args, NP), % number of individuals
|
|
|
|
atomic_concat(['ev', EV, 'p', NP, '.yap'], FileName),
|
|
|
|
open(FileName, 'write', S),
|
|
|
|
atom_number(EV, EV2),
|
|
|
|
atom_number(NP, NP2),
|
|
|
|
EV3 is EV2 / 100.0,
|
|
|
|
generate_people(S, NP2, 4),
|
|
|
|
write(S, '\n'),
|
|
|
|
write(S, 'query(X) :- '),
|
|
|
|
generate_evidence(S, NP2, EV3, 4),
|
|
|
|
write(S, 'friends(p1,p2,X).\n'),
|
|
|
|
close(S).
|
|
|
|
|
|
|
|
|
|
|
|
generate_people(S, N, Counting) :-
|
|
|
|
Counting > N, !.
|
|
|
|
generate_people(S, N, Counting) :-
|
2013-01-09 15:25:14 +00:00
|
|
|
format(S, 'person(p~w).~n', [Counting]),
|
2012-06-08 14:08:14 +01:00
|
|
|
Counting1 is Counting + 1,
|
|
|
|
generate_people(S, N, Counting1).
|
|
|
|
|
|
|
|
|
|
|
|
generate_evidence(S, N, Ev, Counting) :-
|
|
|
|
Counting > N, !.
|
|
|
|
generate_evidence(S, N, Ev, Counting) :-
|
|
|
|
random(X),
|
|
|
|
(
|
|
|
|
X < Ev
|
|
|
|
->
|
|
|
|
random(Y),
|
|
|
|
(Y > 0.5 -> Val = t ; Val = f),
|
|
|
|
format(S, 'smokes(p~w,~w),', [Counting,Val])
|
|
|
|
;
|
|
|
|
true
|
|
|
|
),
|
|
|
|
Counting1 is Counting + 1,
|
|
|
|
generate_evidence(S, N, Ev, Counting1).
|
|
|
|
|