31 #ifndef DOXYGEN_SHOULD_SKIP_THIS 47 template <
typename GUM_SCALAR >
49 const IBayesNet< GUM_SCALAR >* BN,
52 JointTargetedInference< GUM_SCALAR >(BN) {
66 template <
typename GUM_SCALAR >
79 template <
typename GUM_SCALAR >
81 const Triangulation& new_triangulation) {
88 template <
typename GUM_SCALAR >
98 template <
typename GUM_SCALAR >
100 Potential< GUM_SCALAR >* (*proj)(
const Potential< GUM_SCALAR >&,
101 const Set< const DiscreteVariable* >&)) {
107 template <
typename GUM_SCALAR >
109 Potential< GUM_SCALAR >* (*comb)(
const Potential< GUM_SCALAR >&,
110 const Potential< GUM_SCALAR >&)) {
116 template <
typename GUM_SCALAR >
143 "setRelevantPotentialsFinderType for type " 144 << (
unsigned int)type <<
" is not implemented yet");
153 template <
typename GUM_SCALAR >
166 "setFindBarrenNodesType for type " 167 << (
unsigned int)type <<
" is not implemented yet");
176 template <
typename GUM_SCALAR >
182 template <
typename GUM_SCALAR >
188 template <
typename GUM_SCALAR >
193 template <
typename GUM_SCALAR >
199 template <
typename GUM_SCALAR >
205 template <
typename GUM_SCALAR >
210 template <
typename GUM_SCALAR >
212 const IBayesNet< GUM_SCALAR >* bn) {}
215 template <
typename GUM_SCALAR >
221 template <
typename GUM_SCALAR >
227 template <
typename GUM_SCALAR >
232 template <
typename GUM_SCALAR >
237 template <
typename GUM_SCALAR >
242 template <
typename GUM_SCALAR >
247 template <
typename GUM_SCALAR >
264 const auto& bn = this->
BN();
266 for (
auto node : bn.dag())
277 if (targets.size() != bn.size()) {
278 BarrenNodesFinder finder(&(bn.dag()));
279 finder.setTargets(&targets);
282 for (
const auto& pair : this->
evidence()) {
283 evidence_nodes.
insert(pair.first);
285 finder.setEvidence(&evidence_nodes);
287 NodeSet barren_nodes = finder.barrenNodes();
290 for (
const auto node : barren_nodes) {
300 bool dsep_analysis =
false;
309 dsep_analysis =
true;
314 dsep.requisiteNodes(bn.dag(),
319 dsep_analysis =
true;
324 default:
GUM_ERROR(FatalError,
"not implemented yet");
330 if (!requisite_nodes.contains(*iter)
339 for (
const auto node :
__graph) {
340 const NodeSet& parents = bn.parents(node);
341 for (
auto iter1 = parents.cbegin(); iter1 != parents.cend(); ++iter1) {
346 if (__graph.existsNode(*iter1)) __graph.addEdge(*iter1, node);
349 for (++iter2; iter2 != parents.cend(); ++iter2) {
354 if (__graph.existsNode(*iter1) && __graph.existsNode(*iter2))
355 __graph.addEdge(*iter1, *iter2);
363 for (
auto iter1 = targets.cbegin(); iter1 != targets.cend(); ++iter1) {
365 for (++iter2; iter2 != targets.cend(); ++iter2) {
366 __graph.addEdge(*iter1, *iter2);
372 __graph.eraseNode(node);
380 __JT =
new CliqueGraph(triang_jt);
387 for (
auto clique : *
__JT)
389 const std::vector< NodeId >& JT_elim_order =
391 NodeProperty< Size > elim_order(
Size(JT_elim_order.size()));
392 for (std::size_t i = std::size_t(0), size = JT_elim_order.size(); i < size;
394 elim_order.insert(JT_elim_order[i],
NodeId(i));
395 const DAG& dag = bn.dag();
396 for (
const auto node : __graph) {
398 NodeId first_eliminated_node = node;
399 Size elim_number = elim_order[first_eliminated_node];
401 for (
const auto parent : dag.parents(node)) {
402 if (__graph.existsNode(parent) && (elim_order[parent] < elim_number)) {
403 elim_number = elim_order[parent];
404 first_eliminated_node = parent;
423 NodeSet pars(dag.parents(node).size());
424 for (
const auto par : dag.parents(node))
425 if (__graph.exists(par)) pars.
insert(par);
428 NodeId first_eliminated_node = *(pars.begin());
429 Size elim_number = elim_order[first_eliminated_node];
431 for (
const auto parent : pars) {
432 if (elim_order[parent] < elim_number) {
433 elim_number = elim_order[parent];
434 first_eliminated_node = parent;
457 if (nodeset.contains(node)) nodeset.
erase(node);
459 if (!nodeset.empty()) {
460 NodeId first_eliminated_node = *(nodeset.begin());
461 Size elim_number = elim_order[first_eliminated_node];
462 for (
const auto node : nodeset) {
463 if (elim_order[node] < elim_number) {
464 elim_number = elim_order[node];
465 first_eliminated_node = node;
476 template <
typename GUM_SCALAR >
482 template <
typename GUM_SCALAR >
487 template <
typename GUM_SCALAR >
489 Set<
const Potential< GUM_SCALAR >* >& pot_list,
490 Set< const DiscreteVariable* >& kept_vars) {}
494 template <
typename GUM_SCALAR >
496 Set<
const Potential< GUM_SCALAR >* >& pot_list,
497 Set< const DiscreteVariable* >& kept_vars) {
500 const auto& bn = this->
BN();
501 for (
const auto var : kept_vars) {
502 kept_ids.insert(bn.nodeId(*var));
512 for (
auto iter = pot_list.beginSafe(); iter != pot_list.endSafe(); ++iter) {
513 const Sequence< const DiscreteVariable* >& vars =
514 (**iter).variablesSequence();
516 for (
auto var : vars) {
517 if (requisite_nodes.exists(bn.nodeId(*var))) {
523 if (!found) { pot_list.erase(iter); }
529 template <
typename GUM_SCALAR >
531 Set<
const Potential< GUM_SCALAR >* >& pot_list,
532 Set< const DiscreteVariable* >& kept_vars) {
535 const auto& bn = this->
BN();
536 for (
const auto var : kept_vars) {
537 kept_ids.insert(bn.nodeId(*var));
550 template <
typename GUM_SCALAR >
552 Set<
const Potential< GUM_SCALAR >* >& pot_list,
553 Set< const DiscreteVariable* >& kept_vars) {
556 const auto& bn = this->
BN();
557 for (
const auto var : kept_vars) {
558 kept_ids.insert(bn.nodeId(*var));
563 dsep.relevantPotentials(bn,
572 template <
typename GUM_SCALAR >
574 Set<
const Potential< GUM_SCALAR >* >& pot_list,
575 Set< const DiscreteVariable* >& kept_vars) {
593 default:
GUM_ERROR(FatalError,
"not implemented yet");
599 template <
typename GUM_SCALAR >
600 Set< const Potential< GUM_SCALAR >* >
602 __PotentialSet& pot_list, Set< const DiscreteVariable* >& del_vars) {
605 Set< const DiscreteVariable* > the_del_vars = del_vars;
606 for (
auto iter = the_del_vars.beginSafe(); iter != the_del_vars.endSafe();
608 NodeId id = this->
BN().nodeId(**iter);
611 the_del_vars.erase(iter);
616 HashTable< const DiscreteVariable*, __PotentialSet > var2pots;
618 for (
const auto pot : pot_list) {
619 const Sequence< const DiscreteVariable* >& vars = pot->variablesSequence();
620 for (
const auto var : vars) {
621 if (the_del_vars.exists(var)) {
622 if (!var2pots.exists(var)) { var2pots.insert(var, empty_pot_set); }
623 var2pots[var].insert(pot);
630 HashTable< const Potential< GUM_SCALAR >*, Set< const DiscreteVariable* > >
632 Set< const DiscreteVariable* > empty_var_set;
633 for (
auto elt : var2pots) {
634 if (elt.second.size() == 1) {
635 const Potential< GUM_SCALAR >* pot = *(elt.second.begin());
636 if (!pot2barren_var.exists(pot)) {
637 pot2barren_var.insert(pot, empty_var_set);
639 pot2barren_var[pot].insert(elt.first);
648 for (
auto elt : pot2barren_var) {
651 const Potential< GUM_SCALAR >* pot = elt.first;
656 if (pot->variablesSequence().size() != elt.second.size()) {
657 auto new_pot = projector.project(*pot, elt.second);
658 pot_list.insert(new_pot);
659 projected_pots.insert(new_pot);
663 return projected_pots;
668 template <
typename GUM_SCALAR >
669 std::pair< Set< const Potential< GUM_SCALAR >* >,
670 Set< const Potential< GUM_SCALAR >* > >
673 std::pair< __PotentialSet, __PotentialSet > collect_messages;
674 for (
const auto other : __JT->neighbours(
id)) {
676 std::pair< __PotentialSet, __PotentialSet > message(
678 collect_messages.first += message.first;
679 collect_messages.second += message.second;
689 template <
typename GUM_SCALAR >
690 std::pair< Set< const Potential< GUM_SCALAR >* >,
691 Set< const Potential< GUM_SCALAR >* > >
693 std::pair< __PotentialSet, __PotentialSet > res;
694 const auto& bn = this->
BN();
708 const Potential< GUM_SCALAR >& cpt = bn.cpt(node);
709 const auto& variables = cpt.variablesSequence();
715 for (
const auto var : variables) {
716 NodeId xnode = bn.nodeId(*var);
718 && !__graph.existsNode(xnode))
725 for (
const auto var : variables) {
726 NodeId xnode = bn.nodeId(*var);
733 if (hard_nodes.empty()) {
734 res.first.insert(&cpt);
739 if (hard_nodes.size() != variables.size()) {
741 Set< const DiscreteVariable* > hard_variables;
743 for (
const auto xnode : hard_nodes) {
744 marg_cpt_set.insert(
evidence[xnode]);
745 hard_variables.insert(&(bn.variable(xnode)));
748 MultiDimCombineAndProjectDefault< GUM_SCALAR, Potential >
751 combine_and_project.combineAndProject(marg_cpt_set, hard_variables);
754 if (new_cpt_list.size() != 1) {
756 for (
auto pot : new_cpt_list) {
757 if (!marg_cpt_set.contains(pot))
delete pot;
760 "the projection of a potential containing " 761 <<
"hard evidence is empty!");
763 const Potential< GUM_SCALAR >* projected_cpt = *(new_cpt_list.begin());
764 res.first.insert(projected_cpt);
765 res.second.insert(projected_cpt);
770 if (
evidence.exists(node) && !hard_evidence.exists(node)) {
771 res.first.insert(this->
evidence()[node]);
780 template <
typename GUM_SCALAR >
781 std::pair< Set< const Potential< GUM_SCALAR >* >,
782 Set< const Potential< GUM_SCALAR >* > >
786 std::pair< Set<
const Potential< GUM_SCALAR >* >,
787 Set<
const Potential< GUM_SCALAR >* > >&& incoming_messages) {
789 std::pair< Set< const Potential< GUM_SCALAR >* >,
790 Set< const Potential< GUM_SCALAR >* > >
791 pot_list(std::move(incoming_messages));
796 pot_list.first += new_pots.first;
797 pot_list.second += new_pots.second;
801 if (!__JT->existsEdge(from_id, to_id)) {
805 const NodeSet& from_clique = __JT->clique(from_id);
806 const NodeSet& separator = __JT->separator(from_id, to_id);
807 Set< const DiscreteVariable* > del_vars(from_clique.size());
808 Set< const DiscreteVariable* > kept_vars(separator.size());
809 const auto& bn = this->
BN();
811 for (
const auto node : from_clique) {
812 if (!separator.contains(node)) {
813 del_vars.insert(&(bn.variable(node)));
815 kept_vars.insert(&(bn.variable(node)));
826 for (
auto iter = new_pot_list.beginSafe(); iter != new_pot_list.endSafe();
828 const auto pot = *iter;
829 if (pot->variablesSequence().size() == 1) {
830 bool is_all_ones =
true;
831 for (Instantiation inst(*pot); !inst.end(); ++inst) {
838 if (!pot_list.first.exists(pot))
delete pot;
839 new_pot_list.erase(iter);
846 for (
auto iter = pot_list.second.beginSafe();
847 iter != pot_list.second.endSafe();
849 if (!new_pot_list.contains(*iter)) {
851 pot_list.second.erase(iter);
856 for (
const auto pot : new_pot_list) {
857 if (!pot_list.first.contains(pot)) { pot_list.second.insert(pot); }
861 return std::pair< __PotentialSet, __PotentialSet >(
862 std::move(new_pot_list), std::move(pot_list.second));
868 template <
typename GUM_SCALAR >
869 Set< const Potential< GUM_SCALAR >* >
871 Set<
const Potential< GUM_SCALAR >* > pot_list,
872 Set< const DiscreteVariable* >& del_vars,
873 Set< const DiscreteVariable* >& kept_vars) {
886 MultiDimCombineAndProjectDefault< GUM_SCALAR, Potential > combine_and_project(
889 combine_and_project.combineAndProject(pot_list, del_vars);
894 for (
auto iter = barren_projected_potentials.beginSafe();
895 iter != barren_projected_potentials.endSafe();
897 if (!new_pot_list.exists(*iter))
delete *iter;
901 for (
auto iter_pot = new_pot_list.beginSafe();
902 iter_pot != new_pot_list.endSafe();
904 if ((*iter_pot)->variablesSequence().size() == 0) {
911 new_pot_list.erase(iter_pot);
920 template <
typename GUM_SCALAR >
925 template <
typename GUM_SCALAR >
926 Potential< GUM_SCALAR >*
928 const auto& bn = this->
BN();
933 return new Potential< GUM_SCALAR >(*(this->
evidence()[id]));
942 const NodeSet& nodes = __JT->clique(clique_of_id);
943 Set< const DiscreteVariable* > kept_vars{&(bn.variable(
id))};
944 Set< const DiscreteVariable* > del_vars(nodes.size());
945 for (
const auto node : nodes) {
946 if (node !=
id) del_vars.
insert(&(bn.variable(node)));
953 Potential< GUM_SCALAR >* joint =
nullptr;
955 if (new_pot_list.size() == 1) {
956 joint =
const_cast< Potential< GUM_SCALAR >*
>(*(new_pot_list.begin()));
959 if (pot_list.first.exists(joint)) {
960 joint =
new Potential< GUM_SCALAR >(*joint);
964 new_pot_list.clear();
967 MultiDimCombinationDefault< GUM_SCALAR, Potential > fast_combination(
969 joint = fast_combination.combine(new_pot_list);
973 for (
auto pot : new_pot_list)
974 if (!pot_list.first.exists(pot))
delete pot;
977 for (
auto pot : pot_list.second)
983 bool nonzero_found =
false;
984 for (Instantiation inst(*joint); !inst.end(); ++inst) {
985 if ((*joint)[inst]) {
986 nonzero_found =
true;
990 if (!nonzero_found) {
994 "some evidence entered into the Bayes " 995 "net are incompatible (their joint proba = 0)");
1003 template <
typename GUM_SCALAR >
1004 const Potential< GUM_SCALAR >&
1018 template <
typename GUM_SCALAR >
1019 Potential< GUM_SCALAR >*
1024 NodeSet targets =
set, hard_ev_nodes;
1026 if (targets.contains(node)) {
1027 targets.
erase(node);
1028 hard_ev_nodes.insert(node);
1035 if (targets.empty()) {
1037 for (
const auto node :
set) {
1040 if (pot_list.size() == 1) {
1041 return new Potential< GUM_SCALAR >(**(pot_list.begin()));
1043 MultiDimCombinationDefault< GUM_SCALAR, Potential > fast_combination(
1045 return fast_combination.combine(pot_list);
1055 Set< const DiscreteVariable* > del_vars(nodes.size());
1056 Set< const DiscreteVariable* > kept_vars(targets.size());
1057 const auto& bn = this->
BN();
1058 for (
const auto node : nodes) {
1059 if (!targets.contains(node)) {
1060 del_vars.insert(&(bn.variable(node)));
1062 kept_vars.insert(&(bn.variable(node)));
1070 Potential< GUM_SCALAR >* joint =
nullptr;
1072 if ((new_pot_list.size() == 1) && hard_ev_nodes.empty()) {
1073 joint =
const_cast< Potential< GUM_SCALAR >*
>(*(new_pot_list.begin()));
1076 if (pot_list.first.exists(joint)) {
1077 joint =
new Potential< GUM_SCALAR >(*joint);
1081 new_pot_list.clear();
1087 for (
const auto node : hard_ev_nodes) {
1088 new_new_pot_list.insert(
evidence[node]);
1090 MultiDimCombinationDefault< GUM_SCALAR, Potential > fast_combination(
1092 joint = fast_combination.combine(new_new_pot_list);
1096 for (
auto pot : new_pot_list)
1097 if (!pot_list.first.exists(pot))
delete pot;
1100 for (
auto pot : pot_list.second)
1105 bool nonzero_found =
false;
1106 for (Instantiation inst(*joint); !inst.end(); ++inst) {
1107 if ((*joint)[inst]) {
1108 nonzero_found =
true;
1112 if (!nonzero_found) {
1116 "some evidence entered into the Bayes " 1117 "net are incompatible (their joint proba = 0)");
1125 template <
typename GUM_SCALAR >
1126 const Potential< GUM_SCALAR >&
1140 template <
typename GUM_SCALAR >
1141 const Potential< GUM_SCALAR >&
1150 #endif // DOXYGEN_SHOULD_SKIP_THIS void __setProjectionFunction(Potential< GUM_SCALAR > *(*proj)(const Potential< GUM_SCALAR > &, const Set< const DiscreteVariable * > &))
sets the operator for performing the projections
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
NodeId __targets2clique
indicate a clique that contains all the nodes of the target
VariableElimination(const IBayesNet< GUM_SCALAR > *BN, RelevantPotentialsFinderType relevant_type=RelevantPotentialsFinderType::DSEP_BAYESBALL_POTENTIALS, FindBarrenNodesType=FindBarrenNodesType::FIND_BARREN_NODES)
default constructor
void _onAllTargetsErased() final
fired before a all single and joint_targets are removed
__PotentialSet __removeBarrenVariables(__PotentialSet &pot_list, Set< const DiscreteVariable * > &del_vars)
virtual void clear()
removes all the nodes and edges from the graph
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
const NodeProperty< const Potential< GUM_SCALAR > *> & evidence() const
returns the set of evidence
static INLINE Potential< GUM_SCALAR > * VENewprojPotential(const Potential< GUM_SCALAR > &t1, const Set< const DiscreteVariable * > &del_vars)
void __setCombinationFunction(Potential< GUM_SCALAR > *(*comb)(const Potential< GUM_SCALAR > &, const Potential< GUM_SCALAR > &))
sets the operator for performing the combinations
node_iterator_safe beginSafe() const
a begin iterator to parse the set of nodes contained in the NodeGraphPart
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const Potential< GUM_SCALAR > & _posterior(NodeId id) final
returns the posterior of a given variable
JunctionTree * __JT
the junction tree used to answer the last inference query
RelevantPotentialsFinderType __find_relevant_potential_type
the type of relevant potential finding algorithm to be used
void __findRelevantPotentialsXX(__PotentialSet &pot_list, Set< const DiscreteVariable * > &kept_vars)
update a set of potentials: the remaining are those to be combined to produce a message on a separato...
void setFindBarrenNodesType(FindBarrenNodesType type)
sets how we determine barren nodes
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
static void relevantPotentials(const IBayesNet< GUM_SCALAR > &bn, const NodeSet &query, const NodeSet &hardEvidence, const NodeSet &softEvidence, Set< const TABLE< GUM_SCALAR > * > &potentials)
update a set of potentials, keeping only those d-connected with query variables given evidence ...
void _onEvidenceErased(const NodeId id, bool isHardEvidence) final
fired before an evidence is removed
std::pair< __PotentialSet, __PotentialSet > __collectMessage(NodeId id, NodeId from)
actually perform the collect phase
Set< const Potential< GUM_SCALAR > *> __PotentialSet
void _makeInference() final
called when the inference has to be performed effectively
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Potential< GUM_SCALAR > * __target_posterior
the posterior computed during the last inference
Triangulation * __triangulation
the triangulation class creating the junction tree used for inference
void _updateOutdatedBNPotentials() final
prepares inference when the latter is in OutdatedBNPotentials state
void erase(const Key &k)
Erases an element from the set.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
const Potential< GUM_SCALAR > & _jointPosterior(const NodeSet &set) final
returns the posterior of a declared target set
void __findRelevantPotentialsGetAll(__PotentialSet &pot_list, Set< const DiscreteVariable * > &kept_vars)
update a set of potentials: the remaining are those to be combined to produce a message on a separato...
void __findRelevantPotentialsWithdSeparation(__PotentialSet &pot_list, Set< const DiscreteVariable * > &kept_vars)
update a set of potentials: the remaining are those to be combined to produce a message on a separato...
RelevantPotentialsFinderType
type of algorithm for determining the relevant potentials for combinations using some d-separation an...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
const JunctionTree * junctionTree(NodeId id)
returns the join tree used for compute the posterior of node id
void _onMarginalTargetErased(const NodeId id) final
fired before a single target is removed
void _onAllMarginalTargetsErased() final
fired before a all the single targets are removed
void __findRelevantPotentialsWithdSeparation3(__PotentialSet &pot_list, Set< const DiscreteVariable * > &kept_vars)
update a set of potentials: the remaining are those to be combined to produce a message on a separato...
virtual void eraseNode(const NodeId id)
remove a node and its adjacent edges from the graph
Potential< GUM_SCALAR > *(* __combination_op)(const Potential< GUM_SCALAR > &, const Potential< GUM_SCALAR > &)
the operator for performing the combinations
FindBarrenNodesType
type of algorithm to determine barren nodes
UndiGraph __graph
the undigraph extracted from the BN and used to construct the join tree
const NodeSet & softEvidenceNodes() const
returns the set of nodes with soft evidence
virtual const NodeProperty< Size > & domainSizes() const final
get the domain sizes of the random variables of the BN
void _onAllEvidenceErased(bool contains_hard_evidence) final
fired before all the evidence are erased
void __findRelevantPotentialsWithdSeparation2(__PotentialSet &pot_list, Set< const DiscreteVariable * > &kept_vars)
update a set of potentials: the remaining are those to be combined to produce a message on a separato...
virtual NodeId createdJunctionTreeClique(const NodeId id)=0
returns the Id of the clique created by the elimination of a given node during the triangulation proc...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
const NodeProperty< Idx > & hardEvidence() const
indicate for each node with hard evidence which value it took
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
HashTable< NodeId, NodeSet > __clique_potentials
for each BN node, indicate in which clique its CPT will be stored
void _onJointTargetErased(const NodeSet &set) final
fired before a joint target is removed
void _onJointTargetAdded(const NodeSet &set) final
fired after a new joint target is inserted
FindBarrenNodesType __barren_nodes_type
the type of barren nodes computation we wish
void _onAllJointTargetsErased() final
fired before a all the joint targets are removed
void setTriangulation(const Triangulation &new_triangulation)
use a new triangulation algorithm
void setRelevantPotentialsFinderType(RelevantPotentialsFinderType type)
sets how we determine the relevant potentials to combine
const NodeSet & hardEvidenceNodes() const
returns the set of nodes with hard evidence
HashTable< NodeId, NodeId > __node_to_clique
for each node of __graph (~ in the Bayes net), associate an ID in the JT
Potential< GUM_SCALAR > * _unnormalizedJointPosterior(NodeId id) final
returns a fresh potential equal to P(argument,evidence)
CliqueGraph JunctionTree
a junction tree is a clique graph satisfying the running intersection property and such that no cliqu...
__PotentialSet __marginalizeOut(__PotentialSet pot_list, Set< const DiscreteVariable * > &del_vars, Set< const DiscreteVariable * > &kept_vars)
removes variables del_vars from a list of potentials and returns the resulting list ...
void clear()
Removes all the elements in the hash table.
std::pair< __PotentialSet, __PotentialSet > __NodePotentials(NodeId node)
returns the CPT + evidence of a node projected w.r.t. hard evidence
void _updateOutdatedBNStructure() final
prepares inference when the latter is in OutdatedBNStructure state
void _onAllMarginalTargetsAdded() final
fired after all the nodes of the BN are added as single targets
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
std::pair< __PotentialSet, __PotentialSet > __produceMessage(NodeId from_id, NodeId to_id, std::pair< __PotentialSet, __PotentialSet > &&incoming_messages)
creates the message sent by clique from_id to clique to_id
virtual Triangulation * newFactory() const =0
returns a fresh triangulation of the same type as the current object but with an empty graph ...
virtual const NodeSet & targets() const noexcept final
returns the list of marginal targets
const node_iterator_safe & endSafe() const noexcept
the end iterator to parse the set of nodes contained in the NodeGraphPart
void __createNewJT(const NodeSet &targets)
create a new junction tree as well as its related data structures
~VariableElimination() final
destructor
std::size_t Size
In aGrUM, hashed values are unsigned long int.
virtual const CliqueGraph & junctionTree()=0
returns a compatible junction tree
const GUM_SCALAR __1_minus_epsilon
for comparisons with 1 - epsilon
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
virtual const std::vector< NodeId > & eliminationOrder()=0
returns an elimination ordering compatible with the triangulated graph
void _onMarginalTargetAdded(const NodeId id) final
fired after a new single target is inserted
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
Potential< GUM_SCALAR > *(* __projection_op)(const Potential< GUM_SCALAR > &, const Set< const DiscreteVariable * > &)
the operator for performing the projections
Size NodeId
Type for node ids.
void _onEvidenceChanged(const NodeId id, bool hasChangedSoftHard) final
fired after an evidence is changed, in particular when its status (soft/hard) changes ...
void insert(const Key &k)
Inserts a new element into the set.
void(VariableElimination< GUM_SCALAR >::* __findRelevantPotentials)(Set< const Potential< GUM_SCALAR > * > &pot_list, Set< const DiscreteVariable * > &kept_vars)
update a set of potentials: the remaining are those to be combined to produce a message on a separato...
void _onEvidenceAdded(const NodeId id, bool isHardEvidence) final
fired after a new evidence is inserted
#define GUM_ERROR(type, msg)
virtual void setGraph(const UndiGraph *graph, const NodeProperty< Size > *domsizes)=0
initialize the triangulation data structures for a new graph
static void requisiteNodes(const DAG &dag, const NodeSet &query, const NodeSet &hardEvidence, const NodeSet &softEvidence, NodeSet &requisite)
Fill the 'requisite' nodeset with the requisite nodes in dag given a query and evidence.
virtual void _onBayesNetChanged(const IBayesNet< GUM_SCALAR > *bn) final
fired after a new Bayes net has been assigned to the engine
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.