28 #ifndef AGRUM_GRAPHICALMODELINFERENCE_H 29 #define AGRUM_GRAPHICALMODELINFERENCE_H 32 #include <agrum/tools/graphicalModels/graphicalModel.h> 33 #include <agrum/tools/multidim/potential.h> 34 #include <agrum/agrum.h> 83 template <
typename GUM_SCALAR >
181 virtual void clear();
199 virtual void addEvidence(NodeId id,
const Idx val)
final;
207 virtual void addEvidence(
const std::string& nodeName,
const Idx val)
final;
215 virtual void addEvidence(NodeId id,
const std::string& label)
final;
223 virtual void addEvidence(
const std::string& nodeName,
224 const std::string& label)
final;
235 const std::vector< GUM_SCALAR >& vals)
final;
245 virtual void addEvidence(
const std::string& nodeName,
246 const std::vector< GUM_SCALAR >& vals)
final;
257 virtual void addEvidence(
const Potential< GUM_SCALAR >& pot)
final;
268 virtual void addEvidence(Potential< GUM_SCALAR >&& pot)
final;
280 addSetOfEvidence(
const Set<
const Potential< GUM_SCALAR >* >& potset)
final;
292 const List<
const Potential< GUM_SCALAR >* >& potlist)
final;
300 virtual void chgEvidence(NodeId id,
const Idx val)
final;
308 virtual void chgEvidence(
const std::string& nodeName,
const Idx val)
final;
316 virtual void chgEvidence(NodeId id,
const std::string& label)
final;
324 virtual void chgEvidence(
const std::string& nodeName,
325 const std::string& label)
final;
336 const std::vector< GUM_SCALAR >& vals)
final;
346 virtual void chgEvidence(
const std::string& nodeName,
347 const std::vector< GUM_SCALAR >& vals)
final;
358 virtual void chgEvidence(
const Potential< GUM_SCALAR >& pot)
final;
367 virtual void eraseEvidence(
const std::string& nodeName)
final;
382 virtual bool hasEvidence(
const std::string& nodeName)
const final;
528 void setModel_(
const GraphicalModel* model);
537 #include <agrum/tools/graphicalModels/inference/graphicalModelInference_tpl.h> virtual void prepareInference() final
prepare the internal inference structures for the next inference
virtual const NodeProperty< Size > & domainSizes() const final
get the domain sizes of the random variables of the model
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
virtual void updateOutdatedPotentials_()=0
prepares inference when the latter is in OutdatedPotentials state
virtual void onAllEvidenceErased_(bool contains_hard_evidence)=0
fired before all the evidence are erased
GraphicalModelInference()
default constructor with a null model (useful for virtual inheritance)
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(const std::string &nodeName, const std::vector< GUM_SCALAR > &vals) final
change the value of an already existing evidence (might be soft or hard)
virtual void updateOutdatedStructure_()=0
prepares inference when the latter is in OutdatedStructure state
virtual bool hasHardEvidence(const std::string &nodeName) const final
indicates whether node id has received a hard evidence
void computeDomainSizes__()
computes the domain sizes of the random variables
virtual void eraseEvidence(const std::string &nodeName) final
removed the evidence, if any, corresponding to node of name nodeName
const NodeSet & hardEvidenceNodes() const
returns the set of nodes with hard evidence
void setOutdatedStructureState_()
put the inference into an outdated model structure state
INLINE void emplace(Args &&... args)
virtual bool hasHardEvidence(NodeId id) const final
indicates whether node id has received a hard evidence
virtual void onEvidenceAdded_(const NodeId id, bool isHardEvidence)=0
fired after a new evidence is inserted
virtual void addListOfEvidence(const List< const Potential< GUM_SCALAR > * > &potlist) final
adds a new list of evidence
virtual void addEvidence(const std::string &nodeName, const std::vector< GUM_SCALAR > &vals) final
adds a new evidence on node named nodeName (might be soft or hard)
virtual ~GraphicalModelInference()
destructor
virtual bool hasSoftEvidence(const std::string &nodeName) const final
indicates whether node id has received a soft evidence
NodeSet hard_evidence_nodes__
the set of nodes that received hard evidence
bool isHardEvidence__(const Potential< GUM_SCALAR > &pot, Idx &val) const
checks whether a potential corresponds to a hard evidence or not
virtual void onEvidenceChanged_(const NodeId id, bool hasChangedSoftHard)=0
fired after an evidence is changed, in particular when its status (soft/hard) changes ...
virtual bool isInferenceDone() const noexcept final
returns whether the inference object is in a InferenceDone state
virtual void addSetOfEvidence(const Set< const Potential< GUM_SCALAR > * > &potset) final
adds a new set of evidence
virtual bool hasEvidence(const std::string &nodeName) const final
indicates whether node id has received an evidence
virtual void onModelChanged_(const GraphicalModel *model)=0
fired after a new Bayes net has been assigned to the engine
virtual bool hasEvidence() const final
indicates whether some node(s) have received evidence
void setModelDuringConstruction_(const GraphicalModel *model)
assigns a model during the inference engine construction
GraphicalModelInference(const GraphicalModel *model)
default constructor
virtual StateOfInference state() const noexcept final
returns the state of the inference engine
Potential< GUM_SCALAR > createHardEvidence__(NodeId id, Idx val) const
create the internal structure for a hard evidence
NodeSet soft_evidence_nodes__
the set of nodes that received soft evidence
virtual bool hasSoftEvidence(NodeId id) const final
indicates whether node id has received a soft evidence
StateOfInference
current state of the inference
StateOfInference state__
the current state of the inference (outdated/ready/done)
virtual const GraphicalModel & model() const final
Returns a constant reference over the IBayesNet referenced by this class.
virtual void addEvidence(const Potential< GUM_SCALAR > &pot) final
adds a new evidence on node id (might be soft or hard)
virtual void onStateChanged_()=0
fired when the stage is changed
virtual void chgEvidence(NodeId id, const std::vector< GUM_SCALAR > &vals) final
change the value of an already existing evidence (might be soft or hard)
void setModel_(const GraphicalModel *model)
virtual void makeInference_()=0
called when the inference has to be performed effectively
virtual void onEvidenceErased_(const NodeId id, bool isHardEvidence)=0
fired before an evidence is removed
virtual void addEvidence(Potential< GUM_SCALAR > &&pot) final
adds a new evidence on node id (might be soft or hard)
virtual void chgEvidence(const std::string &nodeName, const Idx val) final
change the value of an already existing hard evidence
virtual void addEvidence(NodeId id, const std::vector< GUM_SCALAR > &vals) final
adds a new evidence on node id (might be soft or hard)
virtual void addEvidence(const std::string &nodeName, const Idx val) final
adds a new hard evidence on node named nodeName
virtual void eraseEvidence(NodeId id) final
removed the evidence, if any, corresponding to node id
const NodeSet & softEvidenceNodes() const
returns the set of nodes with soft evidence
virtual Size nbrHardEvidence() const final
returns the number of hard evidence entered into the Bayesian network
virtual bool hasEvidence(NodeId id) const final
indicates whether node id has received an evidence
virtual bool isInferenceReady() const noexcept final
returns whether the inference object is in a ready state
NodeProperty< Size > domain_sizes__
the domain sizes of the random variables
virtual void chgEvidence(NodeId id, const Idx val) final
change the value of an already existing hard evidence
virtual void clear()
clears all the data structures allocated for the last inference
virtual void eraseAllEvidence() final
removes all the evidence entered into the network
virtual Size nbrSoftEvidence() const final
returns the number of soft evidence entered into the Bayesian network
virtual void chgEvidence(const Potential< GUM_SCALAR > &pot) final
change the value of an already existing evidence (might be soft or hard)
const GraphicalModel * model__
the Bayes net on which we perform inferences
void setOutdatedPotentialsState_()
puts the inference into an OutdatedPotentials state if it is not already in an OutdatedStructure stat...
NodeProperty< Idx > hard_evidence__
assign to each node with a hard evidence the index of its observed value
NodeProperty< const Potential< GUM_SCALAR > *> evidence__
the set of evidence entered into the network
const NodeProperty< Idx > & hardEvidence() const
indicate for each node with hard evidence which value it took
const NodeProperty< const Potential< GUM_SCALAR > *> & evidence() const
returns the set of evidence
<agrum/tools/graphicalModels/graphicalModel.h>
virtual bool isInferenceOutdatedStructure() const noexcept final
returns whether the inference object is in a OutdatedStructure state
virtual void makeInference() final
perform the heavy computations needed to compute the targets' posteriors
virtual Size nbrEvidence() const final
returns the number of evidence entered into the Bayesian network
virtual bool isInferenceOutdatedPotentials() const noexcept final
returns whether the inference object is in a OutdatedPotential state