31 template <
typename GUM_SCALAR >
36 if (this->
__bn ==
nullptr) {
51 template <
typename GUM_SCALAR >
58 template <
typename GUM_SCALAR >
71 template <
typename GUM_SCALAR >
75 if (this->
__bn ==
nullptr)
77 "No Bayes net has been assigned to the " 78 "inference algorithm");
79 if (!this->
__bn->dag().exists(node)) {
87 template <
typename GUM_SCALAR >
89 const std::string& nodeName)
const {
95 template <
typename GUM_SCALAR >
108 template <
typename GUM_SCALAR >
111 if (this->
__bn ==
nullptr)
113 "No Bayes net has been assigned to the " 114 "inference algorithm");
116 if (!this->
__bn->dag().exists(target)) {
132 template <
typename GUM_SCALAR >
135 if (this->
__bn ==
nullptr)
137 "No Bayes net has been assigned to the " 138 "inference algorithm");
142 for (
const auto target : this->
__bn->dag()) {
154 template <
typename GUM_SCALAR >
156 const std::string& nodeName) {
158 if (this->
__bn ==
nullptr)
160 "No Bayes net has been assigned to the " 161 "inference algorithm");
168 template <
typename GUM_SCALAR >
171 if (this->
__bn ==
nullptr)
173 "No Bayes net has been assigned to the " 174 "inference algorithm");
176 if (!this->
__bn->dag().exists(target)) {
193 template <
typename GUM_SCALAR >
195 const std::string& nodeName) {
197 if (this->
__bn ==
nullptr)
199 "No Bayes net has been assigned to the " 200 "inference algorithm");
207 template <
typename GUM_SCALAR >
214 template <
typename GUM_SCALAR >
222 template <
typename GUM_SCALAR >
225 if (this->
__bn !=
nullptr) {
237 template <
typename GUM_SCALAR >
255 template <
typename GUM_SCALAR >
258 const std::string& nodeName) {
265 template <
typename GUM_SCALAR >
273 template <
typename GUM_SCALAR >
276 return H(this->
BN().idFromName(nodeName));
280 template <
typename GUM_SCALAR >
284 const auto& vtarget = this->
BN().variable(target);
288 "Target <" << vtarget.name() <<
"> (" << target
289 <<
") can not be in evs (" << evs <<
").");
291 auto condset = this->
BN().minimalCondSet(target, evs);
296 res.
add(this->
BN().variable(target));
298 for (
const auto& n : condset) {
299 res.
add(this->
BN().variable(n));
306 for (
const auto& n : condset)
320 template <
typename GUM_SCALAR >
322 const std::string& target,
const std::vector< std::string >& evs) {
323 const auto& bn = this->
BN();
326 for (
const auto& evname : evs) {
327 evsId.
insert(bn.idFromName(evname));
334 template <
typename GUM_SCALAR >
338 template <
typename GUM_SCALAR >
void __setBayesNetDuringConstruction(const IBayesNet< GUM_SCALAR > *bn)
assigns a BN during the inference engine construction
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
aGrUM's Potential is a multi-dimensional array with tensor operators.
virtual void __setState(const StateOfInference state) final
set the state of the inference engine and call the notification _onStateChanged when necessary (i...
virtual void _onBayesNetChanged(const IBayesNet< GUM_SCALAR > *bn)
fired after a new Bayes net has been assigned to the engine
virtual GUM_SCALAR H(NodeId X) final
Entropy Compute Shanon's entropy of a node given the observation.
NodeSet __targets
the set of marginal targets
const NodeProperty< const Potential< GUM_SCALAR > *> & evidence() const
returns the set of evidence
virtual void eraseTarget(NodeId target) final
removes an existing (marginal) target
virtual void _onMarginalTargetAdded(const NodeId id)=0
fired after a new marginal target is inserted
virtual const Size nbrTargets() const noexcept final
returns the number of marginal targets
const IBayesNet< GUM_SCALAR > * __bn
the Bayes net on which we perform inferences
virtual bool isTarget(NodeId node) const final
return true if variable is a (marginal) target
void erase(const Key &k)
Erases an element from the set.
<agrum/BN/inference/marginalTargetedInference.h>
void incNotVar(const DiscreteVariable &v)
Operator increment for vars which are not v.
Class representing the minimal interface for Bayesian Network.
gum is the global namespace for all aGrUM entities
void incVar(const DiscreteVariable &v)
Operator increment for variable v only.
virtual void _onAllMarginalTargetsErased()=0
fired before a all marginal targets are removed
Idx val(Idx i) const
Returns the current value of the variable at position i.
virtual void makeInference() final
perform the heavy computations needed to compute the targets' posteriors
virtual void addTarget(NodeId target) final
Add a marginal target to the list of targets.
void __setAllMarginalTargets()
sets all the nodes of the Bayes net as targets
<agrum/BN/inference/BayesNetInference.h>
virtual void addAllTargets() final
adds all nodes as targets
void setFirstVar(const DiscreteVariable &v)
Assign the first value in the Instantiation for var v.
virtual void chgEvidence(NodeId id, const Idx val) final
change the value of an already existing hard evidence
virtual bool isDone() const noexcept final
returns whether the inference object is in a done state
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
virtual void eraseAllEvidence() final
removes all the evidence entered into the network
virtual const Potential< GUM_SCALAR > & posterior(NodeId node)
Computes and returns the posterior of a node.
const NodeSet & hardEvidenceNodes() const
returns the set of nodes with hard evidence
Class for assigning/browsing values to tuples of discrete variables.
virtual void _onMarginalTargetErased(const NodeId id)=0
fired before a marginal target is removed
virtual void add(const DiscreteVariable &v) final
Adds a new var to the variables of the multidimensional matrix.
Potential< GUM_SCALAR > evidenceImpact(NodeId target, const NodeSet &evs)
Create a gum::Potential for P(target|evs) (for all instanciation of target and evs) ...
virtual void _onAllMarginalTargetsAdded()=0
fired after all the nodes of the BN are added as marginal targets
virtual void set(const Instantiation &i, const GUM_SCALAR &value) const final
Default implementation of MultiDimContainer::set().
void setFirst()
Assign the first values to the tuple of the Instantiation.
virtual const Potential< GUM_SCALAR > & _posterior(NodeId id)=0
asks derived classes for the posterior of a given variable
virtual const NodeSet & targets() const noexcept final
returns the list of marginal targets
virtual void eraseAllTargets()
Clear all previously defined targets.
void clear()
Removes all the elements, if any, from the set.
bool _isTargetedMode() const
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size size() const noexcept
Returns the number of elements in the set.
bool __targeted_mode
whether the actual targets are default
virtual ~MarginalTargetedInference()
destructor
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Size NodeId
Type for node ids.
void insert(const Key &k)
Inserts a new element into the set.
#define GUM_ERROR(type, msg)
MarginalTargetedInference(const IBayesNet< GUM_SCALAR > *bn)
default constructor
bool end() const
Returns true if the Instantiation reached the end.