other pyAgrum.lib modules

bn2roc

pyAgrum.lib.bn2roc.module_help(exit_value=1, message='')

defines help viewed if args are not OK on command line, and exit with exit_value

pyAgrum.lib.bn2roc.showROC(bn, csv_name, variable, label, visible=True, show_fig=False, with_labels=True)

Compute the ROC curve and save the result in the folder of the csv file.

Parameters:
  • bn (pyAgrum.BayesNet) – a bayesian network
  • csv_name (str) – a csv filename
  • target (str) – the target
  • label (str) – the target label
  • visible (bool) – indicates if the resulting curve must be printed

bn2csv

Samples generation w.r.t to a probability distribution represented by a Bayesian network.

class pyAgrum.lib.bn2csv.CSVGenerator

Bases: object

Class for samples generation w.r.t to a probability distribution represented by a Bayesian network.

caching_probas(bn, node_id, n, par)
Parameters:
  • bn (pyAgrum.BayesNet) – a Bayesian network
  • node_id (int) – a node id
  • n (int) – a node id
  • par (list) – the node’s parents
Returns:

the node’s probabilities

Return type:

list

cachingnameAndParents(bn, n)

Compute a list of parents for node n in BN bn.

Parameters:
  • bn (pyAgrum.BayesNet) – a Bayesian network
  • n – (int) a node id
  • n – (str) a node name
Returns:

a couple of name of n and list of parents names

Return type:

tuple

static draw(tab)

draw a value using tab as probability table.

Parameters:tab (list) – a probability table
Returns:the couple (i,proba)
Return type:tuple
static nameAndParents(bn, n)

Compute a list of parents for node n in BN bn.

Parameters:
  • bn (pyAgrum.BayesNet) – a Bayesian network
  • n – (int) a node id
  • n – (str) a node name
Returns:

a couple of name of n and list of parents names

Return type:

tuple

Raises:

gum.IndexError – If the node is not in the Bayesian network

newSample(bn, seq)

Generate a sample w.r.t to the bn using the variable sequence seq (topological order)

Parameters:
  • bn (pyAgrum.BayesNet) – a Bayesian network
  • seq (list) – a variable sequence
Returns:

the coule (sample,log2-likelihood)

Return type:

tuple

proceed(name_in, name_out, n, visible, with_labels)

From the file name_in (BN file), generate n samples and save them in name_out

Parameters:
  • name_in (str) – a file name
  • name_out (str) – the output file
  • n (int) – the number of samples
  • visible (bool) – indicate if a progress bar should be displayed
  • with_labels (bool) – indicate if values should be labelled or not
Returns:

the log2-likelihood of the n samples database

Return type:

double

pyAgrum.lib.bn2csv.generateCSV(name_in, name_out, n, visible=False, with_labels=True)

From the file name_in (BN file), generate n samples and save them in name_out

Parameters:
  • name_in (str) – a file name
  • name_out (str) – the output file
  • n (int) – the number of samples
  • visible (bool) – indicate if a progress bar should be displayed
  • with_labels (bool) – indicate if values should be labelled or not
Returns:

the log2-likelihood of the n samples database

Return type:

double

pyAgrum.lib.bn2csv.module_help(exit_value=1)

defines help viewed if args are not OK on command line, and exit with exit_value

bn2scores

pyAgrum.lib.bn2scores.checkCompatibility(bn, fields, csv_name)

check if variables of the bn are in the fields

if not : return None if compatibilty : return a list of position for variables in fields

pyAgrum.lib.bn2scores.computeScores(bn_name, csv_name, visible=False, transforme_label=None)
pyAgrum.lib.bn2scores.getNumLabel(inst, i, label, transforme_label)
pyAgrum.lib.bn2scores.lines_count(filename)

count lines in a file

pyAgrum.lib.bn2scores.module_help(exit_value=1)

defines help viewed if args are not OK on command line, and exit with exit_value

pyAgrum.lib.bn2scores.stringify(s)

bn_vs_bn

class pyAgrum.lib.bn_vs_bn.GraphicalBNComparator(name1, name2, delta=1e-06)

Bases: object

BNGraphicalComparator allows to compare in multiple way 2 BNs…The smallest assumption is that the names of the variables are the same in the 2 BNs. But some comparisons will have also to check the type and domainSize of the variables. The bns have not exactly the same role : _bn1 is rather the referent model for the comparison whereas _bn2 is the compared one to the referent model

Parameters:
dotDiff()

Return a pydotplus graph that compares the arcs of _bn1 (reference) with those of self._bn2. full black line: the arc is common for both full red line: the arc is common but inverted in _bn2 dotted black line: the arc is added in _bn2 dotted red line: the arc is removed in _bn2

Warning

if pydotplus is not installed, this function just returns None

Returns:the result dot graph or None if pydotplus can not be imported
Return type:pydotplus.Dot
equivalentBNs()

Check if the 2 BNs are equivalent :

  • same variables
  • same graphical structure
  • same parmaeters
Returns:“OK” if bn are the same, a description of the error otherwise
Return type:str
hamming()

Compute hamming and structural hamming distance Hamming distance is the difference of edges comparing the 2 skeletons, and Structural Hamming difference is the difference comparing the cpdags,

including the arcs’ orientation.
Returns:A dictionnary containing ‘hamming’,’structural hamming’
Return type:dict[double,double]
scores()

Compute Precision, Recall, F-score for self._bn2 compared to self._bn1

precision and recall are computed considering BN1 as the reference

Fscor is 2*(recall* precision)/(recall+precision) and is the weighted average of Precision and Recall.

dist2opt=square root of (1-precision)^2+(1-recall)^2 and represents the euclidian distance to the ideal point (precision=1, recall=1)

Returns:A dictionnary containing ‘precision’, ‘recall’, ‘fscore’, ‘dist2opt’ and so on.
Return type:dict[str,double]
pyAgrum.lib.bn_vs_bn.module_help(exit_value=1)

defines help viewed if args are not OK on command line, and exit with exit_value

pretty_print

pyAgrum.lib.pretty_print.bn2txt(aBN)

Representation of all CPTs of a gum.BayesNet

Parameters:aBN – the bayes net or the name of the file
Returns:
pyAgrum.lib.pretty_print.cpt2txt(cpt, digits=4)

string representation of a gum.Potential

Parameters:cpt – the Potential to represent
Returns:the string representation
pyAgrum.lib.pretty_print.max_length(v)
pyAgrum.lib.pretty_print.module_help(exit_value=1)

defines help viewed if args are not OK on command line, and exit with exit_value