42#ifndef GUM_CREDAL_NET_H
43#define GUM_CREDAL_NET_H
79typedef __int64 int64_t;
80typedef unsigned __int64 uint64_t;
100 template < GUM_Numeric GUM_SCALAR >
104 enum class NodeType :
char { Precise, Credal, Vacuous, Indic };
129 CredalNet(std::string_view src_min_num, std::string_view src_max_den =
"");
143 CredalNet(
const BayesNet< GUM_SCALAR >& src_min_num,
144 const BayesNet< GUM_SCALAR >& src_max_den = BayesNet< GUM_SCALAR >());
188 const std::vector< std::vector< std::vector< GUM_SCALAR > > >& cpt);
212 const std::vector< std::vector< GUM_SCALAR > >& cpt);
236 const std::vector< std::vector< GUM_SCALAR > >& cpt);
253 const std::vector< GUM_SCALAR >& lower,
254 const std::vector< GUM_SCALAR >& upper);
274 const std::vector< GUM_SCALAR >& lower,
275 const std::vector< GUM_SCALAR >& upper);
295 const std::vector< GUM_SCALAR >& lower,
296 const std::vector< GUM_SCALAR >& upper);
343 void bnToCredal(GUM_SCALAR beta,
bool oneNet,
bool keepZeroes);
344 void bnToCredal(GUM_SCALAR beta,
bool oneNet);
425 void saveBNsMinMax(std::string_view min_path, std::string_view max_path);
445 std::string
toDot()
const;
471 const BayesNet< GUM_SCALAR >&
src_bn()
const;
478 const BayesNet< GUM_SCALAR >&
current_bn()
const;
664 const std::vector< std::vector< std::vector< GUM_SCALAR > > >& var_cpt)
const;
685 void _initCNNets_(std::string_view src_min_num, std::string_view src_max_den);
690 void _initCNNets_(
const BayesNet< GUM_SCALAR >& src_min_num,
691 const BayesNet< GUM_SCALAR >& src_max_den);
709 void _bnCopy_(BayesNet< GUM_SCALAR >& bn_dest);
724 void _H2Vlrs_(
const std::vector< std::vector< GUM_SCALAR > >& h_rep,
725 std::vector< std::vector< GUM_SCALAR > >& v_rep)
const;
729#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
Definition of templatized reader of BIF files for Bayesian networks.
Definition of class for BIF file output manipulation.
Class for assigning/browsing values to tuples of discrete variables.
Class template representing a Credal Network.
void _H2Vlrs_(const std::vector< std::vector< GUM_SCALAR > > &h_rep, std::vector< std::vector< GUM_SCALAR > > &v_rep) const
void _initParams_()
Initialize private constant variables after the Constructor has been called.
GUM_SCALAR _epsilonMoy_
The average perturbation of the BayesNet provided as input for this CredalNet.
void setCPTs(const NodeId &id, const std::vector< std::vector< std::vector< GUM_SCALAR > > > &cpt)
Set the vertices of the credal sets ( all of the conditionals ) of a given node
GUM_SCALAR _deltaC_
5 by default, used by fracC as number of decimals.
Size domainSize(const NodeId &id)
Get the cardinality of a node
std::string toDot() const
BayesNet< GUM_SCALAR > _src_bn_max_
BayesNet used to store upper probabilities.
void intervalToCredalWithFiles()
void _initCNNets_(std::string_view src_min_num, std::string_view src_max_den)
Initialize private BayesNet variables after the Constructor has been called.
BayesNet< GUM_SCALAR > * _current_bn_
Up-to-date BayesNet (used as a DAG).
void _intervalToCredal_()
Computes the vertices of each credal set according to their interval definition (does not use lrs).
std::string toString() const
bool _hasComputedBinaryCPTMinMax_
Used by L2U, to know if lower and upper probabilities over the second modality has been stored in ord...
NodeProperty< std::vector< std::vector< std::vector< GUM_SCALAR > > > > _credalNet_src_cpt_
This CredalNet original CPTs.
const GUM_SCALAR & epsilonMax() const
void _bnCopy_(BayesNet< GUM_SCALAR > &bn_dest)
bool hasComputedBinaryCPTMinMax() const
GUM_SCALAR _precision_
Precision used by frac.
const NodeProperty< std::vector< std::vector< std::vector< GUM_SCALAR > > > > & credalNet_currentCpt() const
void bnToCredal(GUM_SCALAR beta, bool oneNet, bool keepZeroes)
Perturbates the BayesNet provided as input for this CredalNet by generating intervals instead of poin...
void intervalToCredal()
Computes the vertices of each credal set according to their interval definition (uses lrs).
const GUM_SCALAR & epsilonMean() const
std::vector< std::vector< GUM_SCALAR > > _binCptMin_
Used with binary networks to speed-up L2U inference.
void saveBNsMinMax(std::string_view min_path, std::string_view max_path)
If this CredalNet was built over a perturbed BayesNet, one can save the intervals as two BayesNet.
void approximatedBinarization()
Approximate binarization.
const BayesNet< GUM_SCALAR > & src_bn() const
int _find_dNode_card_(const std::vector< std::vector< std::vector< GUM_SCALAR > > > &var_cpt) const
BayesNet< GUM_SCALAR > _src_bn_
Original BayesNet (used as a DAG).
void computeBinaryCPTMinMax()
Used with binary networks to speed-up L2U inference.
const NodeProperty< std::vector< std::vector< std::vector< GUM_SCALAR > > > > & credalNet_srcCpt() const
NodeType currentNodeType(const NodeId &id) const
NodeProperty< NodeType > _original_nodeType_
The NodeType of each node from the ORIGINAL network.
void lagrangeNormalization()
Normalize counts of a BayesNet storing counts of each events such that no probability is 0.
NodeProperty< std::vector< std::vector< std::vector< GUM_SCALAR > > > > * _credalNet_current_cpt_
This CredalNet up-to-date CPTs.
bool isSeparatelySpecified() const
void _sort_varType_()
Set the NodeType of each node
void idmLearning(const Idx s=0, const bool keepZeroes=false)
Learns parameters from a BayesNet storing counts of events.
GUM_SCALAR _epsilonMax_
The highest perturbation of the BayesNet provided as input for this CredalNet.
std::vector< std::vector< GUM_SCALAR > > _binCptMax_
Used with binary networks to speed-up L2U inference.
NodeType nodeType(const NodeId &id) const
Instantiation instantiation(const NodeId &id)
Get an Instantiation from a node id, useful to fill the constraints of the network
bool _separatelySpecified_
TRUE if this CredalNet is separately and interval specified, FALSE otherwise.
void setCPT(const NodeId &id, const Size &entry, const std::vector< std::vector< GUM_SCALAR > > &cpt)
Set the vertices of one credal set of a given node ( any instantiation index )
NodeProperty< std::vector< NodeId > > _var_bits_
Corresponding bits of each variable.
const std::vector< std::vector< GUM_SCALAR > > & get_binaryCPT_max() const
Used with binary networks to speed-up L2U inference.
BayesNet< GUM_SCALAR > _src_bn_min_
BayesNet used to store lower probabilities.
NodeId addVariable(std::string_view name, const Size &card)
Adds a discrete node into the network.
const BayesNet< GUM_SCALAR > & current_bn() const
void addArc(const NodeId &tail, const NodeId &head)
Adds an arc between two nodes.
const std::vector< std::vector< GUM_SCALAR > > & get_binaryCPT_min() const
Used with binary networks to speed-up L2U inference.
void fillConstraints(const NodeId &id, const std::vector< GUM_SCALAR > &lower, const std::vector< GUM_SCALAR > &upper)
Set the interval constraints of the credal sets of a given node (all instantiations )
GUM_SCALAR _epsilonMin_
The lowest perturbation of the BayesNet provided as input for this CredalNet.
const GUM_SCALAR & epsilonMin() const
NodeProperty< NodeType > * _current_nodeType_
The NodeType of each node from the up-to-date network.
GUM_SCALAR _denMax_
Highest possible denominator allowed when using farey.
void fillConstraint(const NodeId &id, const Idx &entry, const std::vector< GUM_SCALAR > &lower, const std::vector< GUM_SCALAR > &upper)
Set the interval constraints of a credal set of a given node ( from an instantiation index )
GUM_SCALAR _epsRedund_
Value under which a decimal number is considered to be zero when computing redundant vertices.
GUM_SCALAR _precisionC_
1e6 by default, used by fracC as precision.
NodeType
NodeType to speed-up computations in some algorithms.
CredalNet()
Constructor used to create a CredalNet step by step, i.e.
GUM_SCALAR _epsF_
Value under which a decimal number is considered to be zero when using farey.
The options given to a toDot(const DotOptions&).
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.
namespace for all credal networks entities
template class GUM_PUBLIC_CN CredalNet< double >
gum is the global namespace for all aGrUM entities
Implementation of pow functions with integers, faster than stl implementation.
The class to use to execute a function by several threads.
Utility functions used for exploiting OpenMP/STL parallelism.