Skip to content
Snippets Groups Projects
Commit 5ed1b07f authored by Eric Würbel's avatar Eric Würbel
Browse files

work in progress. Does not run (and probably not compile either).

parent 670f2ce1
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,10 @@
% Compute the basic belief assignments of subsets of B in collection
% Bis.
%
% The resulting BBAs is a list of triplets (BaseLabel, Set, Mass)
% where BaseLabel is a label denoting the Set (subbases are labeled
% with an integer starting from 1, the full base is labeled with 0).
%
% Uses rational arithmetic.
%
% We use the is/2 predicate instead of the more practical #=/2 from
......@@ -32,14 +36,14 @@ basic_bbas(B, Bis, BBAs, Opts) :-
%! basic_bba2(+B, +CardB, +Bis, -BBAs) is det
%
% Utility predicade for basic_bbas/3.
% Utility predicate for basic_bbas/3.
basic_bba2(_, _, [], [], _).
basic_bba2(B, CardB, [Bi|Bis], [[(Bi, BBABi), (B, BBAB)]|BBAs], Opts) :-
basic_bba2(B, CardB, [N/Bi|Bis], [[([N], Bi, BBABi), ([0], B, BBAB)]|BBAs], Opts) :-
length(Bi, CardBi),
BBABi is CardBi / CardB,
BBAB is 1 - BBABi,
trace_bba(Bi, Bi, BBABi, Opts, 1),
trace_bba(Bi, B, BBAB, Opts, 1),
trace_bba(N/Bi, N/Bi, BBABi, Opts, 1),
trace_bba(N/Bi, 0/B, BBAB, Opts, 1),
basic_bba2(B, CardB, Bis, BBAs, Opts).
%! trace_bba(+RefSet, +Set, +Value, +Options, +TraceLevel) is det
......@@ -144,6 +148,14 @@ global_bba(B, Bis, GBBA, Opts) :-
basic_bbas(B, Bis, [B1|BasicBBAs], Opts),
global_bba2(B1, BasicBBAs, GBBA, Opts).
%! global_bba2(+BBa, +BBas, GBBA, Opts)
%
% Each BBa is a triplet (BaseLabel, Set, Mass)
% where Base Label is a label denoting the Set (subbases are labeled
% with an integer starting from 1, the full base is labeled with 0).
%
% TODO: continue : modify combine/4, merge_unique/2 and normalize/2
% to account for the new representation of BBas (couples -> triples)
global_bba2(B, [], B, _).
global_bba2(B, [BBa|BBas], GBBA, Opts) :-
trace('---- combining ~w & ~w -----------------------------~n', [B, BBa], Opts, 2),
......
......@@ -89,13 +89,17 @@ ldraw(Stream, B, Bis) :-
member(collec(Bisr), Terms),
is_list(Bisr),
maplist(is_list, Bisr),
check_bis(B, Bisr, Bis).
check_bis(B, Bisr, Bis, 1).
check_bis(_, [], []).
check_bis(B, [Bir|Bisr], [Bi|Bis]) :-
check_bis(_, [], [], _).
check_bis(B, [Bir|Bisr], [N/Bi|Bis], N) :-
list_to_ord_set(Bir, Bi),
% strict inclusion
ord_subset(Bi, B),
\+ ord_seteq(Bi, B),
check_bis(B, Bisr, Bis).
N1 #= N + 1,
check_bis(B, Bisr, Bis, N1).
......@@ -71,6 +71,11 @@ go :-
; full_evidence_computation(Opts, PosArgs)
).
%! full_evidence_computation(+Opts, +PosArgs)
%
% Computes and prints the credibility of each subset of B which is
% maximal-consistent with mu.
full_evidence_computation(Opts, PosArgs) :-
[BFile, MuFile] = PosArgs,
nb_setval(clasppath, '/home/wurbel/local/anaconda3/envs/potassco/bin/clingo'),
......@@ -83,7 +88,7 @@ full_evidence_computation(Opts, PosArgs) :-
load_sof(MuFile, Mu),
generate(B, Mu, TmpFile, Assoc),
run([TmpFile], ['--heuristic=Domain', '--enum-mode=domRec'], ASPResults),
collect_results(ASPResults, WinclResults),
collect_results(ASPResults, WinclResults, 1),
( memberchk(inclusion(true), Opts)
-> print_wincl(WinclResults, Assoc)
; true
......@@ -97,6 +102,10 @@ full_evidence_computation(_, PosArgs) :-
[_, _] \= PosArgs,
error("Bad number of positional args").
%! raw_evidence_computation(+Opts, +Args)
%
% Computes and prints the credibility of a collection of subsets.
raw_evidence_computation(Opts, PosArgs) :-
% hack
set_prolog_flag(prefer_rationals, true),
......@@ -127,6 +136,8 @@ test_wbel(Args) :-
catch(opt_parse(Spec, Args, Opts, PosArgs), Err, error_syn('~w~n', [Err], Spec)),
memberchk(asp(V), Opts),
nb_setval(aspdump, V),
memberchk(prog(Prog), Opts),
nb_setval(prog, Prog),
( memberchk(raw(true), Opts)
-> ( memberchk(inclusion(true), Opts)
-> error("incompatible options -r and -i")
......@@ -189,13 +200,17 @@ generate_b1(N, CountDown, [T|L], Func) :-
%! collect_results(+ASPRes, -WinclRes)
%
% collect ASP answer sets
collect_results([], []) :- !.
collect_results([as(L)|L1], [SL|L2]) :-
% Each answer set represent subbase of B which is maximaly consistent
% with mu. Number each base, that is, the results is a list of
% i/List terms.
collect_results([], [], _) :- !.
collect_results([as(L)|L1], [N/SL|L2], N) :-
!,
list_to_ord_set(L, SL),
collect_results(L1, L2).
collect_results([_|L1], L2) :-
collect_results(L1, L2).
N1 #= N + 1,
collect_results(L1, L2, N1).
collect_results([_|L1], L2, N) :-
collect_results(L1, L2, N).
%! generate(+B, +Mu, +TmpFile, -Assoc) is det
%
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment