57 template < GUM_Numeric GUM_SCALAR >
73 template < GUM_Numeric GUM_SCALAR >
79 template < GUM_Numeric GUM_SCALAR >
90 template < GUM_Numeric GUM_SCALAR >
95 "No Markov net has been assigned to the "
96 "inference algorithm");
97 if (!this->
MRF().internalGraph().exists(node)) {
105 template < GUM_Numeric GUM_SCALAR >
111 template < GUM_Numeric GUM_SCALAR >
122 template < GUM_Numeric GUM_SCALAR >
127 "No Markov net has been assigned to the "
128 "inference algorithm");
130 if (!this->
MRF().internalGraph().exists(target)) {
144 template < GUM_Numeric GUM_SCALAR >
149 "No Markov net has been assigned to the "
150 "inference algorithm");
154 for (
const auto target: this->
MRF().internalGraph()) {
164 template < GUM_Numeric GUM_SCALAR >
169 "No Markov net has been assigned to the "
170 "inference algorithm");
176 template < GUM_Numeric GUM_SCALAR >
181 "No Markov net has been assigned to the "
182 "inference algorithm");
184 if (!this->
MRF().internalGraph().exists(target)) {
199 template < GUM_Numeric GUM_SCALAR >
204 "No Markov net has been assigned to the "
205 "inference algorithm");
211 template < GUM_Numeric GUM_SCALAR >
217 template < GUM_Numeric GUM_SCALAR >
223 template < GUM_Numeric GUM_SCALAR >
237 template < GUM_Numeric GUM_SCALAR >
252 template < GUM_Numeric GUM_SCALAR >
253 const Tensor< GUM_SCALAR >&
261 template < GUM_Numeric GUM_SCALAR >
269 template < GUM_Numeric GUM_SCALAR >
271 return H(this->
MRF().idFromName(nodeName));
274 template < GUM_Numeric GUM_SCALAR >
278 const auto& vtarget = this->
MRF().variable(target);
282 "Target <" << vtarget.name() <<
"> (" << target <<
") can not be in evs (" << evs
285 auto condset = this->
MRF().minimalCondSet(target, evs);
287 Tensor< GUM_SCALAR > res;
290 res.add(this->
MRF().variable(target));
292 for (
const auto& n: condset) {
293 res.add(this->
MRF().variable(n));
300 for (
const auto& n: condset)
305 res.set(inst, this->
posterior(target)[inst]);
313 template < GUM_Numeric GUM_SCALAR >
315 std::string_view target,
316 const std::vector< std::string >& evs) {
317 const auto& mn = this->
MRF();
321 template < GUM_Numeric GUM_SCALAR >
326 template < GUM_Numeric GUM_SCALAR >
virtual void chgEvidence(NodeId id, const Idx val) final
change the value of an already existing hard evidence
virtual bool isInferenceDone() const noexcept final
returns whether the inference object is in a InferenceDone state
const NodeProperty< const Tensor< GUM_SCALAR > * > & evidence() const
returns the set of evidence
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i....
const NodeSet & hardEvidenceNodes() const
returns the set of nodes with hard evidence
virtual void eraseAllEvidence() final
removes all the evidence entered into the network
virtual void makeInference() final
perform the heavy computations needed to compute the targets' posteriors
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
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 setFirstVar(const DiscreteVariable &v)
Assign the first value in the Instantiation for var v.
void incNotVar(const DiscreteVariable &v)
Operator increment for vars which are not 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.
MRFInference(const IMarkovRandomField< GUM_SCALAR > *mn)
default constructor
void _setMRFDuringConstruction_(const IMarkovRandomField< GUM_SCALAR > *mn)
assigns a MRF during the inference engine construction
virtual const IMarkovRandomField< GUM_SCALAR > & MRF() const final
Returns a constant reference over the IMarkovRandomField referenced by this class.
virtual const NodeSet & targets() const noexcept final
returns the list of marginal targets
void _setAllMarginalTargets_()
sets all the nodes of the Markov net as targets
virtual Size nbrTargets() const noexcept final
returns the number of marginal targets
~MarginalTargetedMRFInference() override
destructor
void onModelChanged_(const GraphicalModel *mn) override
fired after a new Markov net has been assigned to the engine
bool isTargetedMode_() const
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
bool _targeted_mode_
whether the actual targets are default
virtual void onAllMarginalTargetsErased_()=0
fired before a all marginal targets are removed
NodeSet _targets_
the set of marginal targets
virtual GUM_SCALAR H(NodeId X) final
Entropy Compute Shanon's entropy of a node given the observation.
virtual void eraseTarget(NodeId target) final
removes an existing (marginal) target
virtual void eraseAllTargets()
Clear all previously defined targets.
Tensor< GUM_SCALAR > evidenceImpact(NodeId target, const NodeSet &evs)
Create a gum::Tensor for P(target|evs) (for all instantiation of target and evs).
virtual void addAllTargets() final
adds all nodes as targets
MarginalTargetedMRFInference(const IMarkovRandomField< GUM_SCALAR > *mn)
default constructor
virtual void addTarget(NodeId target) final
Add a marginal target to the list of targets.
virtual bool isTarget(NodeId node) const final
return true if variable is a (marginal) target
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.
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.
UndiGraph graph() const
Returns a named copy of the internal undirected graph: each node id is assigned the name of the corre...
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 ...
bool contains(std::string_view s, std::string_view needle)
true if needle in s
This file contains the abstract inference class definition for computing (incrementally) marginal pos...
gum is the global namespace for all aGrUM entities