support exporting top-level-work as absolute path
This commit is contained in:
parent
7b993ca987
commit
1f7b839e85
5
configure
vendored
5
configure
vendored
@ -7186,8 +7186,8 @@ fi
|
|||||||
SHLIB_CFLAGS="-fno-common"
|
SHLIB_CFLAGS="-fno-common"
|
||||||
SHLIB_SUFFIX=".dylib"
|
SHLIB_SUFFIX=".dylib"
|
||||||
DO_SECOND_LD=""
|
DO_SECOND_LD=""
|
||||||
SHLIB_LD="$CC -bundle -bundle_loader $abs_top_builddir/yap -L$abs_top_builddir -lYap -undefined dynamic_lookup -Wl,-x -dead-strip -dead_strip_dylibs"
|
# SHLIB_LD="$CC -bundle -bundle_loader \$(abs_top_builddir)/yap -L\$(abs_top_builddir) -lYap -undefined dynamic_lookup -Wl,-x -dead-strip -dead_strip_dylibs"
|
||||||
LDFLAGS="-Wl,-x -dead_strip $LDFLAGS"
|
# LDFLAGS="-Wl,-x -dead_strip -dead_strip_dylibs $LDFLAGS"
|
||||||
SHLIB_LD="$CC -bundle -flat_namespace -undefined suppress"
|
SHLIB_LD="$CC -bundle -flat_namespace -undefined suppress"
|
||||||
INSTALL_DLLS=""
|
INSTALL_DLLS=""
|
||||||
CC="$CC -fstrict-aliasing -freorder-blocks -fsched-interblock -Wall -Wstrict-aliasing=2"
|
CC="$CC -fstrict-aliasing -freorder-blocks -fsched-interblock -Wall -Wstrict-aliasing=2"
|
||||||
@ -7325,6 +7325,7 @@ then
|
|||||||
DYNLIB_LD="$CC -dynamiclib"
|
DYNLIB_LD="$CC -dynamiclib"
|
||||||
PRE_DYNLOADER_PATH="DYLD_LIBRARY_PATH=\$(abs_top_builddir)"
|
PRE_DYNLOADER_PATH="DYLD_LIBRARY_PATH=\$(abs_top_builddir)"
|
||||||
EXTEND_DYNLOADER_PATH="DYLD_LIBRARY_PATH=\$(DESTDIR)\$(LIBDIR): YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR)/Yap YAPBOOTDIR=\$(DESTDIR)\$(SHAREDIR)/Yap/pl YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
|
EXTEND_DYNLOADER_PATH="DYLD_LIBRARY_PATH=\$(DESTDIR)\$(LIBDIR): YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR)/Yap YAPBOOTDIR=\$(DESTDIR)\$(SHAREDIR)/Yap/pl YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
|
||||||
|
# CROSS_SIMULATOR="DYLD_LIBRARY_PATH=."
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
case "$target_cpu" in
|
case "$target_cpu" in
|
||||||
|
@ -877,8 +877,8 @@ dnl Linux has both elf and a.out, in this case we found elf
|
|||||||
SHLIB_CFLAGS="-fno-common"
|
SHLIB_CFLAGS="-fno-common"
|
||||||
SHLIB_SUFFIX=".dylib"
|
SHLIB_SUFFIX=".dylib"
|
||||||
DO_SECOND_LD=""
|
DO_SECOND_LD=""
|
||||||
SHLIB_LD="$CC -bundle -bundle_loader $abs_top_builddir/yap -L$abs_top_builddir -lYap -undefined dynamic_lookup -Wl,-x -dead-strip -dead_strip_dylibs"
|
# SHLIB_LD="$CC -bundle -bundle_loader \$(abs_top_builddir)/yap -L\$(abs_top_builddir) -lYap -undefined dynamic_lookup -Wl,-x -dead-strip -dead_strip_dylibs"
|
||||||
LDFLAGS="-Wl,-x -dead_strip $LDFLAGS"
|
# LDFLAGS="-Wl,-x -dead_strip -dead_strip_dylibs $LDFLAGS"
|
||||||
SHLIB_LD="$CC -bundle -flat_namespace -undefined suppress"
|
SHLIB_LD="$CC -bundle -flat_namespace -undefined suppress"
|
||||||
INSTALL_DLLS=""
|
INSTALL_DLLS=""
|
||||||
CC="$CC -fstrict-aliasing -freorder-blocks -fsched-interblock -Wall -Wstrict-aliasing=2"
|
CC="$CC -fstrict-aliasing -freorder-blocks -fsched-interblock -Wall -Wstrict-aliasing=2"
|
||||||
@ -952,6 +952,7 @@ then
|
|||||||
DYNLIB_LD="$CC -dynamiclib"
|
DYNLIB_LD="$CC -dynamiclib"
|
||||||
PRE_DYNLOADER_PATH="DYLD_LIBRARY_PATH=\$(abs_top_builddir)"
|
PRE_DYNLOADER_PATH="DYLD_LIBRARY_PATH=\$(abs_top_builddir)"
|
||||||
EXTEND_DYNLOADER_PATH="DYLD_LIBRARY_PATH=\$(DESTDIR)\$(LIBDIR): YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR)/Yap YAPBOOTDIR=\$(DESTDIR)\$(SHAREDIR)/Yap/pl YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
|
EXTEND_DYNLOADER_PATH="DYLD_LIBRARY_PATH=\$(DESTDIR)\$(LIBDIR): YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR)/Yap YAPBOOTDIR=\$(DESTDIR)\$(SHAREDIR)/Yap/pl YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)"
|
||||||
|
# CROSS_SIMULATOR="DYLD_LIBRARY_PATH=."
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
case "$target_cpu" in
|
case "$target_cpu" in
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
ROOTDIR = $(prefix)
|
ROOTDIR = $(prefix)
|
||||||
EROOTDIR = @exec_prefix@
|
EROOTDIR = @exec_prefix@
|
||||||
|
abs_top_builddir = @abs_top_builddir@
|
||||||
#
|
#
|
||||||
# where the binary should be
|
# where the binary should be
|
||||||
#
|
#
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
ROOTDIR = $(prefix)
|
ROOTDIR = $(prefix)
|
||||||
EROOTDIR = @exec_prefix@
|
EROOTDIR = @exec_prefix@
|
||||||
|
abs_top_builddir = @abs_top_builddir@
|
||||||
#
|
#
|
||||||
# where the binary should be
|
# where the binary should be
|
||||||
#
|
#
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
ROOTDIR = $(prefix)
|
ROOTDIR = $(prefix)
|
||||||
EROOTDIR = @exec_prefix@
|
EROOTDIR = @exec_prefix@
|
||||||
|
abs_top_builddir = @abs_top_builddir@
|
||||||
#
|
#
|
||||||
# where the binary should be
|
# where the binary should be
|
||||||
#
|
#
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
ROOTDIR = $(prefix)
|
ROOTDIR = $(prefix)
|
||||||
EROOTDIR = @exec_prefix@
|
EROOTDIR = @exec_prefix@
|
||||||
|
abs_top_builddir = @abs_top_builddir@
|
||||||
#
|
#
|
||||||
# where the binary should be
|
# where the binary should be
|
||||||
#
|
#
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
ROOTDIR = $(prefix)
|
ROOTDIR = $(prefix)
|
||||||
EROOTDIR = @exec_prefix@
|
EROOTDIR = @exec_prefix@
|
||||||
|
abs_top_builddir = @abs_top_builddir@
|
||||||
#
|
#
|
||||||
# where the binary should be
|
# where the binary should be
|
||||||
#
|
#
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
ROOTDIR = $(prefix)
|
ROOTDIR = $(prefix)
|
||||||
EROOTDIR = @exec_prefix@
|
EROOTDIR = @exec_prefix@
|
||||||
|
abs_top_builddir = @abs_top_builddir@
|
||||||
#
|
#
|
||||||
# where the binary should be
|
# where the binary should be
|
||||||
#
|
#
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
ROOTDIR = $(prefix)
|
ROOTDIR = $(prefix)
|
||||||
EROOTDIR = @exec_prefix@
|
EROOTDIR = @exec_prefix@
|
||||||
|
abs_top_builddir = @abs_top_builddir@
|
||||||
#
|
#
|
||||||
# where the binary should be
|
# where the binary should be
|
||||||
#
|
#
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
ROOTDIR = $(prefix)
|
ROOTDIR = $(prefix)
|
||||||
EROOTDIR = @exec_prefix@
|
EROOTDIR = @exec_prefix@
|
||||||
|
abs_top_builddir = @abs_top_builddir@
|
||||||
#
|
#
|
||||||
# where the binary should be
|
# where the binary should be
|
||||||
#
|
#
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
ROOTDIR = $(prefix)
|
ROOTDIR = $(prefix)
|
||||||
EROOTDIR = @exec_prefix@
|
EROOTDIR = @exec_prefix@
|
||||||
|
abs_top_builddir = @abs_top_builddir@
|
||||||
#
|
#
|
||||||
# where the binary should be
|
# where the binary should be
|
||||||
#
|
#
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
ROOTDIR = $(prefix)
|
ROOTDIR = $(prefix)
|
||||||
EROOTDIR = @exec_prefix@
|
EROOTDIR = @exec_prefix@
|
||||||
|
abs_top_builddir = @abs_top_builddir@
|
||||||
#
|
#
|
||||||
# where the binary should be
|
# where the binary should be
|
||||||
#
|
#
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
ROOTDIR = $(prefix)
|
ROOTDIR = $(prefix)
|
||||||
EROOTDIR = @exec_prefix@
|
EROOTDIR = @exec_prefix@
|
||||||
|
abs_top_builddir = @abs_top_builddir@
|
||||||
#
|
#
|
||||||
# where the binary should be
|
# where the binary should be
|
||||||
#
|
#
|
||||||
|
@ -1560,7 +1560,7 @@ PL_initialise(int myargc, char **myargv)
|
|||||||
|
|
||||||
init_args.Argv = myargv;
|
init_args.Argv = myargv;
|
||||||
init_args.Argc = myargc;
|
init_args.Argc = myargc;
|
||||||
init_args.SavedState = "startup";
|
init_args.SavedState = "startup.yss";
|
||||||
init_args.HeapSize = 0;
|
init_args.HeapSize = 0;
|
||||||
init_args.StackSize = 0;
|
init_args.StackSize = 0;
|
||||||
init_args.TrailSize = 0;
|
init_args.TrailSize = 0;
|
||||||
|
@ -45,6 +45,7 @@ CLPBN_PROGRAMS= \
|
|||||||
$(CLPBN_SRCDIR)/hmm.yap \
|
$(CLPBN_SRCDIR)/hmm.yap \
|
||||||
$(CLPBN_SRCDIR)/jt.yap \
|
$(CLPBN_SRCDIR)/jt.yap \
|
||||||
$(CLPBN_SRCDIR)/matrix_cpt_utils.yap \
|
$(CLPBN_SRCDIR)/matrix_cpt_utils.yap \
|
||||||
|
$(CLPBN_SRCDIR)/pgrammar.yap \
|
||||||
$(CLPBN_SRCDIR)/table.yap \
|
$(CLPBN_SRCDIR)/table.yap \
|
||||||
$(CLPBN_SRCDIR)/topsort.yap \
|
$(CLPBN_SRCDIR)/topsort.yap \
|
||||||
$(CLPBN_SRCDIR)/utils.yap \
|
$(CLPBN_SRCDIR)/utils.yap \
|
||||||
|
@ -63,7 +63,8 @@
|
|||||||
dist/4,
|
dist/4,
|
||||||
get_dist/4,
|
get_dist/4,
|
||||||
get_evidence_position/3,
|
get_evidence_position/3,
|
||||||
get_evidence_from_position/3
|
get_evidence_from_position/3,
|
||||||
|
additive_dists/6
|
||||||
]).
|
]).
|
||||||
|
|
||||||
:- use_module('clpbn/evidence',
|
:- use_module('clpbn/evidence',
|
||||||
@ -130,7 +131,9 @@ clpbn_flag(parameter_softening,Before,After) :-
|
|||||||
{Var = Key with Dist} :-
|
{Var = Key with Dist} :-
|
||||||
put_atts(El,[key(Key),dist(DistInfo,Parents)]),
|
put_atts(El,[key(Key),dist(DistInfo,Parents)]),
|
||||||
dist(Dist, DistInfo, Key, Parents),
|
dist(Dist, DistInfo, Key, Parents),
|
||||||
add_evidence(Var,Key,DistInfo,El).
|
add_evidence(Var,Key,DistInfo,El)
|
||||||
|
% ,writeln({Var = Key with Dist})
|
||||||
|
.
|
||||||
|
|
||||||
check_constraint(Constraint, _, _, Constraint) :- var(Constraint), !.
|
check_constraint(Constraint, _, _, Constraint) :- var(Constraint), !.
|
||||||
check_constraint((A->D), _, _, (A->D)) :- var(A), !.
|
check_constraint((A->D), _, _, (A->D)) :- var(A), !.
|
||||||
@ -285,16 +288,23 @@ verify_attributes(_, _, []).
|
|||||||
bind_clpbn(T, Var, _, _, _) :- nonvar(T),
|
bind_clpbn(T, Var, _, _, _) :- nonvar(T),
|
||||||
!, ( add_evidence(Var,T) -> true ; writeln(T:Var), fail ).
|
!, ( add_evidence(Var,T) -> true ; writeln(T:Var), fail ).
|
||||||
bind_clpbn(T, Var, Key, Dist, Parents) :- var(T),
|
bind_clpbn(T, Var, Key, Dist, Parents) :- var(T),
|
||||||
get_atts(T, [key(Key1),dist(Dist1,Parents1)]), !,
|
get_atts(T, [key(Key1),dist(Dist1,Parents1)]),
|
||||||
bind_clpbns(Key, Dist, Parents, Key1, Dist1, Parents1),
|
writeln(eq:Key:Key1),
|
||||||
(
|
(
|
||||||
|
bind_clpbns(Key, Dist, Parents, Key1, Dist1, Parents1)
|
||||||
|
->
|
||||||
|
(
|
||||||
get_atts(T, [evidence(Ev1)]) ->
|
get_atts(T, [evidence(Ev1)]) ->
|
||||||
bind_evidence_from_extra_var(Ev1,Var)
|
bind_evidence_from_extra_var(Ev1,Var)
|
||||||
;
|
;
|
||||||
get_atts(Var, [evidence(Ev)]) ->
|
get_atts(Var, [evidence(Ev)]) ->
|
||||||
bind_evidence_from_extra_var(Ev,T)
|
bind_evidence_from_extra_var(Ev,T)
|
||||||
|
;
|
||||||
|
true
|
||||||
|
)
|
||||||
;
|
;
|
||||||
true).
|
fail
|
||||||
|
).
|
||||||
bind_clpbn(_, Var, _, _, _, _) :-
|
bind_clpbn(_, Var, _, _, _, _) :-
|
||||||
use(bnt),
|
use(bnt),
|
||||||
check_if_bnt_done(Var), !.
|
check_if_bnt_done(Var), !.
|
||||||
@ -309,6 +319,7 @@ bind_clpbn(T, Var, Key0, _, _, _) :-
|
|||||||
(
|
(
|
||||||
Key = Key0 -> true
|
Key = Key0 -> true
|
||||||
;
|
;
|
||||||
|
% let us not loose whatever we had.
|
||||||
add_evidence(Var,T)
|
add_evidence(Var,T)
|
||||||
).
|
).
|
||||||
|
|
||||||
@ -318,17 +329,11 @@ fresh_attvar(Var, NVar) :-
|
|||||||
|
|
||||||
% I will now allow two CLPBN variables to be bound together.
|
% I will now allow two CLPBN variables to be bound together.
|
||||||
%bind_clpbns(Key, Dist, Parents, Key, Dist, Parents).
|
%bind_clpbns(Key, Dist, Parents, Key, Dist, Parents).
|
||||||
bind_clpbns(Key, Dist, Parents, Key1, Dist1, Parents1) :-
|
bind_clpbns(Key, Dist, _Parents, Key1, Dist1, _Parents1) :-
|
||||||
Key == Key1, !,
|
Key == Key1, !,
|
||||||
get_dist(Dist,Type,Domain,Table),
|
get_dist(Dist,_Type,_Domain,_Table),
|
||||||
get_dist(Dist1,Type1,Domain1,Table1),
|
get_dist(Dist1,_Type1,_Domain1,_Table1),
|
||||||
( Dist == Dist1,
|
Dist = Dist1.
|
||||||
same_parents(Parents,Parents1)
|
|
||||||
->
|
|
||||||
true
|
|
||||||
;
|
|
||||||
throw(error(domain_error(bayesian_domain),bind_clpbns(var(Dist, Key, Type, Domain, Table, Parents),var(Dist1, Key1, Type1, Domain1, Table1, Parents1))))
|
|
||||||
).
|
|
||||||
bind_clpbns(Key, _, _, _, Key1, _, _, _) :-
|
bind_clpbns(Key, _, _, _, Key1, _, _, _) :-
|
||||||
Key\=Key1, !, fail.
|
Key\=Key1, !, fail.
|
||||||
bind_clpbns(_, _, _, _, _, _, _, _) :-
|
bind_clpbns(_, _, _, _, _, _, _, _) :-
|
||||||
@ -395,3 +400,5 @@ clpbn_run_solver(vel, LVs, LPs, State) :-
|
|||||||
clpbn_run_solver(jt, LVs, LPs, State) :-
|
clpbn_run_solver(jt, LVs, LPs, State) :-
|
||||||
run_jt_solver(LVs, LPs, State).
|
run_jt_solver(LVs, LPs, State).
|
||||||
|
|
||||||
|
add_keys(Key1+V1,_Key2,Key1+V1).
|
||||||
|
|
||||||
|
@ -24,10 +24,11 @@
|
|||||||
randomise_dist/1,
|
randomise_dist/1,
|
||||||
uniformise_all_dists/0,
|
uniformise_all_dists/0,
|
||||||
uniformise_dist/1,
|
uniformise_dist/1,
|
||||||
reset_all_dists/0
|
reset_all_dists/0,
|
||||||
|
additive_dists/6
|
||||||
]).
|
]).
|
||||||
|
|
||||||
:- use_module(library(lists),[is_list/1,nth0/3]).
|
:- use_module(library(lists),[is_list/1,nth0/3,append/3]).
|
||||||
|
|
||||||
:- use_module(library(matrix),
|
:- use_module(library(matrix),
|
||||||
[matrix_new/4,
|
[matrix_new/4,
|
||||||
@ -106,8 +107,10 @@ dist(V, Id, Key, Parents) :-
|
|||||||
var(Key), !,
|
var(Key), !,
|
||||||
when(Key, dist(V, Id, Key, Parents)).
|
when(Key, dist(V, Id, Key, Parents)).
|
||||||
dist(avg(Domain, Parents), avg(Domain), _, Parents).
|
dist(avg(Domain, Parents), avg(Domain), _, Parents).
|
||||||
|
dist(ip(Domain, Tabs, Parents), ip(Domain,Tabs), _, Parents).
|
||||||
dist(max(Domain, Parents), max(Domain), _, Parents).
|
dist(max(Domain, Parents), max(Domain), _, Parents).
|
||||||
dist(min(Domain, Parents), min(Domain), _, Parents).
|
dist(min(Domain, Parents), min(Domain), _, Parents).
|
||||||
|
dist(cons(Domain, Parent), cons(Domain), _, Parent).
|
||||||
dist(p(Type, CPT), Id, Key, FParents) :-
|
dist(p(Type, CPT), Id, Key, FParents) :-
|
||||||
copy_structure(Key, Key0),
|
copy_structure(Key, Key0),
|
||||||
distribution(Type, CPT, Id, Key0, [], FParents).
|
distribution(Type, CPT, Id, Key0, [], FParents).
|
||||||
@ -219,6 +222,8 @@ get_dist_params(Id, Parms) :-
|
|||||||
|
|
||||||
get_dist_domain_size(avg(D,_), DSize) :- !,
|
get_dist_domain_size(avg(D,_), DSize) :- !,
|
||||||
length(D, DSize).
|
length(D, DSize).
|
||||||
|
get_dist_domain_size(ip(D,_,_), DSize) :- !,
|
||||||
|
length(D, DSize).
|
||||||
get_dist_domain_size(Id, DSize) :-
|
get_dist_domain_size(Id, DSize) :-
|
||||||
recorded(clpbn_dist_db, db(Id, _, _, _, _, _, DSize), _).
|
recorded(clpbn_dist_db, db(Id, _, _, _, _, _, DSize), _).
|
||||||
|
|
||||||
@ -231,6 +236,8 @@ get_dist_key(Id, Key) :-
|
|||||||
get_dist_nparams(Id, NParms) :-
|
get_dist_nparams(Id, NParms) :-
|
||||||
recorded(clpbn_dist_db, db(Id, _, _, _, _, NParms, _), _).
|
recorded(clpbn_dist_db, db(Id, _, _, _, _, NParms, _), _).
|
||||||
|
|
||||||
|
get_evidence_position(El, ip(Domain,_,_), Pos) :- !,
|
||||||
|
nth0(Pos, Domain, El), !.
|
||||||
get_evidence_position(El, avg(Domain), Pos) :- !,
|
get_evidence_position(El, avg(Domain), Pos) :- !,
|
||||||
nth0(Pos, Domain, El), !.
|
nth0(Pos, Domain, El), !.
|
||||||
get_evidence_position(El, Id, Pos) :-
|
get_evidence_position(El, Id, Pos) :-
|
||||||
@ -267,6 +274,7 @@ dist_new_table(Id, NewMat) :-
|
|||||||
fail.
|
fail.
|
||||||
dist_new_table(_, _).
|
dist_new_table(_, _).
|
||||||
|
|
||||||
|
copy_structure(V, _) :- attvar(V), !.
|
||||||
copy_structure(V, V) :- var(V), !.
|
copy_structure(V, V) :- var(V), !.
|
||||||
copy_structure(V, _) :- primitive(V), !.
|
copy_structure(V, _) :- primitive(V), !.
|
||||||
copy_structure(Key, Key0) :-
|
copy_structure(Key, Key0) :-
|
||||||
@ -314,3 +322,6 @@ reset_all_dists :-
|
|||||||
reset_all_dists.
|
reset_all_dists.
|
||||||
|
|
||||||
|
|
||||||
|
additive_dists(ip(Domain,Tabs1), ip(Domain,Tabs2), Parents1, Parents2, ip(Domain,Tabs), Parents) :-
|
||||||
|
append(Tabs1, Tabs2, Tabs),
|
||||||
|
append(Parents1, Parents2, Parents).
|
||||||
|
@ -36,8 +36,7 @@ info_ouput(Stream, [V|Output]) :-
|
|||||||
|
|
||||||
|
|
||||||
output_parents(Stream, [V]) :- !,
|
output_parents(Stream, [V]) :- !,
|
||||||
clpbn:get_atts(V,[key(Key)]),
|
output_v(V,Stream).
|
||||||
output_key(Stream,Key).
|
|
||||||
output_parents(Stream, L) :-
|
output_parents(Stream, L) :-
|
||||||
format(Stream,'{ ',[]),
|
format(Stream,'{ ',[]),
|
||||||
output_parents1(Stream,L),
|
output_parents1(Stream,L),
|
||||||
@ -45,11 +44,13 @@ output_parents(Stream, L) :-
|
|||||||
|
|
||||||
output_parents1(_,[]).
|
output_parents1(_,[]).
|
||||||
output_parents1(Stream,[V|L]) :-
|
output_parents1(Stream,[V|L]) :-
|
||||||
clpbn:get_atts(V,[key(Key)]),
|
output_v(V,Stream),
|
||||||
output_key(Stream,Key),
|
put_code(Stream, 0' ), %'
|
||||||
put_code(Stream, 0' ),
|
|
||||||
output_parents1(Stream,L).
|
output_parents1(Stream,L).
|
||||||
|
|
||||||
|
output_v(V,Stream) :-
|
||||||
|
clpbn:get_atts(V,[key(Key)]),
|
||||||
|
output_key(Stream,Key).
|
||||||
|
|
||||||
output_key(Stream, Key) :-
|
output_key(Stream, Key) :-
|
||||||
output_key(Stream, 0, Key).
|
output_key(Stream, 0, Key).
|
||||||
@ -57,11 +58,8 @@ output_key(Stream, Key) :-
|
|||||||
output_key(Stream, _, Key) :-
|
output_key(Stream, _, Key) :-
|
||||||
primitive(Key), !,
|
primitive(Key), !,
|
||||||
write(Stream, Key).
|
write(Stream, Key).
|
||||||
output_key(Stream, I0, Key) :-
|
output_key(Stream, _, Key) :-
|
||||||
Key =.. [Name|Args],
|
format(Stream, '"~w"', [Key]).
|
||||||
write(Stream, Name),
|
|
||||||
I is I0+1,
|
|
||||||
output_key_args(Stream, I, Args).
|
|
||||||
|
|
||||||
output_key_args(_, _, []).
|
output_key_args(_, _, []).
|
||||||
output_key_args(Stream, I, [Arg|Args]) :-
|
output_key_args(Stream, I, [Arg|Args]) :-
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
:- module(clpbn_table,
|
:- module(clpbn_table,
|
||||||
[clpbn_table/1,
|
[clpbn_table/1,
|
||||||
|
clpbn_tableallargs/1,
|
||||||
|
clpbn_table_nondet/1,
|
||||||
clpbn_tabled_clause/2,
|
clpbn_tabled_clause/2,
|
||||||
clpbn_tabled_abolish/1,
|
clpbn_tabled_abolish/1,
|
||||||
clpbn_tabled_asserta/1,
|
clpbn_tabled_asserta/1,
|
||||||
@ -23,9 +25,9 @@
|
|||||||
]).
|
]).
|
||||||
|
|
||||||
:- use_module(library(bhash),
|
:- use_module(library(bhash),
|
||||||
[b_hash_new/2,
|
[b_hash_new/4,
|
||||||
b_hash_lookup/3,
|
b_hash_lookup/3,
|
||||||
b_hash_insert/3]).
|
b_hash_insert/4]).
|
||||||
|
|
||||||
:- meta_predicate clpbn_table(:),
|
:- meta_predicate clpbn_table(:),
|
||||||
clpbn_tabled_clause(:.?),
|
clpbn_tabled_clause(:.?),
|
||||||
@ -37,20 +39,43 @@
|
|||||||
clpbn_tabled_number_of_clauses(:,-),
|
clpbn_tabled_number_of_clauses(:,-),
|
||||||
clpbn_is_tabled(:).
|
clpbn_is_tabled(:).
|
||||||
|
|
||||||
|
:- use_module(library(terms), [
|
||||||
|
instantiated_term_hash/4,
|
||||||
|
variant/2
|
||||||
|
]).
|
||||||
|
|
||||||
:- dynamic clpbn_table/3.
|
:- dynamic clpbn_table/3.
|
||||||
|
|
||||||
|
:- meta_predicate clpbn_table(:), clpbn_table_all_args(:).
|
||||||
|
|
||||||
:- initialization(init).
|
:- initialization(init).
|
||||||
|
|
||||||
init :-
|
init :-
|
||||||
clpbn_reset_tables.
|
clpbn_reset_tables.
|
||||||
|
|
||||||
clpbn_reset_tables :-
|
clpbn_reset_tables :-
|
||||||
clpbn_reset_tables(1024).
|
clpbn_reset_tables(2048).
|
||||||
|
|
||||||
clpbn_reset_tables(Sz) :-
|
clpbn_reset_tables(Sz) :-
|
||||||
b_hash_new(Tab, Sz),
|
b_hash_new(Tab, Sz, myf, myc),
|
||||||
nb_setval(clpbn_tables, Tab).
|
nb_setval(clpbn_tables, Tab).
|
||||||
|
|
||||||
|
myf(Key, Size, Index) :-
|
||||||
|
instantiated_term_hash(Key, -1, Size, Index).
|
||||||
|
|
||||||
|
myc(A, B) :-
|
||||||
|
variant(A,B),
|
||||||
|
term_variables(A,L1),
|
||||||
|
term_variables(B,L2),
|
||||||
|
match_keys(L1,L2).
|
||||||
|
|
||||||
|
match_keys([],[]).
|
||||||
|
match_keys([V1|L1],[V2|L2]) :-
|
||||||
|
clpbn:get_atts(V1,[key(K)]),
|
||||||
|
clpbn:get_atts(V2,[key(K)]),
|
||||||
|
match_keys(L1,L2).
|
||||||
|
|
||||||
|
|
||||||
clpbn_table(M:X) :- !,
|
clpbn_table(M:X) :- !,
|
||||||
clpbn_table(X,M).
|
clpbn_table(X,M).
|
||||||
clpbn_table(X) :-
|
clpbn_table(X) :-
|
||||||
@ -65,7 +90,7 @@ clpbn_table((P1,P2),M) :- !,
|
|||||||
clpbn_table(F/N,M) :-
|
clpbn_table(F/N,M) :-
|
||||||
functor(S,F,N),
|
functor(S,F,N),
|
||||||
S =.. L0,
|
S =.. L0,
|
||||||
take_tail(L0, V, L1, V1, L2),
|
take_tail(L0, V, L1, V, L2),
|
||||||
Key =.. L1,
|
Key =.. L1,
|
||||||
atom_concat(F, '___tabled', NF),
|
atom_concat(F, '___tabled', NF),
|
||||||
L2 = [_|Args],
|
L2 = [_|Args],
|
||||||
@ -73,12 +98,83 @@ clpbn_table(F/N,M) :-
|
|||||||
L0 = [_|OArgs],
|
L0 = [_|OArgs],
|
||||||
S2 =.. [NF|OArgs],
|
S2 =.. [NF|OArgs],
|
||||||
asserta(clpbn_table(S, M, S2)),
|
asserta(clpbn_table(S, M, S2)),
|
||||||
assert((M:S :- nb_getval(clpbn_tables, Tab), ( b_hash_lookup(Key, V1, Tab) -> true ; M:S1, b_hash_insert(Tab, Key, V1) ; true), ( nonvar(V) -> clpbn_evidence:put_evidence(V, V1) ; V = V1 ), ! ) ).
|
assert(
|
||||||
|
(M:S :-
|
||||||
|
b_getval(clpbn_tables, Tab),
|
||||||
|
( b_hash_lookup(Key, V1, Tab) ->
|
||||||
|
V1=V
|
||||||
|
;
|
||||||
|
b_hash_insert(Tab, Key, V, NewTab),
|
||||||
|
b_setval(clpbn_tables,NewTab),
|
||||||
|
once(M:S2)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).
|
||||||
|
|
||||||
take_tail([V], V, [], V1, [V1]) :- !.
|
take_tail([V], V, [], V1, [V1]) :- !.
|
||||||
take_tail([A|L0], V, [A|L1], V1, [A|L2]) :-
|
take_tail([A|L0], V, [A|L1], V1, [A|L2]) :-
|
||||||
take_tail(L0, V, L1, V1, L2).
|
take_tail(L0, V, L1, V1, L2).
|
||||||
|
|
||||||
|
clpbn_tableallargs(M:X) :- !,
|
||||||
|
clpbn_tableallargs(X,M).
|
||||||
|
clpbn_tableallargs(X) :-
|
||||||
|
prolog_load_context(module, M),
|
||||||
|
clpbn_tableallargs(X,M).
|
||||||
|
|
||||||
|
clpbn_tableallargs(M:X,_) :- !,
|
||||||
|
clpbn_tableallargs(X,M).
|
||||||
|
clpbn_tableallargs((P1,P2),M) :- !,
|
||||||
|
clpbn_tableallargs(P1,M),
|
||||||
|
clpbn_tableallargs(P2,M).
|
||||||
|
clpbn_tableallargs(F/N,M) :-
|
||||||
|
functor(Key,F,N),
|
||||||
|
Key =.. [F|Args],
|
||||||
|
atom_concat(F, '___tabled', NF),
|
||||||
|
NKey =.. [NF|Args],
|
||||||
|
asserta(clpbn_table(Key, M, NKey)),
|
||||||
|
assert(
|
||||||
|
(M:Key :-
|
||||||
|
b_getval(clpbn_tables, Tab),
|
||||||
|
( b_hash_lookup(Key, Out, Tab) ->
|
||||||
|
true
|
||||||
|
;
|
||||||
|
b_hash_insert(Tab, Key, Out, NewTab),
|
||||||
|
b_setval(clpbn_tables, NewTab),
|
||||||
|
once(M:NKey)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).
|
||||||
|
|
||||||
|
clpbn_table_nondet(M:X) :- !,
|
||||||
|
clpbn_table_nondet(X,M).
|
||||||
|
clpbn_table_nondet(X) :-
|
||||||
|
prolog_load_context(module, M),
|
||||||
|
clpbn_table_nondet(X,M).
|
||||||
|
|
||||||
|
clpbn_table_nondet(M:X,_) :- !,
|
||||||
|
clpbn_table_nondet(X,M).
|
||||||
|
clpbn_table_nondet((P1,P2),M) :- !,
|
||||||
|
clpbn_table_nondet(P1,M),
|
||||||
|
clpbn_table_nondet(P2,M).
|
||||||
|
clpbn_table_nondet(F/N,M) :-
|
||||||
|
functor(Key,F,N),
|
||||||
|
Key =.. [F|Args],
|
||||||
|
atom_concat(F, '___tabled', NF),
|
||||||
|
NKey =.. [NF|Args],
|
||||||
|
asserta(clpbn_table(Key, M, NKey)),
|
||||||
|
assert(
|
||||||
|
(M:Key :- writeln(in:Key),
|
||||||
|
b_getval(clpbn_tables, Tab),
|
||||||
|
( b_hash_lookup(Key, Out, Tab) ->
|
||||||
|
fail
|
||||||
|
;
|
||||||
|
b_hash_insert(Tab, Key, Out, NewTab),
|
||||||
|
b_setval(clpbn_tables, NewTab),
|
||||||
|
M:NKey
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).
|
||||||
|
|
||||||
user:term_expansion((P :- Gs), NC) :-
|
user:term_expansion((P :- Gs), NC) :-
|
||||||
clpbn_table(P, M, NP),
|
clpbn_table(P, M, NP),
|
||||||
prolog_load_context(module, M), !,
|
prolog_load_context(module, M), !,
|
||||||
@ -86,11 +182,11 @@ user:term_expansion((P :- Gs), NC) :-
|
|||||||
NC = (:-true).
|
NC = (:-true).
|
||||||
|
|
||||||
in_table(K, V) :-
|
in_table(K, V) :-
|
||||||
nb_getval(clpbn_tables, Tab),
|
b_getval(clpbn_tables, Tab),
|
||||||
b_hash_lookup(K, V, Tab).
|
b_hash_lookup(K, V, Tab).
|
||||||
|
|
||||||
store_in_table(K, V) :-
|
store_in_table(K, V) :-
|
||||||
nb_getval(clpbn_tables, Tab),
|
b_getval(clpbn_tables, Tab),
|
||||||
b_hash_insert(Tab, K, V).
|
b_hash_insert(Tab, K, V).
|
||||||
|
|
||||||
clpbn_tabled_clause(M:Head, Body) :- !,
|
clpbn_tabled_clause(M:Head, Body) :- !,
|
||||||
|
@ -6,6 +6,7 @@ GCC=@GCC@
|
|||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
ROOTDIR = $(prefix)
|
ROOTDIR = $(prefix)
|
||||||
EROOTDIR = @exec_prefix@
|
EROOTDIR = @exec_prefix@
|
||||||
|
abs_top_builddir = @abs_top_builddir@
|
||||||
#
|
#
|
||||||
# where the binary should be
|
# where the binary should be
|
||||||
#
|
#
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
problog_max/3,
|
problog_max/3,
|
||||||
problog_exact/3,
|
problog_exact/3,
|
||||||
problog_montecarlo/3,
|
problog_montecarlo/3,
|
||||||
|
problog_table/1,
|
||||||
get_fact_probability/2,
|
get_fact_probability/2,
|
||||||
set_fact_probability/2,
|
set_fact_probability/2,
|
||||||
get_fact/2,
|
get_fact/2,
|
||||||
@ -65,7 +66,10 @@
|
|||||||
|
|
||||||
% op attaching probabilities to facts
|
% op attaching probabilities to facts
|
||||||
:- op( 550, yfx, :: ).
|
:- op( 550, yfx, :: ).
|
||||||
|
:- op( 1150, fx, problog_table ).
|
||||||
|
|
||||||
|
:- meta_predicate problog_table(:).
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
% control predicates on various levels
|
% control predicates on various levels
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
@ -99,6 +103,10 @@
|
|||||||
:- dynamic dynamic_probability_fact/1.
|
:- dynamic dynamic_probability_fact/1.
|
||||||
:- dynamic dynamic_probability_fact_extract/2.
|
:- dynamic dynamic_probability_fact_extract/2.
|
||||||
|
|
||||||
|
|
||||||
|
% keep a tab on tabling
|
||||||
|
:- dynamic problog_tabled/1.
|
||||||
|
|
||||||
% directory where ProblogBDD executable is located
|
% directory where ProblogBDD executable is located
|
||||||
% automatically set during loading -- assumes it is in same place as this file (problog.yap)
|
% automatically set during loading -- assumes it is in same place as this file (problog.yap)
|
||||||
%:- getcwd(PD),retractall(problog_dir(_)),assert(problog_dir(PD)).
|
%:- getcwd(PD),retractall(problog_dir(_)),assert(problog_dir(PD)).
|
||||||
@ -221,8 +229,9 @@ user:term_expansion(P::Goal, problog:ProbFact) :-
|
|||||||
append(Args,[LProb],L1),
|
append(Args,[LProb],L1),
|
||||||
probclause_id(ID),
|
probclause_id(ID),
|
||||||
ProbFact =.. [ProblogName,ID|L1],
|
ProbFact =.. [ProblogName,ID|L1],
|
||||||
|
assert_static(prob_for_id(ID,P)),
|
||||||
(
|
(
|
||||||
(\+ var(P), P = t(TrueProb))
|
(nonvar(P), P = t(TrueProb))
|
||||||
->
|
->
|
||||||
(
|
(
|
||||||
assert(tunable_fact(ID,TrueProb)),
|
assert(tunable_fact(ID,TrueProb)),
|
||||||
@ -257,7 +266,7 @@ user:term_expansion(P::Goal, problog:ProbFact) :-
|
|||||||
assert(non_ground_fact(ID))
|
assert(non_ground_fact(ID))
|
||||||
),
|
),
|
||||||
problog_predicate(Name, Arity, ProblogName).
|
problog_predicate(Name, Arity, ProblogName).
|
||||||
|
|
||||||
|
|
||||||
% introduce wrapper clause if predicate seen first time
|
% introduce wrapper clause if predicate seen first time
|
||||||
problog_predicate(Name, Arity, _) :-
|
problog_predicate(Name, Arity, _) :-
|
||||||
@ -269,7 +278,6 @@ problog_predicate(Name, Arity, ProblogName) :-
|
|||||||
append(Args,[Prob],L1),
|
append(Args,[Prob],L1),
|
||||||
ProbFact =.. [ProblogName,ID|L1],
|
ProbFact =.. [ProblogName,ID|L1],
|
||||||
prolog_load_context(module,Mod),
|
prolog_load_context(module,Mod),
|
||||||
|
|
||||||
assert( (Mod:OriginalGoal :- ProbFact,
|
assert( (Mod:OriginalGoal :- ProbFact,
|
||||||
(
|
(
|
||||||
non_ground_fact(ID)
|
non_ground_fact(ID)
|
||||||
@ -342,12 +350,15 @@ reset_non_ground_facts :-
|
|||||||
% cut choice points if ID is ground (they'll all fail as ID is unique),
|
% cut choice points if ID is ground (they'll all fail as ID is unique),
|
||||||
% but not if it isn't (used to iterate over all facts when writing out probabilities for learning)
|
% but not if it isn't (used to iterate over all facts when writing out probabilities for learning)
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
get_fact_probability(ID,Prob) :-
|
||||||
|
ground(ID), !,
|
||||||
|
prob_for_id(ID,Prob).
|
||||||
get_fact_probability(ID,Prob) :-
|
get_fact_probability(ID,Prob) :-
|
||||||
(
|
(
|
||||||
ground(ID) ->
|
ground(ID) ->
|
||||||
get_internal_fact(ID,ProblogTerm,_ProblogName,ProblogArity),!
|
get_internal_fact(ID,ProblogTerm,_ProblogName,ProblogArity),!
|
||||||
;
|
;
|
||||||
get_internal_fact(ID,ProblogTerm,_ProblogName,ProblogArity)
|
get_internal_fact(ID,ProblogTerm,_ProblogName,ProblogArity)
|
||||||
),
|
),
|
||||||
arg(ProblogArity,ProblogTerm,Log),
|
arg(ProblogArity,ProblogTerm,Log),
|
||||||
Prob is exp(Log).
|
Prob is exp(Log).
|
||||||
@ -1131,6 +1142,8 @@ mc_prove(A) :- !,
|
|||||||
|
|
||||||
clean_sample :-
|
clean_sample :-
|
||||||
reset_static_array(mc_sample),
|
reset_static_array(mc_sample),
|
||||||
|
problog_tabled(P),
|
||||||
|
abolish_table(P),
|
||||||
fail.
|
fail.
|
||||||
clean_sample.
|
clean_sample.
|
||||||
|
|
||||||
@ -1142,3 +1155,18 @@ get_some_proof(Goal) :-
|
|||||||
(Used == [] -> Proof=true; reverse(Used,Proof)),
|
(Used == [] -> Proof=true; reverse(Used,Proof)),
|
||||||
insert_ptree(Proof,1).
|
insert_ptree(Proof,1).
|
||||||
|
|
||||||
|
problog_table(M:P) :- !,
|
||||||
|
problog_table(P,M).
|
||||||
|
problog_table(P) :-
|
||||||
|
prolog_load_context(module,M),
|
||||||
|
problog_table(P,M).
|
||||||
|
|
||||||
|
problog_table(M:P,_) :-
|
||||||
|
problog_table(P,M).
|
||||||
|
problog_table((P1,P2),M) :-
|
||||||
|
problog_table(P1,M),
|
||||||
|
problog_table(P2,M).
|
||||||
|
problog_table(P,M) :-
|
||||||
|
table(M:P),
|
||||||
|
assert(problog_tabled(M:P)).
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
ROOTDIR = $(prefix)
|
ROOTDIR = $(prefix)
|
||||||
EROOTDIR = @exec_prefix@
|
EROOTDIR = @exec_prefix@
|
||||||
|
abs_top_builddir = @abs_top_builddir@
|
||||||
#
|
#
|
||||||
# where the binary should be
|
# where the binary should be
|
||||||
#
|
#
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit cba31e06301d475e572a2f377061c7b5014b4254
|
Subproject commit e071f01c1d9015e6d3fabc73092a6e902541485a
|
@ -1 +1 @@
|
|||||||
Subproject commit 3cda12359a93d7d9e337cc564b7bfacf40fc8cb5
|
Subproject commit e3ee70d5971a5af8c9a2a3a5fe8a1892c3777f2b
|
@ -1 +1 @@
|
|||||||
Subproject commit 8843002483df3078583ca8495630a1b864a7999f
|
Subproject commit eb6d27251c2548c25e6d37fff2a27a014caaa7aa
|
@ -11,6 +11,7 @@ ifeq (@PROLOG_SYSTEM@,yap)
|
|||||||
prefix = @prefix@
|
prefix = @prefix@
|
||||||
ROOTDIR = $(prefix)
|
ROOTDIR = $(prefix)
|
||||||
EROOTDIR = @exec_prefix@
|
EROOTDIR = @exec_prefix@
|
||||||
|
abs_top_builddir = @abs_top_builddir@
|
||||||
|
|
||||||
srcdir=@srcdir@
|
srcdir=@srcdir@
|
||||||
|
|
||||||
@ -20,7 +21,7 @@ YAPLIBDIR=$(EROOTDIR)/lib/Yap
|
|||||||
SHAREDIR=$(ROOTDIR)/share/Yap
|
SHAREDIR=$(ROOTDIR)/share/Yap
|
||||||
|
|
||||||
SHELL=@SHELL@
|
SHELL=@SHELL@
|
||||||
PL=@EXTEND_DYNLOADER_PATH@ $(DESTDIR)$(BINDIR)/yap $(DESTDIR)$(YAPLIBDIR)/startup
|
PL=@EXTEND_DYNLOADER_PATH@ $(DESTDIR)$(BINDIR)/yap $(DESTDIR)$(YAPLIBDIR)/startup.yss
|
||||||
CHRDIR=$(SHAREDIR)/chr
|
CHRDIR=$(SHAREDIR)/chr
|
||||||
EXDIR=$(CHRDIR)/examples/chr
|
EXDIR=$(CHRDIR)/examples/chr
|
||||||
LN_S=@LN_S@
|
LN_S=@LN_S@
|
||||||
|
Reference in New Issue
Block a user