49#ifndef GUM_SHAFER_SHENOY_INFERENCE_H
50#define GUM_SHAFER_SHENOY_INFERENCE_H
67 template <
typename GUM_SCALAR >
69 const Tensor< GUM_SCALAR >& t2) {
74 template <
typename GUM_SCALAR >
75 INLINE
static Tensor< GUM_SCALAR >
SSNewprojTensor(
const Tensor< GUM_SCALAR >& t1,
77 return t1.sumOut(del_vars);
87 template <
typename GUM_SCALAR >
104 bool use_binary_join_tree =
true);
252 const
NodeSet& declared_target) final;
437 const Tensor< GUM_SCALAR >&));
519#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
Implementation of Shafer-Shenoy's propagation for inference in Bayesian networks.
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.
EvidenceInference(const IBayesNet< GUM_SCALAR > *bn)
default constructor
Virtual base class for probabilistic graphical models.
The class for generic Hash Tables.
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
Class containing a schedule of operations to perform on multidims.
ScheduledInference(Size max_nb_threads=0, double max_megabyte_memory=0.0)
default constructor
Safe iterators for the Set class.
Implementation of Shafer-Shenoy's propagation algorithm for inference in Bayesian networks.
void _computeJoinTreeRoots_()
compute a root for each connected component of JT
void onMarginalTargetErased_(const NodeId id) final
fired before a single target is removed
Tensor< GUM_SCALAR > * unnormalizedJointPosterior_(NodeId id) final
returns a fresh tensor equal to P(argument,evidence)
HashTable< NodeSet, const Tensor< GUM_SCALAR > * > _joint_target_posteriors_
the set of set target posteriors computed during the last inference
bool _isNewJTNeeded_() const
check whether a new join tree is really needed for the next inference
void _setProjectionFunction_(Tensor< GUM_SCALAR >(*proj)(const Tensor< GUM_SCALAR > &, const gum::VariableSet &))
sets the operator for performing the projections
static constexpr GUM_SCALAR _one_minus_epsilon_
for comparisons with 1 - epsilon
static constexpr double _schedule_threshold_
minimal number of operations to perform in the JT to use schedules
void _collectMessage_(Schedule &schedule, NodeId id, NodeId from)
perform the collect phase using schedules
void onEvidenceChanged_(const NodeId id, bool hasChangedSoftHard) final
fired after an evidence is changed, in particular when its status (soft/hard) changes
void onEvidenceAdded_(const NodeId id, bool isHardEvidence) final
fired after a new evidence is inserted
const JunctionTree * junctionTree()
returns the current junction tree
void _invalidateAllMessages_()
invalidate all messages, posteriors and created tensors
const IScheduleMultiDim * _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
NodeProperty< _ScheduleMultiDimSet_ > _clique_tensors_
the list of all tensors stored in the cliques
bool _use_schedules_
indicates whether we should use schedules for inference
void setFindBarrenNodesType(FindBarrenNodesType type)
sets how we determine barren nodes
EvidenceChangeType
the possible types of evidence changes
const Tensor< GUM_SCALAR > & jointPosterior_(const NodeSet &set) final
returns the posterior of a declared target set
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
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
SetIteratorSafe< const Tensor< GUM_SCALAR > * > _TensorSetIterator_
FindBarrenNodesType _barren_nodes_type_
the type of barren nodes computation we wish
void onJointTargetAdded_(const NodeSet &set) final
fired after a new joint target is inserted
GUM_SCALAR evidenceProbability() final
returns the probability of evidence
Tensor< GUM_SCALAR > * _unnormalizedJointPosterior_(Schedule &schedule, const NodeSet &set)
returns a fresh tensor equal to P(argument,evidence) using schedules
Tensor< GUM_SCALAR >(* _projection_op_)(const Tensor< GUM_SCALAR > &, const gum::VariableSet &)
the operator for performing the projections
NodeProperty< const IScheduleMultiDim * > _node_to_hard_ev_projected_CPTs_
the CPTs that were projected due to hard evidence nodes
const Tensor< GUM_SCALAR > & posterior_(NodeId id) final
returns the posterior of a given variable
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
void onStateChanged_() final
fired when the state of the inference engine is changed
_ScheduleMultiDimSet_ _removeBarrenVariables_(Schedule &schedule, _ScheduleMultiDimSet_ &pot_list, gum::VariableSet &del_vars)
remove barren variables and return the newly created projected tensors
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 onAllMarginalTargetsErased_() final
fired before all the single targets are removed
void onEvidenceErased_(const NodeId id, bool isHardEvidence) final
fired before an evidence is removed
void _diffuseMessageInvalidations_(NodeId from_id, NodeId to_id, NodeSet &invalidated_cliques)
invalidate all the messages sent from a given clique
Tensor< GUM_SCALAR >(* _combination_op_)(const Tensor< GUM_SCALAR > &, const Tensor< GUM_SCALAR > &)
the operator for performing the combinations
void(ShaferShenoyInference< 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
NodeProperty< const IScheduleMultiDim * > _node_to_soft_evidence_
the soft evidence stored in the cliques per their assigned node in the BN
~ShaferShenoyInference()
destructor
ShaferShenoyInference< GUM_SCALAR > & operator=(const ShaferShenoyInference< GUM_SCALAR > &)=delete
avoid copy operators
Triangulation * _triangulation_
the triangulation class creating the junction tree used for inference
void onAllJointTargetsErased_() final
fired before all the joint targets are removed
UndiGraph _graph_
the undigraph extracted from the BN and used to construct the join tree
HashTable< NodeSet, NodeId > _joint_target_to_clique_
for each set target, assign a clique in the JT that contains it
void onAllEvidenceErased_(bool has_hard_evidence) final
fired before all the evidence are erased
void onMarginalTargetAdded_(const NodeId id) final
fired after a new single target is inserted
ShaferShenoyInference(const IBayesNet< GUM_SCALAR > *BN, RelevantTensorsFinderType=RelevantTensorsFinderType::DSEP_BAYESBALL_TENSORS, FindBarrenNodesType barren_type=FindBarrenNodesType::FIND_BARREN_NODES, bool use_binary_join_tree=true)
default constructor
ShaferShenoyInference(const ShaferShenoyInference< GUM_SCALAR > &)=delete
avoid copy constructors
JoinTree * _JT_
the join (or junction) tree used to answer the last inference query
NodeProperty< EvidenceChangeType > _evidence_changes_
indicates which nodes of the BN have evidence that changed since the last inference
void updateOutdatedStructure_() final
prepares inference when the latter is in OutdatedStructure state
JunctionTree * _junctionTree_
the junction tree to answer the last inference query
void _produceMessage_(Schedule &schedule, NodeId from_id, NodeId to_id)
creates the message sent by clique from_id to clique to_id using schedules
Tensor< GUM_SCALAR > * _unnormalizedJointPosterior_(const NodeSet &set)
returns a fresh tensor equal to P(argument,evidence) without using schedules
void _initializeJTCliques_(Schedule &schedule)
put all the CPTs into the cliques when creating the JT using a schedule
void _produceMessage_(NodeId from_id, NodeId to_id)
creates the message sent by clique from_id to clique to_id without schedules
void onAllMarginalTargetsAdded_() final
fired after all the nodes of the BN are added as single targets
NodeProperty< GUM_SCALAR > _constants_
the constants resulting from the projections of CPTs defined over only hard evidence nodes @TODO remo...
bool _is_new_jt_needed_
indicates whether a new join tree is needed for the next inference
NodeSet _hard_ev_nodes_
the hard evidence nodes which were projected in CPTs
NodeProperty< const IScheduleMultiDim * > _clique_ss_tensor_
the tensors stored into the cliques by Shafer-Shenoy
void onAllTargetsErased_() final
fired before all single and joint targets are removed
void makeInference_() final
called when the inference has to be performed effectively
void onModelChanged_(const GraphicalModel *bn) final
fired after a new Bayes net has been assigned to the inference engine
ArcProperty< const IScheduleMultiDim * > _arc_to_created_tensors_
the set of tensors created for the last inference messages
Tensor< GUM_SCALAR > * _unnormalizedJointPosterior_(NodeId id)
computes the unnormalized posterior of a node without using schedules
void _createNewJT_()
create a new junction tree as well as its related data structures
ArcProperty< const IScheduleMultiDim * > _separator_tensors_
the list of all tensors stored in the separators after inferences
void setTriangulation(const Triangulation &new_triangulation)
use a new triangulation algorithm
void onJointTargetErased_(const NodeSet &set) final
fired before a joint target is removed
void _collectMessage_(NodeId id, NodeId from)
actually perform the collect phase directly without schedules
RelevantTensorsFinderType _find_relevant_tensor_type_
the type of relevant tensor finding algorithm to be used
Tensor< GUM_SCALAR > * _unnormalizedJointPosterior_(Schedule &schedule, NodeId id)
computes the unnormalized posterior of a node using schedules
void setRelevantTensorsFinderType(RelevantTensorsFinderType type)
sets how we determine the relevant tensors to combine
const JoinTree * joinTree()
returns the current join tree used
Set< const Tensor< GUM_SCALAR > * > _TensorSet_
void _initializeJTCliques_()
put all the CPTs into the cliques when creating the JT without using a schedule
Set< const IScheduleMultiDim * > _ScheduleMultiDimSet_
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
NodeSet _roots_
a clique node used as a root in each connected component of JT
void _setCombinationFunction_(Tensor< GUM_SCALAR >(*comb)(const Tensor< GUM_SCALAR > &, const Tensor< GUM_SCALAR > &))
sets the operator for performing the combinations
const IScheduleMultiDim * _marginalizeOut_(_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 directly without sch...
ArcProperty< bool > _messages_computed_
indicates whether a message (from one clique to another) has been computed
NodeProperty< const Tensor< GUM_SCALAR > * > _target_posteriors_
the set of single posteriors computed during the last inference
void updateOutdatedTensors_() final
prepares inference when the latter is in OutdatedTensors state
NodeProperty< NodeId > _node_to_clique_
for each node of graph (~ in the Bayes net), associate an ID in the JT
bool _use_binary_join_tree_
indicates whether we should transform junction trees into binary join trees
_TensorSet_ _removeBarrenVariables_(_TensorSet_ &pot_list, gum::VariableSet &del_vars)
remove barren variables without schedules and return the newly created projected tensors
aGrUM's Tensor is a multi-dimensional array with tensor operators.
Interface for all the triangulation methods.
Base class for undirected graphs.
Class for computing default triangulations of graphs.
This file contains the abstract class definition for computing the probability of evidence entered in...
Size NodeId
Type for node ids.
HashTable< Arc, VAL > ArcProperty
Property on graph elements.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
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 > SSNewprojTensor(const Tensor< GUM_SCALAR > &t1, const gum::VariableSet &del_vars)
static INLINE Tensor< GUM_SCALAR > SSNewmultiTensor(const Tensor< GUM_SCALAR > &t1, const Tensor< GUM_SCALAR > &t2)
CliqueGraph JoinTree
a join tree is a clique graph satisfying the running intersection property (but some cliques may be i...
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.