28 #ifndef DOXYGEN_SHOULD_SKIP_THIS 44 template <
typename GUM_SCALAR >
46 const IBayesNet< GUM_SCALAR >* BN,
49 JointTargetedInference< GUM_SCALAR >(BN) {
63 template <
typename GUM_SCALAR >
76 template <
typename GUM_SCALAR >
78 const Triangulation& new_triangulation) {
85 template <
typename GUM_SCALAR >
95 template <
typename GUM_SCALAR >
97 Potential< GUM_SCALAR >* (*proj)(
const Potential< GUM_SCALAR >&,
98 const Set< const DiscreteVariable* >&)) {
104 template <
typename GUM_SCALAR >
106 Potential< GUM_SCALAR >* (*comb)(
const Potential< GUM_SCALAR >&,
107 const Potential< GUM_SCALAR >&)) {
113 template <
typename GUM_SCALAR >
140 "setRelevantPotentialsFinderType for type " 141 << (
unsigned int)type <<
" is not implemented yet");
150 template <
typename GUM_SCALAR >
163 "setFindBarrenNodesType for type " 164 << (
unsigned int)type <<
" is not implemented yet");
173 template <
typename GUM_SCALAR >
179 template <
typename GUM_SCALAR >
185 template <
typename GUM_SCALAR >
190 template <
typename GUM_SCALAR >
196 template <
typename GUM_SCALAR >
202 template <
typename GUM_SCALAR >
207 template <
typename GUM_SCALAR >
209 const IBayesNet< GUM_SCALAR >* bn) {}
212 template <
typename GUM_SCALAR >
218 template <
typename GUM_SCALAR >
224 template <
typename GUM_SCALAR >
229 template <
typename GUM_SCALAR >
234 template <
typename GUM_SCALAR >
239 template <
typename GUM_SCALAR >
244 template <
typename GUM_SCALAR >
261 const auto& bn = this->
BN();
263 for (
auto node : bn.dag())
274 if (targets.size() != bn.size()) {
275 BarrenNodesFinder finder(&(bn.dag()));
276 finder.setTargets(&targets);
279 for (
const auto& pair : this->
evidence()) {
280 evidence_nodes.
insert(pair.first);
282 finder.setEvidence(&evidence_nodes);
284 NodeSet barren_nodes = finder.barrenNodes();
287 for (
const auto node : barren_nodes) {
297 bool dsep_analysis =
false;
306 dsep_analysis =
true;
311 dsep.requisiteNodes(bn.dag(),
316 dsep_analysis =
true;
321 default:
GUM_ERROR(FatalError,
"not implemented yet");
327 if (!requisite_nodes.contains(*iter)
336 for (
const auto node :
__graph) {
337 const NodeSet& parents = bn.parents(node);
338 for (
auto iter1 = parents.cbegin(); iter1 != parents.cend(); ++iter1) {
343 if (__graph.existsNode(*iter1)) __graph.addEdge(*iter1, node);
346 for (++iter2; iter2 != parents.cend(); ++iter2) {
351 if (__graph.existsNode(*iter1) && __graph.existsNode(*iter2))
352 __graph.addEdge(*iter1, *iter2);
360 for (
auto iter1 = targets.cbegin(); iter1 != targets.cend(); ++iter1) {
362 for (++iter2; iter2 != targets.cend(); ++iter2) {
363 __graph.addEdge(*iter1, *iter2);
369 __graph.eraseNode(node);
377 __JT =
new CliqueGraph(triang_jt);
384 for (
auto clique : *
__JT)
386 const std::vector< NodeId >& JT_elim_order =
388 NodeProperty< Size > elim_order(
Size(JT_elim_order.size()));
389 for (std::size_t i = std::size_t(0), size = JT_elim_order.size(); i < size;
391 elim_order.insert(JT_elim_order[i],
NodeId(i));
392 const DAG& dag = bn.dag();
393 for (
const auto node : __graph) {
395 NodeId first_eliminated_node = node;
396 Size elim_number = elim_order[first_eliminated_node];
398 for (
const auto parent : dag.parents(node)) {
399 if (__graph.existsNode(parent) && (elim_order[parent] < elim_number)) {
400 elim_number = elim_order[parent];
401 first_eliminated_node = parent;
420 NodeSet pars(dag.parents(node).size());
421 for (
const auto par : dag.parents(node))
422 if (__graph.exists(par)) pars.
insert(par);
425 NodeId first_eliminated_node = *(pars.begin());
426 Size elim_number = elim_order[first_eliminated_node];
428 for (
const auto parent : pars) {
429 if (elim_order[parent] < elim_number) {
430 elim_number = elim_order[parent];
431 first_eliminated_node = parent;
454 if (nodeset.contains(node)) nodeset.
erase(node);
456 if (!nodeset.empty()) {
457 NodeId first_eliminated_node = *(nodeset.begin());
458 Size elim_number = elim_order[first_eliminated_node];
459 for (
const auto node : nodeset) {
460 if (elim_order[node] < elim_number) {
461 elim_number = elim_order[node];
462 first_eliminated_node = node;
473 template <
typename GUM_SCALAR >
479 template <
typename GUM_SCALAR >
484 template <
typename GUM_SCALAR >
486 Set<
const Potential< GUM_SCALAR >* >& pot_list,
487 Set< const DiscreteVariable* >& kept_vars) {}
491 template <
typename GUM_SCALAR >
493 Set<
const Potential< GUM_SCALAR >* >& pot_list,
494 Set< const DiscreteVariable* >& kept_vars) {
497 const auto& bn = this->
BN();
498 for (
const auto var : kept_vars) {
499 kept_ids.insert(bn.nodeId(*var));
509 for (
auto iter = pot_list.beginSafe(); iter != pot_list.endSafe(); ++iter) {
510 const Sequence< const DiscreteVariable* >& vars =
511 (**iter).variablesSequence();
513 for (
auto var : vars) {
514 if (requisite_nodes.exists(bn.nodeId(*var))) {
520 if (!found) { pot_list.erase(iter); }
526 template <
typename GUM_SCALAR >
528 Set<
const Potential< GUM_SCALAR >* >& pot_list,
529 Set< const DiscreteVariable* >& kept_vars) {
532 const auto& bn = this->
BN();
533 for (
const auto var : kept_vars) {
534 kept_ids.insert(bn.nodeId(*var));
547 template <
typename GUM_SCALAR >
549 Set<
const Potential< GUM_SCALAR >* >& pot_list,
550 Set< const DiscreteVariable* >& kept_vars) {
553 const auto& bn = this->
BN();
554 for (
const auto var : kept_vars) {
555 kept_ids.insert(bn.nodeId(*var));
560 dsep.relevantPotentials(bn,
569 template <
typename GUM_SCALAR >
571 Set<
const Potential< GUM_SCALAR >* >& pot_list,
572 Set< const DiscreteVariable* >& kept_vars) {
590 default:
GUM_ERROR(FatalError,
"not implemented yet");
596 template <
typename GUM_SCALAR >
597 Set< const Potential< GUM_SCALAR >* >
599 __PotentialSet& pot_list, Set< const DiscreteVariable* >& del_vars) {
602 Set< const DiscreteVariable* > the_del_vars = del_vars;
603 for (
auto iter = the_del_vars.beginSafe(); iter != the_del_vars.endSafe();
605 NodeId id = this->
BN().nodeId(**iter);
608 the_del_vars.erase(iter);
613 HashTable< const DiscreteVariable*, __PotentialSet > var2pots;
615 for (
const auto pot : pot_list) {
616 const Sequence< const DiscreteVariable* >& vars = pot->variablesSequence();
617 for (
const auto var : vars) {
618 if (the_del_vars.exists(var)) {
619 if (!var2pots.exists(var)) { var2pots.insert(var, empty_pot_set); }
620 var2pots[var].insert(pot);
627 HashTable< const Potential< GUM_SCALAR >*, Set< const DiscreteVariable* > >
629 Set< const DiscreteVariable* > empty_var_set;
630 for (
auto elt : var2pots) {
631 if (elt.second.size() == 1) {
632 const Potential< GUM_SCALAR >* pot = *(elt.second.begin());
633 if (!pot2barren_var.exists(pot)) {
634 pot2barren_var.insert(pot, empty_var_set);
636 pot2barren_var[pot].insert(elt.first);
645 for (
auto elt : pot2barren_var) {
648 const Potential< GUM_SCALAR >* pot = elt.first;
653 if (pot->variablesSequence().size() != elt.second.size()) {
654 auto new_pot = projector.project(*pot, elt.second);
655 pot_list.insert(new_pot);
656 projected_pots.insert(new_pot);
660 return projected_pots;
665 template <
typename GUM_SCALAR >
666 std::pair< Set< const Potential< GUM_SCALAR >* >,
667 Set< const Potential< GUM_SCALAR >* > >
670 std::pair< __PotentialSet, __PotentialSet > collect_messages;
671 for (
const auto other : __JT->neighbours(
id)) {
673 std::pair< __PotentialSet, __PotentialSet > message(
675 collect_messages.first += message.first;
676 collect_messages.second += message.second;
686 template <
typename GUM_SCALAR >
687 std::pair< Set< const Potential< GUM_SCALAR >* >,
688 Set< const Potential< GUM_SCALAR >* > >
690 std::pair< __PotentialSet, __PotentialSet > res;
691 const auto& bn = this->
BN();
705 const Potential< GUM_SCALAR >& cpt = bn.cpt(node);
706 const auto& variables = cpt.variablesSequence();
712 for (
const auto var : variables) {
713 NodeId xnode = bn.nodeId(*var);
715 && !__graph.existsNode(xnode))
722 for (
const auto var : variables) {
723 NodeId xnode = bn.nodeId(*var);
730 if (hard_nodes.empty()) {
731 res.first.insert(&cpt);
736 if (hard_nodes.size() != variables.size()) {
738 Set< const DiscreteVariable* > hard_variables;
740 for (
const auto xnode : hard_nodes) {
741 marg_cpt_set.insert(
evidence[xnode]);
742 hard_variables.insert(&(bn.variable(xnode)));
745 MultiDimCombineAndProjectDefault< GUM_SCALAR, Potential >
748 combine_and_project.combineAndProject(marg_cpt_set, hard_variables);
751 if (new_cpt_list.size() != 1) {
753 for (
auto pot : new_cpt_list) {
754 if (!marg_cpt_set.contains(pot))
delete pot;
757 "the projection of a potential containing " 758 <<
"hard evidence is empty!");
760 const Potential< GUM_SCALAR >* projected_cpt = *(new_cpt_list.begin());
761 res.first.insert(projected_cpt);
762 res.second.insert(projected_cpt);
767 if (
evidence.exists(node) && !hard_evidence.exists(node)) {
768 res.first.insert(this->
evidence()[node]);
777 template <
typename GUM_SCALAR >
778 std::pair< Set< const Potential< GUM_SCALAR >* >,
779 Set< const Potential< GUM_SCALAR >* > >
783 std::pair< Set<
const Potential< GUM_SCALAR >* >,
784 Set<
const Potential< GUM_SCALAR >* > >&& incoming_messages) {
786 std::pair< Set< const Potential< GUM_SCALAR >* >,
787 Set< const Potential< GUM_SCALAR >* > >
788 pot_list(std::move(incoming_messages));
793 pot_list.first += new_pots.first;
794 pot_list.second += new_pots.second;
798 if (!__JT->existsEdge(from_id, to_id)) {
802 const NodeSet& from_clique = __JT->clique(from_id);
803 const NodeSet& separator = __JT->separator(from_id, to_id);
804 Set< const DiscreteVariable* > del_vars(from_clique.size());
805 Set< const DiscreteVariable* > kept_vars(separator.size());
806 const auto& bn = this->
BN();
808 for (
const auto node : from_clique) {
809 if (!separator.contains(node)) {
810 del_vars.insert(&(bn.variable(node)));
812 kept_vars.insert(&(bn.variable(node)));
823 for (
auto iter = new_pot_list.beginSafe(); iter != new_pot_list.endSafe();
825 const auto pot = *iter;
826 if (pot->variablesSequence().size() == 1) {
827 bool is_all_ones =
true;
828 for (Instantiation inst(*pot); !inst.end(); ++inst) {
835 if (!pot_list.first.exists(pot))
delete pot;
836 new_pot_list.erase(iter);
843 for (
auto iter = pot_list.second.beginSafe();
844 iter != pot_list.second.endSafe();
846 if (!new_pot_list.contains(*iter)) {
848 pot_list.second.erase(iter);
853 for (
const auto pot : new_pot_list) {
854 if (!pot_list.first.contains(pot)) { pot_list.second.insert(pot); }
858 return std::pair< __PotentialSet, __PotentialSet >(
859 std::move(new_pot_list), std::move(pot_list.second));
865 template <
typename GUM_SCALAR >
866 Set< const Potential< GUM_SCALAR >* >
868 Set<
const Potential< GUM_SCALAR >* > pot_list,
869 Set< const DiscreteVariable* >& del_vars,
870 Set< const DiscreteVariable* >& kept_vars) {
883 MultiDimCombineAndProjectDefault< GUM_SCALAR, Potential > combine_and_project(
886 combine_and_project.combineAndProject(pot_list, del_vars);
891 for (
auto iter = barren_projected_potentials.beginSafe();
892 iter != barren_projected_potentials.endSafe();
894 if (!new_pot_list.exists(*iter))
delete *iter;
898 for (
auto iter_pot = new_pot_list.beginSafe();
899 iter_pot != new_pot_list.endSafe();
901 if ((*iter_pot)->variablesSequence().size() == 0) {
908 new_pot_list.erase(iter_pot);
917 template <
typename GUM_SCALAR >
922 template <
typename GUM_SCALAR >
923 Potential< GUM_SCALAR >*
925 const auto& bn = this->
BN();
930 return new Potential< GUM_SCALAR >(*(this->
evidence()[id]));
939 const NodeSet& nodes = __JT->clique(clique_of_id);
940 Set< const DiscreteVariable* > kept_vars{&(bn.variable(
id))};
941 Set< const DiscreteVariable* > del_vars(nodes.size());
942 for (
const auto node : nodes) {
943 if (node !=
id) del_vars.
insert(&(bn.variable(node)));
950 Potential< GUM_SCALAR >* joint =
nullptr;
952 if (new_pot_list.size() == 1) {
953 joint =
const_cast< Potential< GUM_SCALAR >*
>(*(new_pot_list.begin()));
956 if (pot_list.first.exists(joint)) {
957 joint =
new Potential< GUM_SCALAR >(*joint);
961 new_pot_list.clear();
964 MultiDimCombinationDefault< GUM_SCALAR, Potential > fast_combination(
966 joint = fast_combination.combine(new_pot_list);
970 for (
auto pot : new_pot_list)
971 if (!pot_list.first.exists(pot))
delete pot;
974 for (
auto pot : pot_list.second)
980 bool nonzero_found =
false;
981 for (Instantiation inst(*joint); !inst.end(); ++inst) {
982 if ((*joint)[inst]) {
983 nonzero_found =
true;
987 if (!nonzero_found) {
991 "some evidence entered into the Bayes " 992 "net are incompatible (their joint proba = 0)");
1000 template <
typename GUM_SCALAR >
1001 const Potential< GUM_SCALAR >&
1015 template <
typename GUM_SCALAR >
1016 Potential< GUM_SCALAR >*
1021 NodeSet targets =
set, hard_ev_nodes;
1023 if (targets.contains(node)) {
1024 targets.
erase(node);
1025 hard_ev_nodes.insert(node);
1032 if (targets.empty()) {
1034 for (
const auto node :
set) {
1037 if (pot_list.size() == 1) {
1038 return new Potential< GUM_SCALAR >(**(pot_list.begin()));
1040 MultiDimCombinationDefault< GUM_SCALAR, Potential > fast_combination(
1042 return fast_combination.combine(pot_list);
1052 Set< const DiscreteVariable* > del_vars(nodes.size());
1053 Set< const DiscreteVariable* > kept_vars(targets.size());
1054 const auto& bn = this->
BN();
1055 for (
const auto node : nodes) {
1056 if (!targets.contains(node)) {
1057 del_vars.insert(&(bn.variable(node)));
1059 kept_vars.insert(&(bn.variable(node)));
1067 Potential< GUM_SCALAR >* joint =
nullptr;
1069 if ((new_pot_list.size() == 1) && hard_ev_nodes.empty()) {
1070 joint =
const_cast< Potential< GUM_SCALAR >*
>(*(new_pot_list.begin()));
1073 if (pot_list.first.exists(joint)) {
1074 joint =
new Potential< GUM_SCALAR >(*joint);
1078 new_pot_list.clear();
1084 for (
const auto node : hard_ev_nodes) {
1085 new_new_pot_list.insert(
evidence[node]);
1087 MultiDimCombinationDefault< GUM_SCALAR, Potential > fast_combination(
1089 joint = fast_combination.combine(new_new_pot_list);
1093 for (
auto pot : new_pot_list)
1094 if (!pot_list.first.exists(pot))
delete pot;
1097 for (
auto pot : pot_list.second)
1102 bool nonzero_found =
false;
1103 for (Instantiation inst(*joint); !inst.end(); ++inst) {
1104 if ((*joint)[inst]) {
1105 nonzero_found =
true;
1109 if (!nonzero_found) {
1113 "some evidence entered into the Bayes " 1114 "net are incompatible (their joint proba = 0)");
1122 template <
typename GUM_SCALAR >
1123 const Potential< GUM_SCALAR >&
1137 template <
typename GUM_SCALAR >
1138 const Potential< GUM_SCALAR >&
1147 #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
d-separation analysis (as described in Koller & Friedman 2009)
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
The BayesBall algorithm (as described by Schachter).
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.
gum is the global namespace for all aGrUM entities
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...
Implementation of a variable elimination algorithm for inference in Bayesian Networks.
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...
const NodeProperty< Idx > & hardEvidence() const
indicate for each node with hard evidence which value it took
Header files of gum::Instantiation.
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
An algorithm for converting a join tree into a binary join tree.
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