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,
const std::string& label)
final;
233 virtual void addEvidence(NodeId id,
const std::vector< GUM_SCALAR >& vals)
final;
243 virtual void addEvidence(
const std::string& nodeName,
244 const std::vector< GUM_SCALAR >& vals)
final;
255 virtual void addEvidence(
const Potential< GUM_SCALAR >& pot)
final;
266 virtual void addEvidence(Potential< GUM_SCALAR >&& pot)
final;
277 virtual void addSetOfEvidence(
const Set<
const Potential< GUM_SCALAR >* >& potset)
final;
288 virtual void addListOfEvidence(
const List<
const Potential< GUM_SCALAR >* >& potlist)
final;
296 virtual void chgEvidence(NodeId id,
const Idx val)
final;
304 virtual void chgEvidence(
const std::string& nodeName,
const Idx val)
final;
312 virtual void chgEvidence(NodeId id,
const std::string& label)
final;
320 virtual void chgEvidence(
const std::string& nodeName,
const std::string& label)
final;
330 virtual void chgEvidence(NodeId id,
const std::vector< GUM_SCALAR >& vals)
final;
340 virtual void chgEvidence(
const std::string& nodeName,
341 const std::vector< GUM_SCALAR >& vals)
final;
352 virtual void chgEvidence(
const Potential< GUM_SCALAR >& pot)
final;
361 virtual void eraseEvidence(
const std::string& nodeName)
final;
376 virtual bool hasEvidence(
const std::string& nodeName)
const final;
522 void setModel_(
const GraphicalModel* model);
531 #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
Potential< GUM_SCALAR > _createHardEvidence_(NodeId id, Idx val) const
create the internal structure for a hard evidence
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
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
NodeProperty< const Potential< GUM_SCALAR > *> _evidence_
the set of evidence entered into the network
NodeProperty< Idx > _hard_evidence_
assign to each node with a hard evidence the index of its observed value
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
void _computeDomainSizes_()
computes the domain sizes of the random variables
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
virtual bool hasSoftEvidence(NodeId id) const final
indicates whether node id has received a soft evidence
StateOfInference
current state of the inference
NodeSet _hard_evidence_nodes_
the set of nodes that received hard evidence
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)
StateOfInference _state_
the current state of the inference (outdated/ready/done)
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)
NodeSet _soft_evidence_nodes_
the set of nodes that received soft evidence
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
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
NodeProperty< Size > _domain_sizes_
the domain sizes of the random variables
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
const GraphicalModel * _model_
the Bayes net on which we perform inferences
virtual void chgEvidence(const Potential< GUM_SCALAR > &pot) final
change the value of an already existing evidence (might be soft or hard)
void setOutdatedPotentialsState_()
puts the inference into an OutdatedPotentials state if it is not already in an OutdatedStructure stat...
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