![]() |
aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
|
Class template representing a Credal Network. More...
#include <agrum/CN/credalNet.h>
Public Member Functions | |
void | saveBNsMinMax (const std::string &min_path, const std::string &max_path) const |
If this CredalNet was built over a perturbed BayesNet, one can save the intervals as two BayesNet. More... | |
std::string | toString () const |
void | computeBinaryCPTMinMax () |
Used with binary networks to speed-up L2U inference. More... | |
Constructors / Destructors | |
CredalNet () | |
Constructor used to create a CredalNet step by step, i.e. More... | |
CredalNet (const std::string &src_min_num, const std::string &src_max_den="") | |
Constructor for interval defined credal network which takes 2 BayesNet file path. More... | |
CredalNet (const BayesNet< GUM_SCALAR > &src_min_num, const BayesNet< GUM_SCALAR > &src_max_den=BayesNet< GUM_SCALAR >()) | |
Constructor for interval defined credal network which takes 2 BayesNet. More... | |
~CredalNet () | |
Destructor. More... | |
Credal network creation | |
NodeId | addVariable (const std::string &name, const Size &card) |
Adds a discrete node into the network. More... | |
void | addArc (const NodeId &tail, const NodeId &head) |
Adds an arc between two nodes. More... | |
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 More... | |
void | setCPT (const NodeId &id, Size &entry, const std::vector< std::vector< GUM_SCALAR > > &cpt) |
Set the vertices of one credal set of a given node ( any instantiation index ) More... | |
void | setCPT (const NodeId &id, Instantiation ins, const std::vector< std::vector< GUM_SCALAR > > &cpt) |
Set the vertices of one credal set of a given node ( any instantiation ) More... | |
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 ) More... | |
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 ) More... | |
void | fillConstraint (const NodeId &id, Instantiation ins, const std::vector< GUM_SCALAR > &lower, const std::vector< GUM_SCALAR > &upper) |
Set the interval constraints of a credal sets of a given node ( from an instantiation ) More... | |
Instantiation | instantiation (const NodeId &id) |
Get an Instantiation from a node id, usefull to fill the constraints of the network More... | |
Size | domainSize (const NodeId &id) |
Get the cardinality of a node More... | |
Public manipulation methods | |
void | bnToCredal (const GUM_SCALAR beta, const bool oneNet, const bool keepZeroes=false) |
Perturbates the BayesNet provided as input for this CredalNet by generating intervals instead of point probabilities and then computes each vertex of each credal set. More... | |
void | intervalToCredalWithFiles () |
void | intervalToCredal () |
Computes the vertices of each credal set according to their interval definition (uses lrs). More... | |
void | lagrangeNormalization () |
Normalize counts of a BayesNet storing counts of each events such that no probability is 0. More... | |
void | idmLearning (const Idx s=0, const bool keepZeroes=false) |
Learns parameters from a BayesNet storing counts of events. More... | |
void | approximatedBinarization () |
Approximate binarization. More... | |
Getters and setters | |
const BayesNet< GUM_SCALAR > & | src_bn () const |
const BayesNet< GUM_SCALAR > & | current_bn () const |
const NodeProperty< std::vector< std::vector< std::vector< GUM_SCALAR > > > > & | credalNet_currentCpt () const |
const NodeProperty< std::vector< std::vector< std::vector< GUM_SCALAR > > > > & | credalNet_srcCpt () const |
NodeType | currentNodeType (const NodeId &id) const |
NodeType | nodeType (const NodeId &id) const |
const GUM_SCALAR & | epsilonMin () const |
const GUM_SCALAR & | epsilonMax () const |
const GUM_SCALAR & | epsilonMean () const |
const bool | isSeparatelySpecified () const |
const bool | hasComputedBinaryCPTMinMax () const |
const std::vector< std::vector< GUM_SCALAR > > & | get_binaryCPT_min () const |
Used with binary networks to speed-up L2U inference. More... | |
const std::vector< std::vector< GUM_SCALAR > > & | get_binaryCPT_max () const |
Used with binary networks to speed-up L2U inference. More... | |
Public Types | |
enum | NodeType : char { NodeType::Precise, NodeType::Credal, NodeType::Vacuous, NodeType::Indic } |
NodeType to speed-up computations in some algorithms. More... | |
Class template representing a Credal Network.
GUM_SCALAR | A floating type ( float, GUM_SCALAR, long GUM_SCALAR ... ). |
Definition at line 88 of file credalNet.h.
|
strong |
NodeType to speed-up computations in some algorithms.
Enumerator | |
---|---|
Precise | |
Credal | |
Vacuous | |
Indic |
Definition at line 91 of file credalNet.h.
gum::credal::CredalNet< GUM_SCALAR >::CredalNet | ( | ) |
Constructor used to create a CredalNet step by step, i.e.
node by node, arc by arc, manually filling potentials.
Definition at line 31 of file credalNet_tpl.h.
gum::credal::CredalNet< GUM_SCALAR >::CredalNet | ( | const std::string & | src_min_num, |
const std::string & | src_max_den = "" |
||
) |
Constructor for interval defined credal network which takes 2 BayesNet file path.
One can also provide a single BayesNet in order to perturb it's probability distributions into credal sets according to another BayesNet containing the number of cases, for each node, of each parent instantiation met during learning, i.e. \( p(X = 0 \mid pa(X) = j) = N_{pa(X) = j} \).
src_min_num | The path to a BayesNet which contains lower probabilities. |
src_max_den | The ( optional ) path to a BayesNet which contains upper probabilities. |
Definition at line 390 of file credalNet_tpl.h.
gum::credal::CredalNet< GUM_SCALAR >::CredalNet | ( | const BayesNet< GUM_SCALAR > & | src_min_num, |
const BayesNet< GUM_SCALAR > & | src_max_den = BayesNet< GUM_SCALAR >() |
||
) |
Constructor for interval defined credal network which takes 2 BayesNet.
One can also provide a single BayesNet in order to perturb it's probability distributions into credal sets according to another BayesNet containing the number of cases, for each node, of each parent instantiation met during learning, i.e. \( p(X = 0 \mid pa(X) = j) = N_{pa(X) = j} \).
src_min_num | The BayesNet which contains lower probabilities. |
src_max_den | The ( optional ) BayesNet which contains upper probabilities. |
Definition at line 399 of file credalNet_tpl.h.
gum::credal::CredalNet< GUM_SCALAR >::~CredalNet | ( | ) |
Destructor.
Definition at line 408 of file credalNet_tpl.h.
|
private |
Copy the up-to-date BayesNet associated with this CredalNet. Since all we care about is the DAG, only arcs are copied. Because the order with which arcs are created is important, the function iterates over the CPTs variables to be sure parent order stays the same from a net to it's copy.
bn_dest | The reference to the new copy |
Definition at line 1446 of file credalNet_tpl.h.
|
private |
var_cpt | The reference to a node CPT which may need a Decision Node. |
Definition at line 1434 of file credalNet_tpl.h.
|
private |
it's vertices, from it's H-representation, i.e. the hyper-plan inequalities. Uses lrs.
h_rep | A constant reference to the H-representation of a credal set. |
v_rep | A reference to the V-representation of the same credal set. |
Definition at line 1522 of file credalNet_tpl.h.
|
private |
Initialize private BayesNet variables after the Constructor has been called.
Definition at line 1403 of file credalNet_tpl.h.
|
private |
Initialize private BayesNet variables after the Constructor has been called.
Definition at line 1422 of file credalNet_tpl.h.
|
private |
Initialize private constant variables after the Constructor has been called.
Definition at line 1376 of file credalNet_tpl.h.
|
private |
Computes the vertices of each credal set according to their interval definition (does not use lrs).
Only works with credal sets defined such that when one modality reach it's upper probability, all others are at their lowest.
Called by bnToCredal and idmLearning.
Definition at line 674 of file credalNet_tpl.h.
|
private |
Set the NodeType of each node
Definition at line 1707 of file credalNet_tpl.h.
void gum::credal::CredalNet< GUM_SCALAR >::addArc | ( | const NodeId & | tail, |
const NodeId & | head | ||
) |
Adds an arc between two nodes.
tail | The NodeId of the tail node |
head | The NodeId of the head node |
Definition at line 58 of file credalNet_tpl.h.
NodeId gum::credal::CredalNet< GUM_SCALAR >::addVariable | ( | const std::string & | name, |
const Size & | card | ||
) |
Adds a discrete node into the network.
name | The name of the discrete variable to be added |
card | The cardinality of the variable |
NodeId
of the variable in the network Definition at line 42 of file credalNet_tpl.h.
void gum::credal::CredalNet< GUM_SCALAR >::approximatedBinarization | ( | ) |
Approximate binarization.
Each bit has a lower and upper probability which is the lowest - resp. highest - over all vertices of the credal set. Enlarge the original credal sets and may induce huge imprecision.
Definition at line 947 of file credalNet_tpl.h.
void gum::credal::CredalNet< GUM_SCALAR >::bnToCredal | ( | const GUM_SCALAR | beta, |
const bool | oneNet, | ||
const bool | keepZeroes = false |
||
) |
Perturbates the BayesNet provided as input for this CredalNet by generating intervals instead of point probabilities and then computes each vertex of each credal set.
The perturbations are done according to the number of cases met for each node and each of it's parent instantiation, i.e. \( \epsilon = *\beta^{ln(N_{pa(X) = j} + 1)} \) is the imprecision introduced which leads to \( \underline{p}(X = i \mid pa(X) = j) = (1 - \epsilon) p(X = i *\mid pa(X) = j) \) and \( \overline{p}(X = i \mid pa(X) = j) *=\underline{p}(X =i \mid pa(X) = j) + \epsilon \). Use this method when using a single BayesNet storing counts of events with oneNet
set to TRUE
or when using two BayesNet, one with lower probabilities and one with upper probabilities, with oneNet
set to FALSE
.
beta | The beta used to perturbate the network. \( 0 \leq \beta *\leq 1 \). |
oneNet | Boolean used as a flag. Set to TRUE if one BayesNet if provided with counts, to FALSE if two BayesNet are provided; one with probabilities (the lower net) and one with denominators over the first modalities (the upper net). |
keepZeroes | Boolean used as a flag as whether or not - respectively TRUE or FALSE - we keep zeroes as zeroes. Default is FALSE , i.e. zeroes are not kept. |
Definition at line 420 of file credalNet_tpl.h.
void gum::credal::CredalNet< GUM_SCALAR >::computeBinaryCPTMinMax | ( | ) |
Used with binary networks to speed-up L2U inference.
Store the lower and upper probabilities of each node X over the "true" modality, i.e. respectively \( \underline{p}(X = 1 \mid pa(X) = j) \) and \( \overline{p}(X = 1 \mid pa(X) = j) \).
Definition at line 1261 of file credalNet_tpl.h.
const NodeProperty< std::vector< std::vector< std::vector< GUM_SCALAR > > > > & gum::credal::CredalNet< GUM_SCALAR >::credalNet_currentCpt | ( | ) | const |
Definition at line 1223 of file credalNet_tpl.h.
const NodeProperty< std::vector< std::vector< std::vector< GUM_SCALAR > > > > & gum::credal::CredalNet< GUM_SCALAR >::credalNet_srcCpt | ( | ) | const |
Definition at line 1231 of file credalNet_tpl.h.
const BayesNet< GUM_SCALAR > & gum::credal::CredalNet< GUM_SCALAR >::current_bn | ( | ) | const |
Definition at line 1360 of file credalNet_tpl.h.
CredalNet< GUM_SCALAR >::NodeType gum::credal::CredalNet< GUM_SCALAR >::currentNodeType | ( | const NodeId & | id | ) | const |
id | The constant reference to the choosen NodeId |
Definition at line 1237 of file credalNet_tpl.h.
INLINE Size gum::credal::CredalNet< GUM_SCALAR >::domainSize | ( | const NodeId & | id | ) |
Get the cardinality of a node
id | The NodeId of the node |
Definition at line 383 of file credalNet_tpl.h.
const GUM_SCALAR & gum::credal::CredalNet< GUM_SCALAR >::epsilonMax | ( | ) | const |
Definition at line 1309 of file credalNet_tpl.h.
const GUM_SCALAR & gum::credal::CredalNet< GUM_SCALAR >::epsilonMean | ( | ) | const |
Definition at line 1314 of file credalNet_tpl.h.
const GUM_SCALAR & gum::credal::CredalNet< GUM_SCALAR >::epsilonMin | ( | ) | const |
Definition at line 1304 of file credalNet_tpl.h.
void gum::credal::CredalNet< GUM_SCALAR >::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 )
id | The NodeId of the node |
entry | The index of the instantiation excluding the given node ( only the parents are used to compute the index of the credal set ) |
lower | The lower value for each probability in correct order |
upper | The upper value for each probability in correct order |
You need to call intervalToCredal when done filling all constraints.
BayesNet
(s) associated to this credal net ! ins
to check variable order in the instantiation ( to get index ), therefore we pass it by value Definition at line 264 of file credalNet_tpl.h.
void gum::credal::CredalNet< GUM_SCALAR >::fillConstraint | ( | const NodeId & | id, |
Instantiation | ins, | ||
const std::vector< GUM_SCALAR > & | lower, | ||
const std::vector< GUM_SCALAR > & | upper | ||
) |
Set the interval constraints of a credal sets of a given node ( from an instantiation )
id | The NodeId of the node |
ins | The Instantiation |
lower | The lower value for each probability in correct order |
upper | The upper value for each probability in correct order |
You need to call intervalToCredal when done filling all constraints.
BayesNet
(s) associated to this credal net ! ins
to check variable order in the instantiation ( to get index ), therefor we pass it by value Definition at line 311 of file credalNet_tpl.h.
void gum::credal::CredalNet< GUM_SCALAR >::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 )
id | The NodeId of the node |
lower | The lower value for each probability in correct order |
upper | The upper value for each probability in correct order |
You need to call intervalToCredal when done filling all constraints.
BayesNet
(s) associated to this credal net ! ins
to check variable order in the instantiation ( to get index ), therefore we pass it by value Definition at line 251 of file credalNet_tpl.h.
const std::vector< std::vector< GUM_SCALAR > > & gum::credal::CredalNet< GUM_SCALAR >::get_binaryCPT_max | ( | ) | const |
Used with binary networks to speed-up L2U inference.
Definition at line 1299 of file credalNet_tpl.h.
const std::vector< std::vector< GUM_SCALAR > > & gum::credal::CredalNet< GUM_SCALAR >::get_binaryCPT_min | ( | ) | const |
Used with binary networks to speed-up L2U inference.
Definition at line 1293 of file credalNet_tpl.h.
const bool gum::credal::CredalNet< GUM_SCALAR >::hasComputedBinaryCPTMinMax | ( | ) | const |
TRUE
if this CredalNet has called computeBinaryCPTMinMax() to speed-up inference with binary networks and L2U. This needs to be reworked as it is too easy to forget to call it and it can't be called within the inference engine (constness). Definition at line 1255 of file credalNet_tpl.h.
void gum::credal::CredalNet< GUM_SCALAR >::idmLearning | ( | const Idx | s = 0 , |
const bool | keepZeroes = false |
||
) |
Learns parameters from a BayesNet storing counts of events.
Use this method when using a single BayesNet storing counts of events. IDM model if s
> 0, standard point probability if s
= 0 (default value if none precised).
s | The IDM parameter. |
keepZeroes | Boolean used as a flag as whether or not - respectively TRUE or FALSE - we keep zeroes as zeroes. Default is FALSE , i.e. zeroes are not kept. |
Definition at line 601 of file credalNet_tpl.h.
INLINE Instantiation gum::credal::CredalNet< GUM_SCALAR >::instantiation | ( | const NodeId & | id | ) |
Get an Instantiation
from a node id, usefull to fill the constraints of the network
bnet accessors / shortcuts
id | The NodeId we want an instantiation from |
Definition at line 378 of file credalNet_tpl.h.
void gum::credal::CredalNet< GUM_SCALAR >::intervalToCredal | ( | ) |
Computes the vertices of each credal set according to their interval definition (uses lrs).
Use this method when using two BayesNet, one with lower probabilities and one with upper probabilities.
Definition at line 767 of file credalNet_tpl.h.
void gum::credal::CredalNet< GUM_SCALAR >::intervalToCredalWithFiles | ( | ) |
Computes the vertices of each credal set according to their interval definition (uses lrs).
Use this method when using a single BayesNet storing counts of events.
Definition at line 821 of file credalNet_tpl.h.
const bool gum::credal::CredalNet< GUM_SCALAR >::isSeparatelySpecified | ( | ) | const |
TRUE
if this CredalNet is separately and interval specified, FALSE
otherwise. Definition at line 1250 of file credalNet_tpl.h.
void gum::credal::CredalNet< GUM_SCALAR >::lagrangeNormalization | ( | ) |
Normalize counts of a BayesNet storing counts of each events such that no probability is 0.
Use this method when using a single BayesNet storing counts of events. Lagrange normalization. This call is irreversible and modify counts stored by src_bn
.
Doest not performs computations of the parameters but keeps normalized counts of events only. Call idmLearning
to compute the probabilities (with any parameter value).
Definition at line 552 of file credalNet_tpl.h.
CredalNet< GUM_SCALAR >::NodeType gum::credal::CredalNet< GUM_SCALAR >::nodeType | ( | const NodeId & | id | ) | const |
id | The constant reference to the choosen NodeId |
Definition at line 1245 of file credalNet_tpl.h.
void gum::credal::CredalNet< GUM_SCALAR >::saveBNsMinMax | ( | const std::string & | min_path, |
const std::string & | max_path | ||
) | const |
If this CredalNet was built over a perturbed BayesNet, one can save the intervals as two BayesNet.
to call after bnToCredal( GUM_SCALAR beta ) save a BN with lower probabilities and a BN with upper ones
min_path | The path to save the BayesNet which contains the lower probabilities of each node X, i.e. \( \underline{p}(X = i \mid pa(X) = *j) *\). |
max_path | The path to save the BayesNet which contains the upper probabilities of each node X, i.e. \( \overline{p}(X = i \mid pa(X) = *j) *\). |
Definition at line 915 of file credalNet_tpl.h.
void gum::credal::CredalNet< GUM_SCALAR >::setCPT | ( | const NodeId & | id, |
Size & | entry, | ||
const std::vector< std::vector< GUM_SCALAR > > & | cpt | ||
) |
Set the vertices of one credal set of a given node ( any instantiation index )
id | The NodeId of the node |
entry | The index of the instantiation ( from 0 to K - 1 ) excluding the given node ( only the parents are used to compute the index of the credal set ) |
cpt | The vertices of every credal set ( for each instantiation of the parents ) |
Use this with either LRSWrapper
or LpInterface
to get the vertices of a credal set represented by linear constraints.
BayesNet
(s) associated to this credal net ! Definition at line 110 of file credalNet_tpl.h.
void gum::credal::CredalNet< GUM_SCALAR >::setCPT | ( | const NodeId & | id, |
Instantiation | ins, | ||
const std::vector< std::vector< GUM_SCALAR > > & | cpt | ||
) |
Set the vertices of one credal set of a given node ( any instantiation )
id | The NodeId of the node |
ins | The Instantiation ( only the parents matter to find the credal set index ) |
cpt | The vertices of every credal set ( for each instantiation of the parents ) |
Use this with either LRSWrapper
or LpInterface
to get the vertices of a credal set represented by linear constraints.
BayesNet
(s) associated to this credal net !ins
to check variable order in the instantiation ( to get index ), therefor we pass it by value Definition at line 163 of file credalNet_tpl.h.
void gum::credal::CredalNet< GUM_SCALAR >::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
id | The NodeId of the node |
cpt | The vertices of every credal set ( for each instantiation of the parents ) |
BayesNet
(s) associated to this credal net !First dimension is instantiation position ( from 0 to K - 1 ). Second is the credal set vertice index Third is the vertex
Definition at line 65 of file credalNet_tpl.h.
const BayesNet< GUM_SCALAR > & gum::credal::CredalNet< GUM_SCALAR >::src_bn | ( | ) | const |
Definition at line 1367 of file credalNet_tpl.h.
std::string gum::credal::CredalNet< GUM_SCALAR >::toString | ( | ) | const |
Definition at line 1319 of file credalNet_tpl.h.
|
private |
Used with binary networks to speed-up L2U inference.
Store the upper probabilities of each node X over the "true" modality, i.e. \( \overline{p}(X = 1 \mid pa(X) = j) \).
Definition at line 627 of file credalNet.h.
|
private |
Used with binary networks to speed-up L2U inference.
Store the lower probabilities of each node X over the "true" modality, i.e. \( \underline{p}(X = 1 \mid pa(X) = j) \).
Definition at line 619 of file credalNet.h.
|
private |
This CredalNet up-to-date CPTs.
Definition at line 600 of file credalNet.h.
|
private |
This CredalNet original CPTs.
Definition at line 596 of file credalNet.h.
|
private |
Up-to-date BayesNet (used as a DAG).
Definition at line 593 of file credalNet.h.
|
private |
The NodeType of each node from the up-to-date network.
Definition at line 608 of file credalNet.h.
|
private |
5 by default, used by fracC as number of decimals.
Definition at line 547 of file credalNet.h.
|
private |
Highest possible denominator allowed when using farey.
A value too high may lead to lrs being unable to find vertices.
Definition at line 574 of file credalNet.h.
|
private |
Value under which a decimal number is considered to be zero when using farey.
Definition at line 570 of file credalNet.h.
|
private |
The highest perturbation of the BayesNet provided as input for this CredalNet.
Definition at line 556 of file credalNet.h.
|
private |
The lowest perturbation of the BayesNet provided as input for this CredalNet.
Definition at line 552 of file credalNet.h.
|
private |
The average perturbation of the BayesNet provided as input for this CredalNet.
Definition at line 560 of file credalNet.h.
|
private |
Value under which a decimal number is considered to be zero when computing redundant vertices.
Definition at line 565 of file credalNet.h.
|
private |
Used by L2U, to know if lower and upper probabilities over the second modality has been stored in order to speed-up the algorithm.
Definition at line 612 of file credalNet.h.
|
private |
The NodeType of each node from the ORIGINAL network.
Definition at line 606 of file credalNet.h.
|
private |
Precision used by frac.
Definition at line 577 of file credalNet.h.
|
private |
1e6 by default, used by fracC as precision.
Definition at line 545 of file credalNet.h.
|
private |
TRUE
if this CredalNet is separately and interval specified, FALSE
otherwise.
Definition at line 582 of file credalNet.h.
|
private |
|
private |
BayesNet used to store upper probabilities.
Definition at line 590 of file credalNet.h.
|
private |
BayesNet used to store lower probabilities.
Definition at line 588 of file credalNet.h.
|
private |