42#ifndef __INFERENCE_ENGINE__H__
43#define __INFERENCE_ENGINE__H__
71 template <
typename GUM_SCALAR >
252 const std::vector< GUM_SCALAR >& vertex,
253 const bool& elimRedund =
false);
370 virtual void addEvidence(
const std::string& nodeName,
const Idx val)
final;
386 virtual void addEvidence(
const std::string& nodeName,
const std::string& label)
final;
396 virtual void addEvidence(
NodeId id,
const std::vector< GUM_SCALAR >& vals)
final;
406 virtual void addEvidence(
const std::string& nodeName,
407 const std::vector< GUM_SCALAR >& vals)
final;
418 virtual void addEvidence(
const Tensor< GUM_SCALAR >& pot)
final;
436 void insertModals(
const std::map< std::string, std::vector< GUM_SCALAR > >& modals);
448 void insertEvidence(
const std::map< std::string, std::vector< GUM_SCALAR > >& eviMap);
492 Tensor< GUM_SCALAR >
marginalMin(
const std::string& varName)
const;
499 Tensor< GUM_SCALAR >
marginalMax(
const std::string& varName)
const;
520 const GUM_SCALAR&
expectationMin(
const std::string& varName)
const;
527 const GUM_SCALAR&
expectationMax(
const std::string& varName)
const;
540 const std::vector< GUM_SCALAR >&
dynamicExpMin(
const std::string& varName)
const;
553 const std::vector< GUM_SCALAR >&
dynamicExpMax(
const std::string& varName)
const;
560 const std::vector< std::vector< GUM_SCALAR > >&
vertices(
const NodeId id)
const;
604#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
605 extern template class InferenceEngine< double >;
This file contains general scheme for iteratively convergent algorithms.
ApproximationScheme(bool verbosity=false)
The class for generic Hash Tables.
std::string messageApproximationScheme() const
Returns the approximation scheme message.
ThreadNumberManager(Size nb_threads=0)
default constructor
Class template representing a Credal Network.
void updateExpectations_(const NodeId &id, const std::vector< GUM_SCALAR > &vertex)
Given a node id and one of it's possible vertex obtained during inference, update this node lower and...
void repetitiveInit_()
Initialize t0_ and t1_ clusters.
void dynamicExpectations()
Compute dynamic expectations.
void saveVertices(const std::string &path) const
Saves vertices to file.
margi oldMarginalMax_
Old upper marginals used to compute epsilon.
const std::vector< GUM_SCALAR > & dynamicExpMin(const std::string &varName) const
Get the lower dynamic expectation of a given variable prefix (without the time step included,...
const std::string getApproximationSchemeMsg()
Get approximation scheme state.
margi evidence_
Holds observed variables states.
virtual void insertEvidenceFile(const std::string &path)
Insert evidence from file.
virtual void makeInference()=0
To be redefined by each credal net algorithm.
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.
margi marginalMax_
Upper marginals.
NodeProperty< GUM_SCALAR > expe
void initExpectations_()
Initialize lower and upper expectations before inference, with the lower expectation being initialize...
void updateCredalSets_(const NodeId &id, const std::vector< GUM_SCALAR > &vertex, const bool &elimRedund=false)
Given a node id and one of it's possible vertex, update it's credal set.
bool repetitiveInd_
True if using repetitive independence ( dynamic network only ), False otherwise.
const NodeProperty< std::vector< NodeId > > & getT1Cluster() const
Get the t1_ cluster.
void displatchMarginalsToThreads_()
computes Vector threadRanges_, that assigns some part of marginalMin_ and marginalMax_ to the threads
NodeProperty< std::vector< NodeId > > cluster
typename gum::HashTable< std::string, std::vector< GUM_SCALAR > > dynExpe
void saveExpectations(const std::string &path) const
Saves expectations to file.
virtual const GUM_SCALAR computeEpsilon_()
Compute approximation scheme epsilon using the old marginals and the new ones.
void saveMarginals(const std::string &path) const
Saves marginals to file.
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.
void initMarginalSets_()
Initialize credal set vertices with empty sets.
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(const std::string &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.
NodeProperty< std::vector< bool > > query
void dynamicExpectations_()
Rearrange lower and upper expectations to suit dynamic networks.
bool storeVertices() const
Get the number of iterations without changes used to stop some algorithms.
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
void insertModalsFile(const std::string &path)
Insert variables modalities from file to compute expectations.
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.
void insertQueryFile(const std::string &path)
Insert query variables states 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.
virtual ~InferenceEngine()
Destructor.
const CredalNet< GUM_SCALAR > & credalNet() const
Get this creadal 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 usefull 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.
void initMarginals_()
Initialize lower and upper old marginals and marginals before inference, with the lower marginal bein...
VarMod2BNsMap< GUM_SCALAR > dbnOpt_
Object used to efficiently store optimal bayes net during inference, for some algorithms.
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.