42#ifndef GUM_CREDAL_NET_H
43#define GUM_CREDAL_NET_H
79typedef __int64 int64_t;
80typedef unsigned __int64 uint64_t;
96 template < GUM_Numeric GUM_SCALAR >
100 enum class NodeType :
char { Precise, Credal, Vacuous, Indic };
125 CredalNet(std::string_view src_min_num, std::string_view src_max_den =
"");
139 CredalNet(
const BayesNet< GUM_SCALAR >& src_min_num,
140 const BayesNet< GUM_SCALAR >& src_max_den = BayesNet< GUM_SCALAR >());
158 NodeId addVariable(std::string_view name,
const Size& card);
183 void setCPTs(
const NodeId&
id,
184 const std::vector< std::vector< std::vector< GUM_SCALAR > > >& cpt);
206 void setCPT(
const NodeId&
id,
208 const std::vector< std::vector< GUM_SCALAR > >& cpt);
230 void setCPT(
const NodeId&
id,
232 const std::vector< std::vector< GUM_SCALAR > >& cpt);
248 void fillConstraints(
const NodeId&
id,
249 const std::vector< GUM_SCALAR >& lower,
250 const std::vector< GUM_SCALAR >& upper);
268 void fillConstraint(
const NodeId&
id,
270 const std::vector< GUM_SCALAR >& lower,
271 const std::vector< GUM_SCALAR >& upper);
289 void fillConstraint(
const NodeId&
id,
291 const std::vector< GUM_SCALAR >& lower,
292 const std::vector< GUM_SCALAR >& upper);
339 void bnToCredal(GUM_SCALAR beta,
bool oneNet,
bool keepZeroes);
340 void bnToCredal(GUM_SCALAR beta,
bool oneNet);
352 void intervalToCredalWithFiles();
361 void intervalToCredal();
375 void lagrangeNormalization();
388 void idmLearning(
const Idx s = 0,
const bool keepZeroes =
false);
400 void approximatedBinarization();
421 void saveBNsMinMax(std::string_view min_path, std::string_view max_path);
432 std::string toString()
const;
443 void computeBinaryCPTMinMax();
452 const BayesNet< GUM_SCALAR >& src_bn()
const;
459 const BayesNet< GUM_SCALAR >& current_bn()
const;
466 credalNet_currentCpt()
const;
473 credalNet_srcCpt()
const;
481 NodeType currentNodeType(
const NodeId&
id)
const;
489 NodeType nodeType(
const NodeId&
id)
const;
495 const GUM_SCALAR& epsilonMin()
const;
501 const GUM_SCALAR& epsilonMax()
const;
507 const GUM_SCALAR& epsilonMean()
const;
513 bool isSeparatelySpecified()
const;
521 bool hasComputedBinaryCPTMinMax()
const;
531 const std::vector< std::vector< GUM_SCALAR > >& get_binaryCPT_min()
const;
541 const std::vector< std::vector< GUM_SCALAR > >& get_binaryCPT_max()
const;
645 const std::vector< std::vector< std::vector< GUM_SCALAR > > >& var_cpt)
const;
666 void _initCNNets_(std::string_view src_min_num, std::string_view src_max_den);
671 void _initCNNets_(
const BayesNet< GUM_SCALAR >& src_min_num,
672 const BayesNet< GUM_SCALAR >& src_max_den);
690 void _bnCopy_(BayesNet< GUM_SCALAR >& bn_dest);
705 void _H2Vlrs_(
const std::vector< std::vector< GUM_SCALAR > >& h_rep,
706 std::vector< std::vector< GUM_SCALAR > >& v_rep)
const;
710#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.
GUM_SCALAR _deltaC_
5 by default, used by fracC as number of decimals.
BayesNet< GUM_SCALAR > _src_bn_max_
BayesNet used to store upper probabilities.
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).
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.
void _bnCopy_(BayesNet< GUM_SCALAR > &bn_dest)
GUM_SCALAR _precision_
Precision used by frac.
std::vector< std::vector< GUM_SCALAR > > _binCptMin_
Used with binary networks to speed-up L2U inference.
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).
NodeProperty< NodeType > _original_nodeType_
The NodeType of each node from the ORIGINAL network.
NodeProperty< std::vector< std::vector< std::vector< GUM_SCALAR > > > > * _credalNet_current_cpt_
This CredalNet up-to-date CPTs.
void _sort_varType_()
Set the NodeType of each node
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.
bool _separatelySpecified_
TRUE if this CredalNet is separately and interval specified, FALSE otherwise.
NodeProperty< std::vector< NodeId > > _var_bits_
Corresponding bits of each variable.
BayesNet< GUM_SCALAR > _src_bn_min_
BayesNet used to store lower probabilities.
GUM_SCALAR _epsilonMin_
The lowest perturbation of the BayesNet provided as input for this CredalNet.
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.
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.
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
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.