54 template <
typename GUM_SCALAR >
72 template <
typename GUM_SCALAR >
78 template <
typename GUM_SCALAR >
89 template <
typename GUM_SCALAR >
94 "No Bayes net has been assigned to the "
95 "inference algorithm");
96 if (!this->
BN().dag().exists(node)) {
104 template <
typename GUM_SCALAR >
106 return isTarget(this->
BN().idFromName(nodeName));
110 template <
typename GUM_SCALAR >
121 template <
typename GUM_SCALAR >
126 "No Bayes net has been assigned to the "
127 "inference algorithm");
129 if (!this->
BN().dag().exists(target)) {
143 template <
typename GUM_SCALAR >
148 "No Bayes net has been assigned to the "
149 "inference algorithm");
153 for (
const auto target: this->
BN().dag()) {
163 template <
typename GUM_SCALAR >
168 "No Bayes net has been assigned to the "
169 "inference algorithm");
175 template <
typename GUM_SCALAR >
180 "No Bayes net has been assigned to the "
181 "inference algorithm");
183 if (!this->
BN().dag().exists(target)) {
198 template <
typename GUM_SCALAR >
203 "No Bayes net has been assigned to the "
204 "inference algorithm");
210 template <
typename GUM_SCALAR >
216 template <
typename GUM_SCALAR >
222 template <
typename GUM_SCALAR >
228 template <
typename GUM_SCALAR >
242 template <
typename GUM_SCALAR >
257 template <
typename GUM_SCALAR >
258 const Tensor< GUM_SCALAR >&
266 template <
typename GUM_SCALAR >
274 template <
typename GUM_SCALAR >
276 return H(this->
BN().idFromName(nodeName));
279 template <
typename GUM_SCALAR >
282 const auto& vtarget = this->
BN().variable(target);
286 "Target <" << vtarget.name() <<
"> (" << target <<
") can not be in evs (" << evs
289 auto condset = this->
BN().minimalCondSet(target, evs);
291 Tensor< GUM_SCALAR > res;
294 res.add(this->
BN().variable(target));
296 for (
const auto& n: condset) {
297 res.add(this->
BN().variable(n));
304 for (
const auto& n: condset)
308 const auto& pot = this->
posterior(target);
310 res.set(inst, pot[inst]);
318 template <
typename GUM_SCALAR >
320 const std::string& target,
321 const std::vector< std::string >& evs) {
322 const auto& bn = this->
BN();
326 template <
typename GUM_SCALAR >
331 template <
typename GUM_SCALAR >
void _setBayesNetDuringConstruction_(const IBayesNet< GUM_SCALAR > *bn)
assigns a BN during the inference engine construction
BayesNetInference(const IBayesNet< GUM_SCALAR > *bn)
default constructor
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.
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i....
virtual void chgEvidence(NodeId id, const Idx val) final
change the value of an already existing hard evidence
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
const NodeSet & hardEvidenceNodes() const
returns the set of nodes with hard evidence
const NodeProperty< const Tensor< GUM_SCALAR > * > & evidence() const
returns the set of evidence
virtual void makeInference() final
perform the heavy computations needed to compute the targets' posteriors
virtual bool isInferenceDone() const noexcept final
returns whether the inference object is in a InferenceDone state
Virtual base class for probabilistic graphical models.
Class representing the minimal interface for Bayesian network with no numerical data.
Class for assigning/browsing values to tuples of discrete variables.
bool end() const
Returns true if the Instantiation reached the end.
void incVar(const DiscreteVariable &v)
Operator increment for variable v only.
void incNotVar(const DiscreteVariable &v)
Operator increment for vars which are not v.
void setFirstVar(const DiscreteVariable &v)
Assign the first value in the Instantiation for var v.
Idx val(Idx i) const
Returns the current value of the variable at position i.
void setFirst()
Assign the first values to the tuple of the Instantiation.
Exception: at least one argument passed to a function is not what was expected.
NodeSet _targets_
the set of marginal targets
virtual Size nbrTargets() const noexcept final
returns the number of marginal targets
virtual bool isInTargetMode() const noexcept final
indicates whether the inference is in a target mode
bool isTargetedMode_() const
virtual const Tensor< GUM_SCALAR > & posterior(NodeId node)
Computes and returns the posterior of a node.
virtual void eraseTarget(NodeId target) final
removes an existing (marginal) target
virtual void onAllMarginalTargetsErased_()=0
fired before a all marginal targets are removed
void _setAllMarginalTargets_()
sets all the nodes of the Bayes net as targets
virtual const Tensor< GUM_SCALAR > & posterior_(NodeId id)=0
asks derived classes for the posterior of a given variable
virtual void onMarginalTargetErased_(const NodeId id)=0
fired before a marginal target is removed
virtual void eraseAllTargets()
Clear all previously defined targets.
virtual void onAllMarginalTargetsAdded_()=0
fired after all the nodes of the BN are added as marginal targets
virtual GUM_SCALAR H(NodeId X) final
Entropy Compute Shanon's entropy of a node given the observation.
bool _targeted_mode_
whether the actual targets are default
virtual const NodeSet & targets() const noexcept final
returns the list of marginal targets
MarginalTargetedInference(const IBayesNet< GUM_SCALAR > *bn)
default constructor
virtual bool isTarget(NodeId node) const final
return true if variable is a (marginal) target
virtual void addTarget(NodeId target) final
Add a marginal target to the list of targets.
virtual void addAllTargets() final
adds all nodes as targets
virtual void onModelChanged_(const GraphicalModel *bn)
fired after a new Bayes net has been assigned to the engine
virtual void onMarginalTargetAdded_(const NodeId id)=0
fired after a new marginal target is inserted
virtual ~MarginalTargetedInference()
destructor
Tensor< GUM_SCALAR > evidenceImpact(NodeId target, const NodeSet &evs)
Create a gum::Tensor for P(target|evs) (for all instanciation of target and evs).
NodeSet asNodeSet() const
returns a copy of the set of nodes represented by the NodeGraphPart
Exception : a pointer or a reference on a nullptr (0) object.
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Exception : a looked-for element could not be found.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size NodeId
Type for node ids.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
gum is the global namespace for all aGrUM entities