49#ifndef GUM_VARIABLE_ELIMINATION_H
50#define GUM_VARIABLE_ELIMINATION_H
66 template <
typename GUM_SCALAR >
68 const Tensor< GUM_SCALAR >& t2) {
73 template <
typename GUM_SCALAR >
74 INLINE
static Tensor< GUM_SCALAR >
VENewprojTensor(
const Tensor< GUM_SCALAR >& t1,
76 return t1.sumOut(del_vars);
86 template <
typename GUM_SCALAR >
234 const
NodeSet& declared_target) final;
312 const Tensor< GUM_SCALAR >&));
359 std::pair< _TensorSet_, _TensorSet_ >
362 std::pair< _TensorSet_, _TensorSet_ >&& incoming_messages);
395 const NodeSet& hard_evidence_nodes);
402 const NodeSet& hard_evidence_nodes);
406#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
Detect barren nodes for inference in Bayesian networks.
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
Virtual base class for probabilistic graphical models.
Class representing the minimal interface for Bayesian network with no numerical data.
The Table-agnostic base class of scheduleMultiDim.
JointTargetedInference(const IBayesNet< GUM_SCALAR > *bn)
default constructor
virtual const NodeSet & targets() const noexcept final
returns the list of marginal targets
Class containing a schedule of operations to perform on multidims.
ScheduledInference(Size max_nb_threads=0, double max_megabyte_memory=0.0)
default constructor
aGrUM's Tensor is a multi-dimensional array with tensor operators.
Interface for all the triangulation methods.
Base class for undirected graphs.
Implementation of a Variable Elimination's-like version of lazy propagation for inference in Bayesian...
void onEvidenceAdded_(const NodeId id, bool isHardEvidence) final
fired after a new evidence is inserted
void onAllMarginalTargetsAdded_() final
fired after all the nodes of the BN are added as single targets
void updateOutdatedTensors_() final
prepares inference when the latter is in OutdatedTensors state
RelevantTensorsFinderType _find_relevant_tensor_type_
the type of relevant tensor finding algorithm to be used
VariableElimination(const IBayesNet< GUM_SCALAR > *BN, RelevantTensorsFinderType=RelevantTensorsFinderType::DSEP_BAYESBALL_TENSORS, FindBarrenNodesType=FindBarrenNodesType::FIND_BARREN_NODES)
default constructor
const Tensor< GUM_SCALAR > & posterior_(NodeId id) final
returns the posterior of a given variable
void _findRelevantTensorsXX_(_ScheduleMultiDimSet_ &pot_list, gum::VariableSet &kept_vars)
update a set of tensors: the remaining are those to be combined to produce a message on a separator
UndiGraph _graph_
the undigraph extracted from the BN and used to construct the join tree
Tensor< GUM_SCALAR >(* _combination_op_)(const Tensor< GUM_SCALAR > &, const Tensor< GUM_SCALAR > &)
the operator for performing the combinations
void _findRelevantTensorsWithdSeparation_(_ScheduleMultiDimSet_ &pot_list, gum::VariableSet &kept_vars)
update a set of tensors: the remaining are those to be combined to produce a message on a separator
HashTable< NodeId, NodeId > _node_to_clique_
for each node of graph (~ in the Bayes net), associate an ID in the JT
void onStateChanged_() final
fired when the state of the inference engine is changed
void onJointTargetErased_(const NodeSet &set) final
fired before a joint target is removed
void _findRelevantTensorsWithdSeparation2_(_ScheduleMultiDimSet_ &pot_list, gum::VariableSet &kept_vars)
update a set of tensors: the remaining are those to be combined to produce a message on a separator
void _setCombinationFunction_(Tensor< GUM_SCALAR >(*comb)(const Tensor< GUM_SCALAR > &, const Tensor< GUM_SCALAR > &))
sets the operator for performing the combinations
Set< const Tensor< GUM_SCALAR > * > _TensorSet_
void(VariableElimination< GUM_SCALAR >::* _findRelevantTensors_)(Set< const IScheduleMultiDim * > &pot_list, gum::VariableSet &kept_vars)
update a set of tensors: the remaining are those to be combined to produce a message on a separator
VariableElimination(const VariableElimination< GUM_SCALAR > &)=delete
avoid copy constructors
void onMarginalTargetAdded_(const NodeId id) final
fired after a new single target is inserted
void _findRelevantTensorsGetAll_(_ScheduleMultiDimSet_ &pot_list, gum::VariableSet &kept_vars)
update a set of tensors: the remaining are those to be combined to produce a message on a separator
_ScheduleMultiDimSet_ _marginalizeOut_(Schedule &schedule, _ScheduleMultiDimSet_ pot_list, gum::VariableSet &del_vars, gum::VariableSet &kept_vars)
removes variables del_vars from a list of tensors and returns the resulting list using schedules
void onEvidenceChanged_(const NodeId id, bool hasChangedSoftHard) final
fired after an evidence is changed, in particular when its status (soft/hard) changes
const Tensor< GUM_SCALAR > & jointPosterior_(const NodeSet &set) final
returns the posterior of a declared target set
void _setProjectionFunction_(Tensor< GUM_SCALAR >(*proj)(const Tensor< GUM_SCALAR > &, const gum::VariableSet &))
sets the operator for performing the projections
_ScheduleMultiDimSet_ _removeBarrenVariables_(Schedule &schedule, _ScheduleMultiDimSet_ &pot_list, gum::VariableSet &del_vars)
remove barren variables using schedules and return the newly created projected tensors
Tensor< GUM_SCALAR > * _unnormalizedJointPosterior_(Schedule &schedule, NodeId id)
returns a fresh tensor equal to P(1st arg,evidence) without using schedules
void onAllTargetsErased_() final
fired before all single and joint targets are removed
void setFindBarrenNodesType(FindBarrenNodesType type)
sets how we determine barren nodes
const JunctionTree * junctionTree(NodeId id)
returns the join tree used for compute the posterior of node id
void _findRelevantTensorsWithdSeparation3_(_ScheduleMultiDimSet_ &pot_list, gum::VariableSet &kept_vars)
update a set of tensors: the remaining are those to be combined to produce a message on a separator
~VariableElimination()
destructor
void onEvidenceErased_(const NodeId id, bool isHardEvidence) final
fired before an evidence is removed
std::pair< _TensorSet_, _TensorSet_ > _produceMessage_(NodeId from_id, NodeId to_id, std::pair< _TensorSet_, _TensorSet_ > &&incoming_messages)
creates the message sent by clique from_id to clique to_id without using schedules
Tensor< GUM_SCALAR > * unnormalizedJointPosterior_(NodeId id) final
returns a fresh tensor equal to P(argument,evidence)
_TensorSet_ _removeBarrenVariables_(_TensorSet_ &pot_list, gum::VariableSet &del_vars)
remove barren variables without schedules and return the newly created projected tensors
HashTable< NodeId, NodeSet > _clique_to_nodes_
for each clique, indicate the set of nodes whose CPTs will be stored into it
void onMarginalTargetErased_(const NodeId id) final
fired before a single target is removed
_ScheduleMultiDimSet_ _NodeTensors_(Schedule &schedule, NodeId node)
returns the CPT + evidence of a node projected w.r.t. hard evidence
static constexpr double _schedule_threshold_
minimal number of operations to perform in the JT to use schedules
void updateOutdatedStructure_() final
prepares inference when the latter is in OutdatedStructure state
JunctionTree * _JT_
the junction tree used to answer the last inference query
void onAllMarginalTargetsErased_() final
fired before all the single targets are removed
void onAllEvidenceErased_(bool has_hard_evidence) final
fired before all the evidence are erased
void setTriangulation(const Triangulation &new_triangulation)
use a new triangulation algorithm
void makeInference_() final
called when the inference has to be performed effectively
Tensor< GUM_SCALAR >(* _projection_op_)(const Tensor< GUM_SCALAR > &, const gum::VariableSet &)
the operator for performing the projections
void onJointTargetAdded_(const NodeSet &set) final
fired after a new joint target is inserted
std::pair< _TensorSet_, _TensorSet_ > _NodeTensors_(NodeId node)
returns the CPT + evidence of a node projected w.r.t. hard evidence
Tensor< GUM_SCALAR > * _unnormalizedJointPosterior_(NodeId id)
returns a fresh tensor equal to P(1st arg,evidence) without using schedules
Tensor< GUM_SCALAR > * _unnormalizedJointPosterior_(Schedule &schedule, const NodeSet &set, const NodeSet &targets, const NodeSet &hard_evidence_nodes)
returns a fresh tensor equal to P(1st arg,evidence) without using schedules
_TensorSet_ _marginalizeOut_(_TensorSet_ pot_list, gum::VariableSet &del_vars, gum::VariableSet &kept_vars)
removes variables del_vars from a list of tensors and returns the resulting list directly without sch...
Tensor< GUM_SCALAR > * _target_posterior_
the posterior computed during the last inference
void _createNewJT_(const NodeSet &targets)
create a new junction tree as well as its related data structures
Triangulation * _triangulation_
the triangulation class creating the junction tree used for inference
std::pair< _TensorSet_, _TensorSet_ > _collectMessage_(NodeId id, NodeId from)
perform the collect phase directly without schedules
_ScheduleMultiDimSet_ _collectMessage_(Schedule &schedule, NodeId id, NodeId from)
perform the collect phase using schedules
NodeId _targets2clique_
indicate a clique that contains all the nodes of the target
void onAllJointTargetsErased_() final
fired before all the joint targets are removed
void setRelevantTensorsFinderType(RelevantTensorsFinderType type)
sets how we determine the relevant tensors to combine
const GUM_SCALAR _one_minus_epsilon_
for comparisons with 1 - epsilon
Set< const IScheduleMultiDim * > _ScheduleMultiDimSet_
Tensor< GUM_SCALAR > * _unnormalizedJointPosterior_(const NodeSet &set, const NodeSet &targets, const NodeSet &hard_evidence_nodes)
returns a fresh tensor equal to P(1st arg,evidence) without using schedules
_ScheduleMultiDimSet_ _produceMessage_(Schedule &schedule, NodeId from_id, NodeId to_id, _ScheduleMultiDimSet_ &&incoming_messages)
creates the message sent by clique from_id to clique to_id using schedules
virtual void onModelChanged_(const GraphicalModel *bn) final
fired after a new Bayes net has been assigned to the inference engine
FindBarrenNodesType _barren_nodes_type_
the type of barren nodes computation we wish
VariableElimination< GUM_SCALAR > & operator=(const VariableElimination< GUM_SCALAR > &)=delete
avoid copy operators
Class for computing default triangulations of graphs.
Size NodeId
Type for node ids.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
This file contains the abstract inference class definition for computing (incrementally) joint poster...
gum is the global namespace for all aGrUM entities
FindBarrenNodesType
type of algorithm to determine barren nodes
Set< const DiscreteVariable * > VariableSet
static INLINE Tensor< GUM_SCALAR > VENewprojTensor(const Tensor< GUM_SCALAR > &t1, const gum::VariableSet &del_vars)
static INLINE Tensor< GUM_SCALAR > VENewmultiTensor(const Tensor< GUM_SCALAR > &t1, const Tensor< GUM_SCALAR > &t2)
CliqueGraph JunctionTree
a junction tree is a clique graph satisfying the running intersection property and such that no cliqu...
RelevantTensorsFinderType
type of algorithm for determining the relevant tensors for combinations using some d-separation analy...
the type of algorithm to use to perform relevant reasoning in Bayes net inference
The class enabling flexible inferences using schedules.
Implementation of Variable Elimination for inference in Bayesian networks.