54 template <
typename GUM_SCALAR >
70 template <
typename GUM_SCALAR >
76 template <
typename GUM_SCALAR >
87 template <
typename GUM_SCALAR >
92 "No Markov net has been assigned to the "
93 "inference algorithm");
94 if (!this->
MRF().graph().exists(node)) {
102 template <
typename GUM_SCALAR >
109 template <
typename GUM_SCALAR >
120 template <
typename GUM_SCALAR >
125 "No Markov net has been assigned to the "
126 "inference algorithm");
128 if (!this->
MRF().graph().exists(target)) {
142 template <
typename GUM_SCALAR >
147 "No Markov net has been assigned to the "
148 "inference algorithm");
152 for (
const auto target: this->
MRF().graph()) {
162 template <
typename GUM_SCALAR >
167 "No Markov net has been assigned to the "
168 "inference algorithm");
174 template <
typename GUM_SCALAR >
179 "No Markov net has been assigned to the "
180 "inference algorithm");
182 if (!this->
MRF().graph().exists(target)) {
197 template <
typename GUM_SCALAR >
202 "No Markov net has been assigned to the "
203 "inference algorithm");
209 template <
typename GUM_SCALAR >
215 template <
typename GUM_SCALAR >
221 template <
typename GUM_SCALAR >
235 template <
typename GUM_SCALAR >
250 template <
typename GUM_SCALAR >
251 const Tensor< GUM_SCALAR >&
259 template <
typename GUM_SCALAR >
267 template <
typename GUM_SCALAR >
269 return H(this->
MRF().idFromName(nodeName));
272 template <
typename GUM_SCALAR >
276 const auto& vtarget = this->
MRF().variable(target);
280 "Target <" << vtarget.name() <<
"> (" << target <<
") can not be in evs (" << evs
283 auto condset = this->
MRF().minimalCondSet(target, evs);
285 Tensor< GUM_SCALAR > res;
288 res.add(this->
MRF().variable(target));
290 for (
const auto& n: condset) {
291 res.add(this->
MRF().variable(n));
298 for (
const auto& n: condset)
303 res.set(inst, this->
posterior(target)[inst]);
311 template <
typename GUM_SCALAR >
313 const std::string& target,
314 const std::vector< std::string >& evs) {
315 const auto& mn = this->
MRF();
319 template <
typename GUM_SCALAR >
324 template <
typename GUM_SCALAR >
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 Markov random field.
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.
virtual const IMarkovRandomField< GUM_SCALAR > & MRF() const final
Returns a constant reference over the IMarkovRandomField referenced by this class.
MRFInference(const IMarkovRandomField< GUM_SCALAR > *mn)
default constructor
void _setMRFDuringConstruction_(const IMarkovRandomField< GUM_SCALAR > *mn)
assigns a MRF during the inference engine construction
void _setAllMarginalTargets_()
sets all the nodes of the Markov net as targets
virtual void onAllMarginalTargetsAdded_()=0
fired after all the nodes of the MRF are added as marginal targets
virtual void onMarginalTargetErased_(const NodeId id)=0
fired before a marginal target is removed
virtual bool isTarget(NodeId node) const final
return true if variable is a (marginal) target
bool _targeted_mode_
whether the actual targets are default
virtual void onAllMarginalTargetsErased_()=0
fired before a all marginal targets are removed
bool isTargetedMode_() const
virtual ~MarginalTargetedMRFInference()
destructor
virtual const NodeSet & targets() const noexcept final
returns the list of marginal targets
NodeSet _targets_
the set of marginal targets
virtual void eraseTarget(NodeId target) final
removes an existing (marginal) target
Tensor< GUM_SCALAR > evidenceImpact(NodeId target, const NodeSet &evs)
Create a gum::Tensor for P(target|evs) (for all instanciation of target and evs).
virtual void addAllTargets() final
adds all nodes as targets
virtual void onModelChanged_(const GraphicalModel *mn)
fired after a new Markov net has been assigned to the engine
MarginalTargetedMRFInference(const IMarkovRandomField< GUM_SCALAR > *mn)
default constructor
virtual void addTarget(NodeId target) final
Add a marginal target to the list of targets.
virtual void onMarginalTargetAdded_(const NodeId id)=0
fired after a new marginal target is inserted
virtual const Tensor< GUM_SCALAR > & posterior_(NodeId id)=0
asks derived classes for the posterior of a given variable
virtual const Tensor< GUM_SCALAR > & posterior(NodeId node)
Computes and returns the posterior of a node.
virtual GUM_SCALAR H(NodeId X) final
Entropy Compute Shanon's entropy of a node given the observation.
virtual void eraseAllTargets()
Clear all previously defined targets.
virtual Size nbrTargets() const noexcept final
returns the number of marginal targets
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.
const UndiGraph & graph() const
Returns a constant reference to the dag of this Bayes Net.
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