Prolog "zero"
Admin User, created Mar 15. 2025
/**
* Warranty & Liability
* To the extent permitted by applicable law and unless explicitly
* otherwise agreed upon, XLOG Technologies AG makes no warranties
* regarding the provided information. XLOG Technologies AG assumes
* no liability that any problems might be solved with the information
* provided by XLOG Technologies AG.
*
* Rights & License
* All industrial property rights regarding the information - copyright
* and patent rights in particular - are the sole property of XLOG
* Technologies AG. If the company was not the originator of some
* excerpts, XLOG Technologies AG has at least obtained the right to
* reproduce, change and translate the information.
*
* Reproduction is restricted to the whole unaltered document. Reproduction
* of the information is only allowed for non-commercial uses. Selling,
* giving away or letting of the execution of the library is prohibited.
* The library can be distributed as part of your applications and libraries
* for execution provided this comment remains unchanged.
*
* Restrictions
* Only to be distributed with programs that add significant and primary
* functionality to the library. Not to be distributed with additional
* software intended to replace any components of the library.
*
* Trademarks
* Jekejeke is a registered trademark of XLOG Technologies AG.
*/
:- ensure_loaded(library(aggregate)).
:- ensure_loaded(library(edge/adapt)).
:- ensure_loaded(library(lists)).
/************************************************************/
/* Multi */
/************************************************************/
/* Multi Classify */
/**
* zero_bayes(N, P-Q, G, C):
* The predicate succeeds in C with the binary decision diagrams,
* that map P to Q from G obtained by the majority rule. The
* parameter N gives the ensemble size.
*/
% zero_bayes(+Integer, +Pair, +Goal, -List)
zero_bayes(N, P-Q, G, C) :-
aggregate_all((bag(P), bag(Q)), G, (L, S)),
length(A, N), maplist(=(0-0), A),
foldl(sys_zero_delta_list, L, S, A, R),
maplist(sys_zero_majority, R, C).
% sys_zero_delta_list(+List, +List, +List, -List)
sys_zero_delta_list(P, Q, I, O) :-
maplist(sys_zero_delta(P), Q, I, O).
% sys_zero_delta(+List, +Integer, +Tree, -Tree)
sys_zero_delta(P, Q, S, H) :-
tree_current(P, 0, S, A-B),
C is A+Q,
D is B+(1-Q),
tree_set(P, 0, S, C-D, H).
% sys_zero_majority(+Tree, -Tree)
sys_zero_majority((K->A;B), T) :- !,
sys_zero_majority(A, C),
sys_zero_majority(B, D),
tree_make(K, C, D, T).
sys_zero_majority(A-B, 1) :- A > B, !.
sys_zero_majority(_, 0).
/* Multi Error */
/**
* zero_failure(P-Q, G, C, S):
* The predicate succeeds in S with the failure counts, comparing
* the binary decision diagrams C to the map P to Q from G.
*/
% zero_failure(+Pair, +Goal, +Tree, -Integer)
zero_failure(P-Q, G, C, S) :-
aggregate_all(count,
(G,
maplist(tree_current(P, 0), C, W),
Q \== W), S).