42#ifndef GUM_INFERENCE_ENGINE_H
43#define GUM_INFERENCE_ENGINE_H
73 template < GUM_Numeric GUM_SCALAR >
189 void repetitiveInit_();
197 void initExpectations_();
204 void initMarginals_();
210 void dispatchMarginalsToThreads_();
215 void initMarginalSets_();
230 virtual const GUM_SCALAR computeEpsilon_();
240 inline void updateExpectations_(
const NodeId&
id,
const std::vector< GUM_SCALAR >& vertex);
253 inline void updateCredalSets_(
const NodeId&
id,
254 const std::vector< GUM_SCALAR >& vertex,
255 const bool& elimRedund =
false);
264 void dynamicExpectations_();
372 virtual void addEvidence(std::string_view nodeName,
const Idx val)
final;
388 virtual void addEvidence(std::string_view nodeName, std::string_view label)
final;
398 virtual void addEvidence(
NodeId id,
const std::vector< GUM_SCALAR >& vals)
final;
408 virtual void addEvidence(std::string_view nodeName,
409 const std::vector< GUM_SCALAR >& vals)
final;
420 virtual void addEvidence(
const Tensor< GUM_SCALAR >& pot)
final;
438 void insertModals(
const std::map< std::string, std::vector< GUM_SCALAR > >& modals);
450 void insertEvidence(
const std::map< std::string, std::vector< GUM_SCALAR > >& eviMap);
494 Tensor< GUM_SCALAR >
marginalMin(std::string_view varName)
const;
501 Tensor< GUM_SCALAR >
marginalMax(std::string_view varName)
const;
542 const std::vector< GUM_SCALAR >&
dynamicExpMin(std::string_view varName)
const;
555 const std::vector< GUM_SCALAR >&
dynamicExpMax(std::string_view varName)
const;
562 const std::vector< std::vector< GUM_SCALAR > >&
vertices(
const NodeId id)
const;
606#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
This file contains general scheme for iteratively convergent algorithms.
ApproximationScheme(bool verbosity=false)
The class for generic Hash Tables.
ThreadNumberManager(Size nb_threads=0)
default constructor
Class template representing a Credal Network.
Abstract class template representing a CredalNet inference engine.
void dynamicExpectations()
Compute dynamic expectations.
margi oldMarginalMax_
Old upper marginals used to compute epsilon.
const std::string getApproximationSchemeMsg()
Get approximation scheme state.
margi evidence_
Holds observed variables states.
virtual void makeInference()=0
To be redefined by each credal net algorithm.
const std::vector< GUM_SCALAR > & dynamicExpMin(std::string_view varName) const
Get the lower dynamic expectation of a given variable prefix (without the time step included,...
cluster t1_
Clusters of nodes used with dynamic networks.
dynExpe dynamicExpMin_
Lower dynamic expectations.
bool storeBNOpt_
Iterations limit stopping rule used by some algorithms such as CNMonteCarloSampling.
void saveExpectations(std::string_view path) const
Saves expectations to file.
margi marginalMax_
Upper marginals.
NodeProperty< GUM_SCALAR > expe
void insertModalsFile(std::string_view path)
Insert variables modalities from file to compute expectations.
void saveVertices(std::string_view path) const
Saves vertices to file.
void insertQueryFile(std::string_view path)
Insert query variables states from file.
bool repetitiveInd_
True if using repetitive independence ( dynamic network only ), False otherwise.
const NodeProperty< std::vector< NodeId > > & getT1Cluster() const
Get the t1_ cluster.
NodeProperty< std::vector< NodeId > > cluster
typename gum::HashTable< std::string, std::vector< GUM_SCALAR > > dynExpe
const std::vector< std::vector< GUM_SCALAR > > & vertices(const NodeId id) const
Get the vertice of a given node id.
InferenceEngine(const CredalNet< GUM_SCALAR > &credalNet)
Construtor.
margi oldMarginalMin_
Old lower marginals used to compute epsilon.
bool storeVertices_
True if credal sets vertices are stored, False otherwise.
dynExpe dynamicExpMax_
Upper dynamic expectations.
const std::vector< GUM_SCALAR > & dynamicExpMax(std::string_view varName) const
Get the upper dynamic expectation of a given variable prefix (without the time step included,...
NodeProperty< std::vector< std::vector< GUM_SCALAR > > > credalSet
std::string toString() const
Print all nodes marginals to standart output.
void insertQuery(const NodeProperty< std::vector< bool > > &query)
Insert query variables and states from Property.
bool repetitiveInd() const
Get the current independence status.
void storeVertices(const bool value)
NodeProperty< std::vector< bool > > query
const CredalNet< GUM_SCALAR > * credalNet_
A pointer to the Credal Net used.
void setRepetitiveInd(const bool repetitive)
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
virtual void eraseAllEvidence()
removes all the evidence entered into the network
NodeProperty< std::vector< GUM_SCALAR > > margi
expe expectationMax_
Upper expectations, if some variables modalities were inserted.
void insertEvidence(const std::map< std::string, std::vector< GUM_SCALAR > > &eviMap)
Insert evidence from map.
void insertModals(const std::map< std::string, std::vector< GUM_SCALAR > > &modals)
Insert variables modalities from map to compute expectations.
query query_
Holds the query nodes states.
virtual void insertEvidenceFile(std::string_view path)
Insert evidence from file.
credalSet marginalSets_
Credal sets vertices, if enabled.
Tensor< GUM_SCALAR > marginalMin(const NodeId id) const
Get the lower marginals of a given node id.
void saveMarginals(std::string_view path) const
Saves marginals to file.
const CredalNet< GUM_SCALAR > & credalNet() const
Get this credal network.
VarMod2BNsMap< GUM_SCALAR > * getVarMod2BNsMap()
Get optimum IBayesNet.
margi marginalMin_
Lower marginals.
cluster t0_
Clusters of nodes used with dynamic networks.
const GUM_SCALAR & expectationMin(const NodeId id) const
Get the lower expectation of a given node id.
dynExpe modal_
Variables modalities used to compute expectations.
expe expectationMin_
Lower expectations, if some variables modalities were inserted.
Tensor< GUM_SCALAR > marginalMax(const NodeId id) const
Get the upper marginals of a given node id.
const GUM_SCALAR & expectationMax(const NodeId id) const
Get the upper expectation of a given node id.
int timeSteps_
The number of time steps of this network (only useful for dynamic networks).
std::vector< std::pair< NodeId, Idx > > threadRanges_
the ranges of elements of marginalMin_ and marginalMax_ processed by each thread
const NodeProperty< std::vector< NodeId > > & getT0Cluster() const
Get the t0_ cluster.
VarMod2BNsMap< GUM_SCALAR > dbnOpt_
Object used to efficiently store optimal bayes net during inference, for some algorithms.
void storeBNOpt(const bool value)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
Size NodeId
Type for node ids.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Abstract class representing CredalNet inference engines.
namespace for all credal networks entities
gum is the global namespace for all aGrUM entities
A wrapper that enables to store data in a way that prevents false cacheline sharing.
A class to manage the number of threads to use in an algorithm.
Class used to store optimum IBayesNet during some inference algorithms.