[pyAgrum] updating and extending docs (especially about tools for BayesNet)

parent ede4e02e
......@@ -15,10 +15,10 @@ Parameters
g : pyAgrum.UndiGraph
a undirected graph
dag : pyAgrum::DAG
dag : pyAgrum.DAG
a dag
bn : pyAgrum::BayesNet
bn : pyAgrum.BayesNet
a BayesianNetwork
partial_order: List[List[int]]
......@@ -39,10 +39,10 @@ Parameters
g : pyAgrum.UndiGraph
a undirected graph
dag : pyAgrum::DAG
dag : pyAgrum.DAG
a dag
bn : pyAgrum::BayesNet
bn : pyAgrum.BayesNet
a BayesianNetwork
partial_order: List[List[int]]
......@@ -63,10 +63,10 @@ Parameters
g : pyAgrum.UndiGraph
a undirected graph
dag : pyAgrum::DAG
dag : pyAgrum.DAG
a dag
bn : pyAgrum::BayesNet
bn : pyAgrum.BayesNet
a BayesianNetwork
partial_order: List[List[int]]
......
Tools for Bayesian networks
---------------------------
.. figure:: _static/BNcomparison.png
:align: center
:alt: tools for comparing Bayesian networks
aGrUM/pyAgrum provide a set of classes and functions in order to easely work
with Bayesian networks.
.. toctree::
:maxdepth: 3
BNToolsGener
BNToolsCompar
BNToolsExplain
Comparison of Bayesian networks
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. figure:: _static/BNcomparison.png
:align: center
:alt: tools for comparing Bayesian networks
To compare Bayesian network, one can compare the structure of the BNs
(see pyAgrum.lib.bn_vs_vb.GraphicalBNComparator).
However BNs can also be compared as probability distributions.
.. autoclass:: pyAgrum.ExactBNdistance
.. autoclass:: pyAgrum.GibbsBNdistance
Explanation and analysis
^^^^^^^^^^^^^^^^^^^^^^^^
This tools aimed to provide some different views on the Bayesian network in
order to explore its qualitative and/or quantitave behaviours.
.. autoclass:: pyAgrum.JunctionTreeGenerator
.. autoclass:: pyAgrum.EssentialGraph
.. autoclass:: pyAgrum.MarkovBlanket
Generation of database
^^^^^^^^^^^^^^^^^^^^^^
.. autoclass:: pyAgrum.BNDatabaseGenerator
\ No newline at end of file
Bayesian Network
================
.. figure:: _static/causal.png
.. figure:: _static/BayesNet.png
:align: center
:alt: Causality in pyAgrum
:alt: a Bayesian network (alarm)
The Bayesian Network is the main object of pyAgrum. A Bayesian network is a probabilistic graphical model. It represents a joint distribution over a set of random variables. In pyAgrum, the variables are (for now) only discrete. A Bayesian network uses a directed acyclic graph (DAG) to represent conditional indepencies in the joint distribution. These conditional indepencies allow to factorize the joint distribution, thereby allowing to compactly represent very large ones. Moreover, inference algorithms can also use this graph to speed up the computations. Finally, the Bayesian networks can be learnt from data.
The Bayesian Network is the main object of pyAgrum. A Bayesian network is a
probabilistic graphical model. It represents a joint distribution over a set of
random variables. In pyAgrum, the variables are (for now) only discrete.
A Bayesian network uses a directed acyclic graph (DAG) to represent conditional
indepencies in the joint distribution. These conditional indepencies allow to
factorize the joint distribution, thereby allowing to compactly represent very
large ones. Moreover, inference algorithms can also use this graph to speed up
the computations. Finally, the Bayesian networks can be learnt from data.
.. toctree::
:maxdepth: 3
BNModel
BNTools
BNInference
BNLearning
......
......@@ -80,6 +80,9 @@ napoleon_use_ivar = False
napoleon_use_param = True
napoleon_use_rtype = True
mathjax_path="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js"
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
......@@ -558,7 +561,7 @@ autodoc_default_options = {'members' : None,
'inherited-members':None,
#'show-inheritance':None,
#'ignore-module-all',
#'exclude-members' : ['DiscretizedVariabl_double'],
'exclude-members' : 'thisown',
}
......
......@@ -235,10 +235,10 @@ class JunctionTreeGenerator(object):
g : pyAgrum.UndiGraph
a undirected graph
dag : pyAgrum::DAG
dag : pyAgrum.DAG
a dag
bn : pyAgrum::BayesNet
bn : pyAgrum.BayesNet
a BayesianNetwork
partial_order: List[List[int]]
......@@ -269,10 +269,10 @@ class JunctionTreeGenerator(object):
g : pyAgrum.UndiGraph
a undirected graph
dag : pyAgrum::DAG
dag : pyAgrum.DAG
a dag
bn : pyAgrum::BayesNet
bn : pyAgrum.BayesNet
a BayesianNetwork
partial_order: List[List[int]]
......@@ -303,10 +303,10 @@ class JunctionTreeGenerator(object):
g : pyAgrum.UndiGraph
a undirected graph
dag : pyAgrum::DAG
dag : pyAgrum.DAG
a dag
bn : pyAgrum::BayesNet
bn : pyAgrum.BayesNet
a BayesianNetwork
partial_order: List[List[int]]
......
......@@ -113164,10 +113164,10 @@ static PyMethodDef SwigMethods[] = {
"g : pyAgrum.UndiGraph\n"
" a undirected graph\n"
"\n"
"dag : pyAgrum::DAG\n"
"dag : pyAgrum.DAG\n"
" a dag\n"
"\n"
"bn : pyAgrum::BayesNet\n"
"bn : pyAgrum.BayesNet\n"
" a BayesianNetwork\n"
"\n"
"partial_order: List[List[int]]\n"
......@@ -113194,10 +113194,10 @@ static PyMethodDef SwigMethods[] = {
"g : pyAgrum.UndiGraph\n"
" a undirected graph\n"
"\n"
"dag : pyAgrum::DAG\n"
"dag : pyAgrum.DAG\n"
" a dag\n"
"\n"
"bn : pyAgrum::BayesNet\n"
"bn : pyAgrum.BayesNet\n"
" a BayesianNetwork\n"
"\n"
"partial_order: List[List[int]]\n"
......@@ -113224,10 +113224,10 @@ static PyMethodDef SwigMethods[] = {
"g : pyAgrum.UndiGraph\n"
" a undirected graph\n"
"\n"
"dag : pyAgrum::DAG\n"
"dag : pyAgrum.DAG\n"
" a dag\n"
"\n"
"bn : pyAgrum::BayesNet\n"
"bn : pyAgrum.BayesNet\n"
" a BayesianNetwork\n"
"\n"
"partial_order: List[List[int]]\n"
......@@ -34,10 +34,9 @@ from itertools import product
from ._utils.pyAgrum_header import pyAgrum_header
class BNComparator:
class GraphicalBNComparator:
"""
BNComparator 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.
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
......@@ -74,10 +73,12 @@ class BNComparator:
def _compareBNVariables(self):
"""
Checks if the two BNs have the same set of variables
Returns
-------
str
'OK' if BN are composed of the same variables, indicates problematic variables otherwise
'OK' if the BNs have composed of the same variables, indicates problematic variables otherwise
"""
# it is assumed (checked by the constructor) that _bn1 and _bn2 share the same set of variable names
......@@ -111,14 +112,12 @@ class BNComparator:
def _comparePotentials(self, pot1, pot2):
"""
Compare 2 potentials one in each Bayesian network
Parameters
----------
_bn1 : pyAgrum.BayesNet
a Bayesian network
pot1 : pyAgrum.Potential
one of b1's cpts
_bn2 : pyAgrum.BayesNet
another Bayesian network
pot2 : pyAgrum.Potential
one of _bn2's cpts
......@@ -157,13 +156,12 @@ class BNComparator:
def equivalentBNs(self):
"""
Parameters
----------
name1 : str or pyAgrum.BayesNet
a BN or a filename
name2 : str or pyAgrum.BayesNet
another BN or antoher filename
Check if the 2 BNs are equivalent :
* same variables
* same graphical structure
* same parmaeters
Returns
-------
str
......@@ -188,8 +186,6 @@ class BNComparator:
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
@author : Mélanie Munch
Returns
-------
......@@ -243,16 +239,13 @@ class BNComparator:
precision and recall are computed considering BN1 as the reference
$Fscore=\frac{2\cdot recall\cdot precision}{recall+precision}$ and is the weighted average of Precision and Recall.
$dist2opt=\sqrt{(1-precision)^2+(1-recall)^2}$ and represents the euclidian distance to the ideal(precision=1,
recall=1)
Fscor is 2*(recall* precision)/(recall+precision) and is the weighted average of Precision and Recall.
@author : Mélanie Munch
dist2opt=square root of (1-precision)^2+(1-recall)^2 and represents the euclidian distance to the ideal point (precision=1, recall=1)
Returns
-------
dict[str,double]
dict[str,double]
A dictionnary containing 'precision', 'recall', 'fscore', 'dist2opt' and so on.
"""
# t: True, f: False, p: Positive, n: Negative
......@@ -339,5 +332,5 @@ if __name__ == "__main__":
if len(sys.argv) != 3:
module_help()
cmp = BNComparator(sys.argv[1], sys.argv[2])
cmp = GraphicalBNComparator(sys.argv[1], sys.argv[2])
print(cmp.equivalentBNs())
......@@ -37,7 +37,7 @@ from IPython.core.pylabtools import print_figure
from IPython.display import display, HTML, SVG
from matplotlib.backends.backend_agg import FigureCanvasAgg as fc
from pyAgrum.lib.bn2graph import BN2dot, proba2histo, BNinference2dot, _proba2bgcolor
from pyAgrum.lib.bn_vs_bn import BNComparator
from pyAgrum.lib.bn_vs_bn import GraphicalBNComparator
_cdict = {
'red' : ((0.0, 0.1, 0.3),
......@@ -162,7 +162,7 @@ def getBNDiff(bn1, bn2, size="4", format="png"):
:param size: size of the rendered graph
:param format: render as "png" or "svg"
"""
cmp = BNComparator(bn1, bn2)
cmp = GraphicalBNComparator(bn1, bn2)
return getGraph(cmp.dotDiff(), size, format)
......@@ -179,7 +179,7 @@ def showBNDiff(bn1, bn2, size="4", format="png"):
:param size: size of the rendered graph
:param format: render as "png" or "svg"
"""
cmp = BNComparator(bn1, bn2)
cmp = GraphicalBNComparator(bn1, bn2)
showGraph(cmp.dotDiff(), size, format)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment