minor updates
This commit is contained in:
parent
dacf6b4e57
commit
bb5d02dbc0
@ -58,7 +58,6 @@
|
|||||||
|
|
||||||
|
|
||||||
call_bp_ground(QueryVars, QueryKeys, AllKeys, Factors, Evidence, Output) :-
|
call_bp_ground(QueryVars, QueryKeys, AllKeys, Factors, Evidence, Output) :-
|
||||||
writeln(here:Factors),
|
|
||||||
b_hash_new(Hash0),
|
b_hash_new(Hash0),
|
||||||
keys_to_ids(AllKeys, 0, Hash0, Hash),
|
keys_to_ids(AllKeys, 0, Hash0, Hash),
|
||||||
get_factors_type(Factors, Type),
|
get_factors_type(Factors, Type),
|
||||||
@ -66,21 +65,17 @@ writeln(here:Factors),
|
|||||||
factors_to_ids(Factors, Hash, FactorIds),
|
factors_to_ids(Factors, Hash, FactorIds),
|
||||||
%writeln(type:Type), writeln(''),
|
%writeln(type:Type), writeln(''),
|
||||||
%writeln(allKeys:AllKeys), writeln(''),
|
%writeln(allKeys:AllKeys), writeln(''),
|
||||||
|
%sort(AllKeys,SKeys),writeln(allKeys:SKeys), writeln(''),
|
||||||
%writeln(factors:Factors), writeln(''),
|
%writeln(factors:Factors), writeln(''),
|
||||||
%writeln(factorIds:FactorIds), writeln(''),
|
%writeln(factorIds:FactorIds), writeln(''),
|
||||||
%writeln(evidence:Evidence), writeln(''),
|
%writeln(evidence:Evidence), writeln(''),
|
||||||
%writeln(evidenceIds:EvidenceIds), writeln(''),
|
%writeln(evidenceIds:EvidenceIds), writeln(''),
|
||||||
create_ground_network(Type, FactorIds, EvidenceIds, Network),
|
create_ground_network(Type, FactorIds, EvidenceIds, Network),
|
||||||
%get_vars_information(AllKeys, StatesNames),
|
%get_vars_information(AllKeys, StatesNames),
|
||||||
%set_vars_information(AllKeys, StatesNames),
|
%terms_to_atoms(AllKeys, KeysAtoms),
|
||||||
|
%set_vars_information(KeysAtoms, StatesNames),
|
||||||
run_solver(ground(Network,Hash), QueryKeys, Solutions),
|
run_solver(ground(Network,Hash), QueryKeys, Solutions),
|
||||||
<<<<<<< HEAD
|
|
||||||
%writeln(answer:Solutions),
|
|
||||||
%clpbn_bind_vals([QueryKeys], Solutions, Output).
|
|
||||||
=======
|
|
||||||
writeln(answer:Solutions),
|
|
||||||
clpbn_bind_vals([QueryVars], Solutions, Output),
|
clpbn_bind_vals([QueryVars], Solutions, Output),
|
||||||
>>>>>>> 5a8cc421d2ea7a8135f84d935752e5ecb453fe99
|
|
||||||
free_ground_network(Network).
|
free_ground_network(Network).
|
||||||
|
|
||||||
|
|
||||||
@ -137,6 +132,12 @@ get_vars_information(Key.QueryKeys, Domain.StatesNames) :-
|
|||||||
get_vars_information(QueryKeys, StatesNames).
|
get_vars_information(QueryKeys, StatesNames).
|
||||||
|
|
||||||
|
|
||||||
|
terms_to_atoms([], []).
|
||||||
|
terms_to_atoms(K.Ks, Atom.As) :-
|
||||||
|
term_to_atom(K,Atom),
|
||||||
|
terms_to_atoms(Ks,As).
|
||||||
|
|
||||||
|
|
||||||
finalize_bp_solver(bp(Network, _)) :-
|
finalize_bp_solver(bp(Network, _)) :-
|
||||||
free_ground_network(Network).
|
free_ground_network(Network).
|
||||||
|
|
||||||
@ -150,7 +151,7 @@ bp([QueryVars], AllVars, Output) :-
|
|||||||
|
|
||||||
|
|
||||||
init_bp_solver(_, AllVars0, _, bp(BayesNet, DistIds)) :-
|
init_bp_solver(_, AllVars0, _, bp(BayesNet, DistIds)) :-
|
||||||
%check_for_agg_vars(AllVars0, AllVars),
|
%check_for_agg_vars(AllVars0, AllVars),
|
||||||
get_vars_info(AllVars0, VarsInfo, DistIds0),
|
get_vars_info(AllVars0, VarsInfo, DistIds0),
|
||||||
sort(DistIds0, DistIds),
|
sort(DistIds0, DistIds),
|
||||||
create_ground_network(VarsInfo, BayesNet),
|
create_ground_network(VarsInfo, BayesNet),
|
||||||
|
@ -23,7 +23,7 @@ class DAGraphNode : public Var
|
|||||||
|
|
||||||
const vector<DAGraphNode*>& childs (void) const { return childs_; }
|
const vector<DAGraphNode*>& childs (void) const { return childs_; }
|
||||||
|
|
||||||
vector<DAGraphNode*>& childs (void) { return childs_; }
|
vector<DAGraphNode*>& childs (void) { return childs_; }
|
||||||
|
|
||||||
const vector<DAGraphNode*>& parents (void) const { return parents_; }
|
const vector<DAGraphNode*>& parents (void) const { return parents_; }
|
||||||
|
|
||||||
|
@ -52,6 +52,11 @@ class ElimGraph
|
|||||||
elimHeuristic_ = h;
|
elimHeuristic_ = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ElimHeuristic getEliminationHeuristic (void)
|
||||||
|
{
|
||||||
|
return elimHeuristic_;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void addEdge (EgNode* n1, EgNode* n2)
|
void addEdge (EgNode* n1, EgNode* n2)
|
||||||
|
@ -65,10 +65,10 @@ int createLiftedNetwork (void)
|
|||||||
|
|
||||||
// LiftedUtils::printSymbolDictionary();
|
// LiftedUtils::printSymbolDictionary();
|
||||||
if (Constants::DEBUG > 2) {
|
if (Constants::DEBUG > 2) {
|
||||||
// Util::printHeader ("INITIAL PARFACTORS");
|
Util::printHeader ("INITIAL PARFACTORS");
|
||||||
// for (unsigned i = 0; i < parfactors.size(); i++) {
|
for (unsigned i = 0; i < parfactors.size(); i++) {
|
||||||
// parfactors[i]->print();
|
parfactors[i]->print();
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ParfactorList* pfList = new ParfactorList (parfactors);
|
ParfactorList* pfList = new ParfactorList (parfactors);
|
||||||
@ -243,7 +243,6 @@ createGroundNetwork (void)
|
|||||||
fg->getVarNode (vid)->setEvidence (ev);
|
fg->getVarNode (vid)->setEvidence (ev);
|
||||||
evidenceList = YAP_TailOfTerm (evidenceList);
|
evidenceList = YAP_TailOfTerm (evidenceList);
|
||||||
}
|
}
|
||||||
|
|
||||||
YAP_Int p = (YAP_Int) (fg);
|
YAP_Int p = (YAP_Int) (fg);
|
||||||
return YAP_Unify (YAP_MkIntTerm (p), YAP_ARG4);
|
return YAP_Unify (YAP_MkIntTerm (p), YAP_ARG4);
|
||||||
}
|
}
|
||||||
@ -332,7 +331,6 @@ int
|
|||||||
runGroundSolver (void)
|
runGroundSolver (void)
|
||||||
{
|
{
|
||||||
FactorGraph* fg = (FactorGraph*) YAP_IntOfTerm (YAP_ARG1);
|
FactorGraph* fg = (FactorGraph*) YAP_IntOfTerm (YAP_ARG1);
|
||||||
|
|
||||||
vector<VarIds> tasks;
|
vector<VarIds> tasks;
|
||||||
YAP_Term taskList = YAP_ARG2;
|
YAP_Term taskList = YAP_ARG2;
|
||||||
while (taskList != YAP_TermNil()) {
|
while (taskList != YAP_TermNil()) {
|
||||||
@ -376,7 +374,9 @@ void runVeSolver (
|
|||||||
if (fg->isFromBayesNetwork()) {
|
if (fg->isFromBayesNetwork()) {
|
||||||
mfg = BayesBall::getMinimalFactorGraph (*fg, tasks[i]);
|
mfg = BayesBall::getMinimalFactorGraph (*fg, tasks[i]);
|
||||||
}
|
}
|
||||||
VarElimSolver solver (*mfg);
|
// VarElimSolver solver (*mfg);
|
||||||
|
VarElimSolver solver (*fg); //FIXME
|
||||||
|
// solver.printSolverFlags();
|
||||||
results.push_back (solver.solveQuery (tasks[i]));
|
results.push_back (solver.solveQuery (tasks[i]));
|
||||||
if (fg->isFromBayesNetwork()) {
|
if (fg->isFromBayesNetwork()) {
|
||||||
delete mfg;
|
delete mfg;
|
||||||
@ -410,6 +410,7 @@ void runBpSolver (
|
|||||||
cerr << "error: unknow solver" << endl;
|
cerr << "error: unknow solver" << endl;
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
// solver->printSolverFlags();
|
||||||
results.reserve (tasks.size());
|
results.reserve (tasks.size());
|
||||||
for (unsigned i = 0; i < tasks.size(); i++) {
|
for (unsigned i = 0; i < tasks.size(); i++) {
|
||||||
results.push_back (solver->solveQuery (tasks[i]));
|
results.push_back (solver->solveQuery (tasks[i]));
|
||||||
@ -476,8 +477,8 @@ int
|
|||||||
setVarsInformation (void)
|
setVarsInformation (void)
|
||||||
{
|
{
|
||||||
Var::clearVarsInfo();
|
Var::clearVarsInfo();
|
||||||
YAP_Term labelsL = YAP_ARG1;
|
|
||||||
vector<string> labels;
|
vector<string> labels;
|
||||||
|
YAP_Term labelsL = YAP_ARG1;
|
||||||
while (labelsL != YAP_TermNil()) {
|
while (labelsL != YAP_TermNil()) {
|
||||||
YAP_Atom atom = YAP_AtomOfTerm (YAP_HeadOfTerm (labelsL));
|
YAP_Atom atom = YAP_AtomOfTerm (YAP_HeadOfTerm (labelsL));
|
||||||
labels.push_back ((char*) YAP_AtomName (atom));
|
labels.push_back ((char*) YAP_AtomName (atom));
|
||||||
@ -564,12 +565,12 @@ setHorusFlag (void)
|
|||||||
cerr << "for `" << key << "'" << endl;
|
cerr << "for `" << key << "'" << endl;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
} else if (key == "order_factor_variables") {
|
} else if (key == "order_variables") {
|
||||||
string value ((char*) YAP_AtomName (YAP_AtomOfTerm (YAP_ARG2)));
|
string value ((char*) YAP_AtomName (YAP_AtomOfTerm (YAP_ARG2)));
|
||||||
if ( value == "true") {
|
if ( value == "true") {
|
||||||
FactorGraph::orderFactorVariables = true;
|
FactorGraph::orderVariables = true;
|
||||||
} else if (value == "false") {
|
} else if (value == "false") {
|
||||||
FactorGraph::orderFactorVariables = false;
|
FactorGraph::orderVariables = false;
|
||||||
} else {
|
} else {
|
||||||
cerr << "warning: invalid value `" << value << "' " ;
|
cerr << "warning: invalid value `" << value << "' " ;
|
||||||
cerr << "for `" << key << "'" << endl;
|
cerr << "for `" << key << "'" << endl;
|
||||||
|
@ -27,10 +27,13 @@
|
|||||||
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.
|
||||||
|
|
||||||
|
|
||||||
set_solver(ve) :- set_pfl_flag(solver,ve).
|
set_solver(ve) :- set_pfl_flag(solver,ve).
|
||||||
@ -56,8 +59,8 @@ set_solver(S) :- throw(error('unknow solver ', S)).
|
|||||||
|
|
||||||
:- set_horus_flag(max_iter, 1000).
|
:- set_horus_flag(max_iter, 1000).
|
||||||
|
|
||||||
:- set_horus_flag(order_factor_variables, false).
|
:- set_horus_flag(order_variables, false).
|
||||||
%:- set_horus_flag(order_factor_variables, true).
|
%:- set_horus_flag(order_variables, true).
|
||||||
|
|
||||||
:- set_horus_flag(use_logarithms, false).
|
:- set_horus_flag(use_logarithms, false).
|
||||||
% :- set_horus_flag(use_logarithms, true).
|
% :- set_horus_flag(use_logarithms, true).
|
||||||
|
Reference in New Issue
Block a user