first steps in adapting horus ground solvers to pfl
This commit is contained in:
parent
2bdec8f725
commit
6c3add2ebd
@ -10,7 +10,7 @@
|
|||||||
check_if_bp_done/1,
|
check_if_bp_done/1,
|
||||||
init_bp_solver/4,
|
init_bp_solver/4,
|
||||||
run_bp_solver/3,
|
run_bp_solver/3,
|
||||||
call_bp_ground/5,
|
call_bp_ground/5,
|
||||||
finalize_bp_solver/1
|
finalize_bp_solver/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
@ -31,30 +31,21 @@
|
|||||||
[check_for_agg_vars/2]).
|
[check_for_agg_vars/2]).
|
||||||
|
|
||||||
|
|
||||||
|
:- use_module(library(charsio),
|
||||||
|
[term_to_atom/2]).
|
||||||
|
|
||||||
|
|
||||||
|
:- use_module(library(pfl),
|
||||||
|
[skolem/2,
|
||||||
|
get_pfl_parameters/2
|
||||||
|
]).
|
||||||
|
|
||||||
:- use_module(library(clpbn/horus)).
|
:- use_module(library(clpbn/horus)).
|
||||||
|
|
||||||
:- use_module(library(lists)).
|
:- use_module(library(lists)).
|
||||||
|
|
||||||
:- use_module(library(atts)).
|
:- use_module(library(atts)).
|
||||||
|
|
||||||
:- attribute id/1.
|
|
||||||
|
|
||||||
|
|
||||||
%:- set_horus_flag(inf_alg, ve).
|
|
||||||
:- set_horus_flag(inf_alg, bn_bp).
|
|
||||||
%:- set_horus_flag(inf_alg, fg_bp).
|
|
||||||
%: -set_horus_flag(inf_alg, cbp).
|
|
||||||
|
|
||||||
:- set_horus_flag(schedule, seq_fixed).
|
|
||||||
%:- set_horus_flag(schedule, seq_random).
|
|
||||||
%:- set_horus_flag(schedule, parallel).
|
|
||||||
%:- set_horus_flag(schedule, max_residual).
|
|
||||||
|
|
||||||
:- set_horus_flag(accuracy, 0.0001).
|
|
||||||
|
|
||||||
:- use_module(library(charsio),
|
|
||||||
[term_to_atom/2]).
|
|
||||||
|
|
||||||
:- use_module(library(bhash)).
|
:- use_module(library(bhash)).
|
||||||
|
|
||||||
|
|
||||||
@ -63,48 +54,77 @@
|
|||||||
set_bayes_net_params/2,
|
set_bayes_net_params/2,
|
||||||
run_ground_solver/3,
|
run_ground_solver/3,
|
||||||
set_extra_vars_info/2,
|
set_extra_vars_info/2,
|
||||||
free_bayesian_network/1
|
free_ground_network/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
|
||||||
:- attribute id/1.
|
|
||||||
|
|
||||||
call_bp_ground(QueryKeys, AllKeys, Factors, Evidence, Solutions) :-
|
call_bp_ground(QueryKeys, AllKeys, Factors, Evidence, Solutions) :-
|
||||||
b_hash_new(Hash0),
|
b_hash_new(Hash0),
|
||||||
keys_to_ids(AllKeys, 0, Hash0, Hash),
|
keys_to_ids(AllKeys, 0, Hash0, Hash),
|
||||||
InvMap =.. [view|AllKeys],
|
%InvMap =.. [view|AllKeys],
|
||||||
list_of_keys_to_ids(QueryKeys, Hash, QueryVarsIds),
|
list_of_keys_to_ids(QueryKeys, Hash, QueryIds),
|
||||||
evidence_to_ids(Evidence, Hash, EvIds, EvIdNames),
|
evidence_to_ids(Evidence, Hash, EvIds),
|
||||||
factors_to_ids(Factors, Hash, FactorIds),
|
factors_to_ids(Factors, Hash, FactorIds),
|
||||||
init_graphical_model(FactorIds, Network, InvMap, EvIdNames),
|
get_factors_type(Factors, Type),
|
||||||
run_ground_solver(Network, QueryVarsIds, EvIds, Solutions),
|
writeln(type:Type), writeln(''),
|
||||||
free_graphical_model(Network).
|
writeln(allKeys:AllKeys), writeln(''),
|
||||||
|
%writeln(allKeysIds:Hash), writeln(''),
|
||||||
|
writeln(queryKeys:QueryKeys), writeln(''),
|
||||||
|
writeln(queryIds:QueryIds), writeln(''),
|
||||||
|
writeln(factors:Factors), writeln(''),
|
||||||
|
writeln(factorIds:FactorIds), writeln(''),
|
||||||
|
writeln(evidence:Evidence), writeln(''),
|
||||||
|
writeln(evIds:EvIds),
|
||||||
|
create_ground_network(Type, FactorIds, GroundNetwork).
|
||||||
|
%run_ground_solver(Network, QueryIds, EvIds, Solutions),
|
||||||
|
%free_graphical_model(Network).
|
||||||
|
|
||||||
|
|
||||||
|
get_factors_type([f(bayes, _, _)|_], bayes) :- ! .
|
||||||
|
get_factors_type([f(markov, _, _)|_], markov) :- ! .
|
||||||
|
|
||||||
|
|
||||||
keys_to_ids([], _, Hash, Hash).
|
keys_to_ids([], _, Hash, Hash).
|
||||||
keys_to_ids([Key|AllKeys], I0, Hash0, Hash) :-
|
keys_to_ids([Key|AllKeys], I0, Hash0, Hash) :-
|
||||||
b_hash_insert(Hash0, Key, I0, HashI),
|
b_hash_insert(Hash0, Key, I0, HashI),
|
||||||
I is I0+1,
|
I is I0+1,
|
||||||
keys_to_ids(AllKeys, I, HashI, Hash).
|
keys_to_ids(AllKeys, I, HashI, Hash).
|
||||||
|
|
||||||
|
|
||||||
list_of_keys_to_ids([], _, []).
|
list_of_keys_to_ids([], _, []).
|
||||||
list_of_keys_to_ids([Key|QueryKeys], Hash, [Id|QueryIds]) :-
|
list_of_keys_to_ids([Key|QueryKeys], Hash, [Id|QueryIds]) :-
|
||||||
b_hash_lookup(Key, Id, Hash),
|
b_hash_lookup(Key, Id, Hash),
|
||||||
list_of_keys_to_ids(QueryKeys, Hash, QueryIds).
|
list_of_keys_to_ids(QueryKeys, Hash, QueryIds).
|
||||||
|
|
||||||
|
|
||||||
|
evidence_to_ids([], _, []).
|
||||||
|
evidence_to_ids([Key=Ev|QueryKeys], Hash, [Id=Ev|QueryIds]) :-
|
||||||
|
b_hash_lookup(Key, Id, Hash),
|
||||||
|
evidence_to_ids(QueryKeys, Hash, QueryIds).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%evidence_to_ids([], _, [], []).
|
||||||
|
%evidence_to_ids([Key=V|QueryKeys], Hash, [Id=V|QueryIds], [Id=Name|QueryNames]) :-
|
||||||
|
% b_hash_lookup(Key, Id, Hash),
|
||||||
|
% pfl:skolem(Key,Dom),
|
||||||
|
% nth0(V, Dom, Name),
|
||||||
|
% evidence_to_ids(QueryKeys, Hash, QueryIds, QueryNames).
|
||||||
|
|
||||||
evidence_to_ids([], _, [], []).
|
|
||||||
evidence_to_ids([Key=V|QueryKeys], Hash, [Id=V|QueryIds], [Id=Name|QueryNames]) :-
|
|
||||||
b_hash_lookup(Key, Id, Hash),
|
|
||||||
pfl:skolem(Key,Dom),
|
|
||||||
nth0(V, Dom, Name),
|
|
||||||
evidence_to_ids(QueryKeys, Hash, QueryIds, QueryNames).
|
|
||||||
|
|
||||||
factors_to_ids([], _, []).
|
factors_to_ids([], _, []).
|
||||||
factors_to_ids([f(markov, Keys, CPT)|Fs], Hash, [markov(Ids, CPT)|NFs]) :-
|
factors_to_ids([f(_, Keys, CPT)|Fs], Hash, [f(Ids, Ranges, CPT, DistId)|NFs]) :-
|
||||||
list_of_keys_to_ids(Keys, Hash, Ids),
|
list_of_keys_to_ids(Keys, Hash, Ids),
|
||||||
factors_to_ids(Fs, Hash, NFs).
|
DistId = 0,
|
||||||
factors_to_ids([f(bayes, Keys, CPT)|Fs], Hash, [bayes(Ids, CPT)|NFs]) :-
|
get_ranges(Keys, Ranges),
|
||||||
list_of_keys_to_ids(Keys, Hash, Ids),
|
factors_to_ids(Fs, Hash, NFs).
|
||||||
factors_to_ids(Fs, Hash, NFs).
|
|
||||||
|
|
||||||
|
get_ranges([],[]).
|
||||||
|
get_ranges(K.Ks, Range.Rs) :- !,
|
||||||
|
skolem(K,Domain),
|
||||||
|
length(Domain,Range),
|
||||||
|
get_ranges(Ks, Rs).
|
||||||
|
|
||||||
|
|
||||||
bp([[]],_,_) :- !.
|
bp([[]],_,_) :- !.
|
||||||
@ -117,9 +137,8 @@ bp([QueryVars], AllVars, Output) :-
|
|||||||
|
|
||||||
init_bp_solver(_, AllVars0, _, bp(BayesNet, DistIds)) :-
|
init_bp_solver(_, AllVars0, _, bp(BayesNet, DistIds)) :-
|
||||||
%writeln('init_bp_solver'),
|
%writeln('init_bp_solver'),
|
||||||
check_for_agg_vars(AllVars0, AllVars),
|
%check_for_agg_vars(AllVars0, AllVars),
|
||||||
%writeln('clpbn_vars:'), print_clpbn_vars(AllVars),
|
%writeln('clpbn_vars:'), print_clpbn_vars(AllVars),
|
||||||
assign_ids(AllVars, 0),
|
|
||||||
get_vars_info(AllVars, VarsInfo, DistIds0),
|
get_vars_info(AllVars, VarsInfo, DistIds0),
|
||||||
sort(DistIds0, DistIds),
|
sort(DistIds0, DistIds),
|
||||||
create_ground_network(VarsInfo, BayesNet),
|
create_ground_network(VarsInfo, BayesNet),
|
||||||
@ -138,41 +157,7 @@ run_bp_solver(QueryVars, Solutions, bp(Network, DistIds)) :-
|
|||||||
|
|
||||||
|
|
||||||
finalize_bp_solver(bp(Network, _)) :-
|
finalize_bp_solver(bp(Network, _)) :-
|
||||||
free_bayesian_network(Network).
|
free_ground_network(Network).
|
||||||
|
|
||||||
|
|
||||||
assign_ids([], _).
|
|
||||||
assign_ids([V|Vs], Count) :-
|
|
||||||
put_atts(V, [id(Count)]),
|
|
||||||
Count1 is Count + 1,
|
|
||||||
assign_ids(Vs, Count1).
|
|
||||||
|
|
||||||
|
|
||||||
get_vars_info([], [], []).
|
|
||||||
get_vars_info(V.Vs,
|
|
||||||
var(VarId,DS,Ev,PIds,DistId).VarsInfo,
|
|
||||||
DistId.DistIds) :-
|
|
||||||
clpbn:get_atts(V, [dist(DistId, Parents)]), !,
|
|
||||||
get_atts(V, [id(VarId)]),
|
|
||||||
get_dist_domain_size(DistId, DS),
|
|
||||||
get_evidence(V, Ev),
|
|
||||||
vars_to_ids(Parents, PIds),
|
|
||||||
get_vars_info(Vs, VarsInfo, DistIds).
|
|
||||||
|
|
||||||
|
|
||||||
get_evidence(V, Ev) :-
|
|
||||||
clpbn:get_atts(V, [evidence(Ev)]), !.
|
|
||||||
get_evidence(_V, -1). % no evidence !!!
|
|
||||||
|
|
||||||
|
|
||||||
vars_to_ids([], []).
|
|
||||||
vars_to_ids([L|Vars], [LIds|Ids]) :-
|
|
||||||
is_list(L), !,
|
|
||||||
vars_to_ids(L, LIds),
|
|
||||||
vars_to_ids(Vars, Ids).
|
|
||||||
vars_to_ids([V|Vars], [VarId|Ids]) :-
|
|
||||||
get_atts(V, [id(VarId)]),
|
|
||||||
vars_to_ids(Vars, Ids).
|
|
||||||
|
|
||||||
|
|
||||||
get_extra_vars_info([], []).
|
get_extra_vars_info([], []).
|
||||||
@ -201,17 +186,3 @@ numbers_to_atoms([Number|L0], [Atom|L]) :-
|
|||||||
number_atom(Number, Atom),
|
number_atom(Number, Atom),
|
||||||
numbers_to_atoms(L0, L).
|
numbers_to_atoms(L0, L).
|
||||||
|
|
||||||
|
|
||||||
print_clpbn_vars(Var.AllVars) :-
|
|
||||||
clpbn:get_atts(Var, [key(Key),dist(DistId,Parents)]),
|
|
||||||
parents_to_keys(Parents, ParentKeys),
|
|
||||||
writeln(Var:Key:ParentKeys:DistId),
|
|
||||||
print_clpbn_vars(AllVars).
|
|
||||||
print_clpbn_vars([]).
|
|
||||||
|
|
||||||
|
|
||||||
parents_to_keys([], []).
|
|
||||||
parents_to_keys(Var.Parents, Key.Keys) :-
|
|
||||||
clpbn:get_atts(Var, [key(Key)]),
|
|
||||||
parents_to_keys(Parents, Keys).
|
|
||||||
|
|
||||||
|
@ -78,12 +78,13 @@ Factor::Factor (
|
|||||||
Factor::Factor (
|
Factor::Factor (
|
||||||
const VarIds& vids,
|
const VarIds& vids,
|
||||||
const Ranges& ranges,
|
const Ranges& ranges,
|
||||||
const Params& params)
|
const Params& params,
|
||||||
|
unsigned distId)
|
||||||
{
|
{
|
||||||
args_ = vids;
|
args_ = vids;
|
||||||
ranges_ = ranges;
|
ranges_ = ranges;
|
||||||
params_ = params;
|
params_ = params;
|
||||||
distId_ = Util::maxUnsigned();
|
distId_ = distId;
|
||||||
assert (params_.size() == Util::expectedSize (ranges_));
|
assert (params_.size() == Util::expectedSize (ranges_));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +267,8 @@ class Factor : public TFactor<VarId>
|
|||||||
Factor (const VarNodes&, const Params&,
|
Factor (const VarNodes&, const Params&,
|
||||||
unsigned = Util::maxUnsigned());
|
unsigned = Util::maxUnsigned());
|
||||||
|
|
||||||
Factor (const VarIds&, const Ranges&, const Params&);
|
Factor (const VarIds&, const Ranges&, const Params&,
|
||||||
|
unsigned = Util::maxUnsigned());
|
||||||
|
|
||||||
void sumOutAllExcept (VarId);
|
void sumOutAllExcept (VarId);
|
||||||
|
|
||||||
|
@ -24,11 +24,28 @@ using namespace std;
|
|||||||
typedef std::pair<ParfactorList*, ObservedFormulas*> LiftedNetwork;
|
typedef std::pair<ParfactorList*, ObservedFormulas*> LiftedNetwork;
|
||||||
|
|
||||||
|
|
||||||
Params readParams (YAP_Term);
|
Params readParameters (YAP_Term);
|
||||||
|
|
||||||
|
vector<unsigned> readUnsignedList (YAP_Term);
|
||||||
|
|
||||||
void readLiftedEvidence (YAP_Term, ObservedFormulas&);
|
void readLiftedEvidence (YAP_Term, ObservedFormulas&);
|
||||||
|
|
||||||
Parfactor* readParfactor (YAP_Term);
|
Parfactor* readParfactor (YAP_Term);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
vector<unsigned>
|
||||||
|
readUnsignedList (YAP_Term list)
|
||||||
|
{
|
||||||
|
vector<unsigned> vec;
|
||||||
|
while (list != YAP_TermNil()) {
|
||||||
|
vec.push_back ((unsigned) YAP_IntOfTerm (YAP_HeadOfTerm (list)));
|
||||||
|
list = YAP_TailOfTerm (list);
|
||||||
|
}
|
||||||
|
return vec;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int createLiftedNetwork (void)
|
int createLiftedNetwork (void)
|
||||||
{
|
{
|
||||||
Parfactors parfactors;
|
Parfactors parfactors;
|
||||||
@ -117,7 +134,7 @@ Parfactor* readParfactor (YAP_Term pfTerm)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// read the parameters
|
// read the parameters
|
||||||
const Params& params = readParams (YAP_ArgOfTerm (4, pfTerm));
|
const Params& params = readParameters (YAP_ArgOfTerm (4, pfTerm));
|
||||||
|
|
||||||
// read the constraint
|
// read the constraint
|
||||||
Tuples tuples;
|
Tuples tuples;
|
||||||
@ -202,7 +219,27 @@ createGroundNetwork (void)
|
|||||||
// Statistics::writeStatisticsToFile ("../../compressing.stats");
|
// Statistics::writeStatisticsToFile ("../../compressing.stats");
|
||||||
// }
|
// }
|
||||||
BayesNet* bn = new BayesNet();
|
BayesNet* bn = new BayesNet();
|
||||||
YAP_Term varList = YAP_ARG1;
|
|
||||||
|
string factorsType ((char*) YAP_AtomName (YAP_AtomOfTerm (YAP_ARG1)));
|
||||||
|
cout << "factors type: '" << factorsType << "'" << endl;
|
||||||
|
|
||||||
|
YAP_Term factorList = YAP_ARG2;
|
||||||
|
while (factorList != YAP_TermNil()) {
|
||||||
|
YAP_Term factor = YAP_HeadOfTerm (factorList);
|
||||||
|
// read the var ids
|
||||||
|
VarIds varIds = readUnsignedList (YAP_ArgOfTerm (1, factor));
|
||||||
|
// read the ranges
|
||||||
|
Ranges ranges = readUnsignedList (YAP_ArgOfTerm (2, factor));
|
||||||
|
// read the parameters
|
||||||
|
Params params = readParameters (YAP_ArgOfTerm (3, factor));
|
||||||
|
// read dist id
|
||||||
|
unsigned distId = (unsigned) YAP_IntOfTerm (YAP_ArgOfTerm (4, factor));
|
||||||
|
factorList = YAP_TailOfTerm (factorList);
|
||||||
|
Factor f (varIds, ranges, params, distId);
|
||||||
|
f.print();
|
||||||
|
}
|
||||||
|
assert (false);
|
||||||
|
/*
|
||||||
vector<VarIds> parents;
|
vector<VarIds> parents;
|
||||||
while (varList != YAP_TermNil()) {
|
while (varList != YAP_TermNil()) {
|
||||||
YAP_Term var = YAP_HeadOfTerm (varList);
|
YAP_Term var = YAP_HeadOfTerm (varList);
|
||||||
@ -233,6 +270,7 @@ createGroundNetwork (void)
|
|||||||
nodes[i]->setParents (ps);
|
nodes[i]->setParents (ps);
|
||||||
}
|
}
|
||||||
bn->setIndexes();
|
bn->setIndexes();
|
||||||
|
*/
|
||||||
YAP_Int p = (YAP_Int) (bn);
|
YAP_Int p = (YAP_Int) (bn);
|
||||||
return YAP_Unify (YAP_MkIntTerm (p), YAP_ARG2);
|
return YAP_Unify (YAP_MkIntTerm (p), YAP_ARG2);
|
||||||
}
|
}
|
||||||
@ -240,7 +278,7 @@ createGroundNetwork (void)
|
|||||||
|
|
||||||
|
|
||||||
Params
|
Params
|
||||||
readParams (YAP_Term paramL)
|
readParameters (YAP_Term paramL)
|
||||||
{
|
{
|
||||||
Params params;
|
Params params;
|
||||||
while (paramL!= YAP_TermNil()) {
|
while (paramL!= YAP_TermNil()) {
|
||||||
@ -412,7 +450,7 @@ setParfactorsParams (void)
|
|||||||
YAP_Term dist = YAP_HeadOfTerm (distList);
|
YAP_Term dist = YAP_HeadOfTerm (distList);
|
||||||
unsigned distId = (unsigned) YAP_IntOfTerm (YAP_ArgOfTerm (1, dist));
|
unsigned distId = (unsigned) YAP_IntOfTerm (YAP_ArgOfTerm (1, dist));
|
||||||
assert (Util::contains (paramsMap, distId) == false);
|
assert (Util::contains (paramsMap, distId) == false);
|
||||||
paramsMap[distId] = readParams (YAP_ArgOfTerm (2, dist));
|
paramsMap[distId] = readParameters (YAP_ArgOfTerm (2, dist));
|
||||||
distList = YAP_TailOfTerm (distList);
|
distList = YAP_TailOfTerm (distList);
|
||||||
}
|
}
|
||||||
ParfactorList::iterator it = pfList->begin();
|
ParfactorList::iterator it = pfList->begin();
|
||||||
@ -436,7 +474,7 @@ setBayesNetParams (void)
|
|||||||
YAP_Term dist = YAP_HeadOfTerm (distList);
|
YAP_Term dist = YAP_HeadOfTerm (distList);
|
||||||
unsigned distId = (unsigned) YAP_IntOfTerm (YAP_ArgOfTerm (1, dist));
|
unsigned distId = (unsigned) YAP_IntOfTerm (YAP_ArgOfTerm (1, dist));
|
||||||
assert (Util::contains (paramsMap, distId) == false);
|
assert (Util::contains (paramsMap, distId) == false);
|
||||||
paramsMap[distId] = readParams (YAP_ArgOfTerm (2, dist));
|
paramsMap[distId] = readParameters (YAP_ArgOfTerm (2, dist));
|
||||||
distList = YAP_TailOfTerm (distList);
|
distList = YAP_TailOfTerm (distList);
|
||||||
}
|
}
|
||||||
const BnNodeSet& nodes = bn->getBayesNodes();
|
const BnNodeSet& nodes = bn->getBayesNodes();
|
||||||
@ -559,7 +597,7 @@ setHorusFlag (void)
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
freeBayesNetwork (void)
|
freeGroundNetwork (void)
|
||||||
{
|
{
|
||||||
delete (BayesNet*) YAP_IntOfTerm (YAP_ARG1);
|
delete (BayesNet*) YAP_IntOfTerm (YAP_ARG1);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -583,7 +621,7 @@ extern "C" void
|
|||||||
init_predicates (void)
|
init_predicates (void)
|
||||||
{
|
{
|
||||||
YAP_UserCPredicate ("create_lifted_network", createLiftedNetwork, 3);
|
YAP_UserCPredicate ("create_lifted_network", createLiftedNetwork, 3);
|
||||||
YAP_UserCPredicate ("create_ground_network", createGroundNetwork, 2);
|
YAP_UserCPredicate ("create_ground_network", createGroundNetwork, 3);
|
||||||
YAP_UserCPredicate ("run_lifted_solver", runLiftedSolver, 3);
|
YAP_UserCPredicate ("run_lifted_solver", runLiftedSolver, 3);
|
||||||
YAP_UserCPredicate ("run_ground_solver", runGroundSolver, 3);
|
YAP_UserCPredicate ("run_ground_solver", runGroundSolver, 3);
|
||||||
YAP_UserCPredicate ("set_parfactors_params", setParfactorsParams, 2);
|
YAP_UserCPredicate ("set_parfactors_params", setParfactorsParams, 2);
|
||||||
@ -591,6 +629,6 @@ init_predicates (void)
|
|||||||
YAP_UserCPredicate ("set_extra_vars_info", setExtraVarsInfo, 2);
|
YAP_UserCPredicate ("set_extra_vars_info", setExtraVarsInfo, 2);
|
||||||
YAP_UserCPredicate ("set_horus_flag", setHorusFlag, 2);
|
YAP_UserCPredicate ("set_horus_flag", setHorusFlag, 2);
|
||||||
YAP_UserCPredicate ("free_parfactors", freeParfactors, 1);
|
YAP_UserCPredicate ("free_parfactors", freeParfactors, 1);
|
||||||
YAP_UserCPredicate ("free_bayesian_network", freeBayesNetwork, 1);
|
YAP_UserCPredicate ("free_ground_network", freeGroundNetwork, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -570,6 +570,7 @@ Parfactor::print (bool printParams) const
|
|||||||
cout << " = " << params_[i] << endl;
|
cout << " = " << params_[i] << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cout << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,18 +15,20 @@ friendly(P1, P2) :-
|
|||||||
person(john).
|
person(john).
|
||||||
person(maggie).
|
person(maggie).
|
||||||
person(harry).
|
person(harry).
|
||||||
person(bill).
|
%person(bill).
|
||||||
person(matt).
|
%person(matt).
|
||||||
person(diana).
|
%person(diana).
|
||||||
person(bob).
|
%person(bob).
|
||||||
person(dick).
|
%person(dick).
|
||||||
person(burr).
|
%person(burr).
|
||||||
person(ann).
|
%person(ann).
|
||||||
|
|
||||||
person @ 2.
|
% person @ 2.
|
||||||
|
|
||||||
markov smokes(P)::[t,f] , cancer(P)::[t,f] ; [0.1, 0.2, 0.3, 0.4] ; [person(P)].
|
markov smokes(P)::[t,f] , cancer(P)::[t,f] ; [0.1, 0.2, 0.3, 0.4] ; [person(P)].
|
||||||
|
|
||||||
markov friend(P1,P2)::[t,f], smokes(P1)::[t,f], smokes(P2)::[t,f] ; [0.5, 0.6, 0.7, 0.8] ; [friendly(P1, P2)].
|
markov friend(P1,P2)::[t,f], smokes(P1)::[t,f], smokes(P2)::[t,f] ; [0.5, 0.6, 0.7, 0.8, 0.5, 0.6, 0.7, 0.8] ; [friendly(P1, P2)].
|
||||||
|
|
||||||
?- smokes(person_0, t), smokes(person_1, t), friend(person_0, person_1, F).
|
% ?- smokes(person_0, t), smokes(person_1, t), friend(person_0, person_1, F).
|
||||||
|
|
||||||
|
?- smokes(john, t), smokes(maggie, f), friend(john, maggie, X).
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
:- module(clpbn_horus,
|
:- module(clpbn_horus,
|
||||||
[create_lifted_network/3,
|
[create_lifted_network/3,
|
||||||
create_ground_network/2,
|
create_ground_network/3,
|
||||||
set_parfactors_params/2,
|
set_parfactors_params/2,
|
||||||
set_bayes_net_params/2,
|
set_bayes_net_params/2,
|
||||||
run_lifted_solver/3,
|
run_lifted_solver/3,
|
||||||
@ -15,15 +15,15 @@
|
|||||||
set_extra_vars_info/2,
|
set_extra_vars_info/2,
|
||||||
set_horus_flag/2,
|
set_horus_flag/2,
|
||||||
free_parfactors/1,
|
free_parfactors/1,
|
||||||
free_bayesian_network/1
|
free_ground_network/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
|
||||||
patch_things_up :-
|
patch_things_up :-
|
||||||
assert_static(clpbn_horus:set_horus_flag(_,_)).
|
assert_static(clpbn_horus:set_horus_flag(_,_)).
|
||||||
|
|
||||||
warning :-
|
warning :-
|
||||||
format(user_error,"Horus library not installed: cannot use bp, fove~n.",[]).
|
format(user_error,"Horus library not installed: cannot use bp, fove~n.",[]).
|
||||||
|
|
||||||
:- catch(load_foreign_files([horus], [], init_predicates), _, patch_things_up) -> true ; warning.
|
:- catch(load_foreign_files([horus], [], init_predicates), _, patch_things_up) -> true ; warning.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user