34 template <
typename GUM_SCALAR >
39 if (this->
__bn ==
nullptr) {
54 template <
typename GUM_SCALAR >
61 template <
typename GUM_SCALAR >
74 template <
typename GUM_SCALAR >
78 if (this->
__bn ==
nullptr)
80 "No Bayes net has been assigned to the " 81 "inference algorithm");
82 if (!this->
__bn->dag().exists(node)) {
90 template <
typename GUM_SCALAR >
92 const std::string& nodeName)
const {
98 template <
typename GUM_SCALAR >
111 template <
typename GUM_SCALAR >
114 if (this->
__bn ==
nullptr)
116 "No Bayes net has been assigned to the " 117 "inference algorithm");
119 if (!this->
__bn->dag().exists(target)) {
135 template <
typename GUM_SCALAR >
138 if (this->
__bn ==
nullptr)
140 "No Bayes net has been assigned to the " 141 "inference algorithm");
145 for (
const auto target : this->
__bn->dag()) {
157 template <
typename GUM_SCALAR >
159 const std::string& nodeName) {
161 if (this->
__bn ==
nullptr)
163 "No Bayes net has been assigned to the " 164 "inference algorithm");
171 template <
typename GUM_SCALAR >
174 if (this->
__bn ==
nullptr)
176 "No Bayes net has been assigned to the " 177 "inference algorithm");
179 if (!this->
__bn->dag().exists(target)) {
196 template <
typename GUM_SCALAR >
198 const std::string& nodeName) {
200 if (this->
__bn ==
nullptr)
202 "No Bayes net has been assigned to the " 203 "inference algorithm");
210 template <
typename GUM_SCALAR >
217 template <
typename GUM_SCALAR >
225 template <
typename GUM_SCALAR >
228 if (this->
__bn !=
nullptr) {
240 template <
typename GUM_SCALAR >
258 template <
typename GUM_SCALAR >
261 const std::string& nodeName) {
268 template <
typename GUM_SCALAR >
276 template <
typename GUM_SCALAR >
279 return H(this->
BN().idFromName(nodeName));
283 template <
typename GUM_SCALAR >
287 const auto& vtarget = this->
BN().variable(target);
291 "Target <" << vtarget.name() <<
"> (" << target
292 <<
") can not be in evs (" << evs <<
").");
294 auto condset = this->
BN().minimalCondSet(target, evs);
299 res.
add(this->
BN().variable(target));
301 for (
const auto& n : condset) {
302 res.
add(this->
BN().variable(n));
309 for (
const auto& n : condset)
323 template <
typename GUM_SCALAR >
325 const std::string& target,
const std::vector< std::string >& evs) {
326 const auto& bn = this->
BN();
329 for (
const auto& evname : evs) {
330 evsId.
insert(bn.idFromName(evname));
337 template <
typename GUM_SCALAR >
341 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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.