[aGrUM] gum::MarkovBlanket()::mb()->gum::MarkovBlanket::dag()

parent c9fdc81a
......@@ -48,13 +48,13 @@ namespace gum {
*/
class MarkovBlanket {
public:
MarkovBlanket(const DAGmodel& m, NodeId n,int level=1);
MarkovBlanket(const DAGmodel& m, const std::string& name,int level=1);
MarkovBlanket(const DAGmodel& m, NodeId n, int level = 1);
MarkovBlanket(const DAGmodel& m, const std::string& name, int level = 1);
~MarkovBlanket();
/// @return a copy of the mixed graph
DiGraph mb();
/// @return a copy of the graph
DAG dag();
// @return a dot representation of this MarkovBlanket
// node of interest is in red
......@@ -62,25 +62,25 @@ namespace gum {
// grey
std::string toDot() const;
/// wrapping @ref DiGraph::parents(id)
/// wrapping @ref DAG::parents(id)
const NodeSet& parents(const NodeId id) const;
/// wrapping @ref DiGraph::parents(id)
/// wrapping @ref DAG::parents(id)
const NodeSet& children(const NodeId id) const;
/// wrapping @ref DiGraph::sizeArcs()
/// wrapping @ref DAG::sizeArcs()
Size sizeArcs() const;
/// wrapping @ref DiGraph::arcs()
/// wrapping @ref DAG::arcs()
const ArcSet& arcs() const;
/// wrapping @ref DiGraph::sizeNodes()
/// wrapping @ref DAG::sizeNodes()
Size sizeNodes() const;
/// wrapping @ref DiGraph::size()
/// wrapping @ref DAG::size()
Size size() const;
/// wrapping @ref DiGraph::nodes()
/// wrapping @ref DAG::nodes()
const NodeGraphPart& nodes() const;
/// @return true if all the named node are the same and all the named arcs are
......@@ -91,7 +91,7 @@ namespace gum {
bool __buildMarkovBlanket(const NodeId id);
const DAGmodel& __model;
DiGraph __mb;
DAG __mb;
const NodeId __node;
ArcSet __specialArcs;
};
......
......@@ -32,7 +32,7 @@
namespace gum {
INLINE DiGraph MarkovBlanket::mb() { return __mb; }
INLINE DAG MarkovBlanket::dag() { return __mb; }
INLINE const NodeSet& MarkovBlanket::parents(const NodeId id) const {
return __mb.parents(id);
......
......@@ -112,7 +112,8 @@ namespace gum_tests {
void testMarkovBlanketMultiLevel() {
const auto bn = gum::BayesNet< float >::fastPrototype(
"Z<-A->B->C->D->E<-Y;X->G<-F<-C<-I<-H->W");
TS_ASSERT_THROWS(gum::MarkovBlanket(bn, "C", 0).size(), gum::InvalidArgument);
TS_ASSERT_THROWS(gum::MarkovBlanket(bn, "C", 0).size(),
gum::InvalidArgument);
TS_ASSERT_EQUALS(gum::MarkovBlanket(bn, "C", 1).size(), gum::Size(5));
TS_ASSERT_EQUALS(gum::MarkovBlanket(bn, "C", 2).size(), gum::Size(11));
TS_ASSERT_EQUALS(gum::MarkovBlanket(bn, "C", 3).size(), gum::Size(13));
......
......@@ -13,12 +13,12 @@ MarkovBlanket(m,name) -> MarkovBlanket
* **name** (*str*) -- a node name
"
%feature("docstring") gum::MarkovBlanket::mb
%feature("docstring") gum::MarkovBlanket::dag
"
Returns
-------
pyAgrum.DiGraph
a copy of the directed graph
pyAgrum.DAG
a copy of the DAG
"
%feature("docstring") gum::MarkovBlanket::toDot
......
......@@ -6751,17 +6751,17 @@ class MarkovBlanket(object):
_pyAgrum.MarkovBlanket_swiginit(self, _pyAgrum.new_MarkovBlanket(*args))
__swig_destroy__ = _pyAgrum.delete_MarkovBlanket
def mb(self):
def dag(self):
r"""
mb(MarkovBlanket self) -> DiGraph
dag(MarkovBlanket self) -> DAG
Returns
-------
pyAgrum.DiGraph
a copy of the directed graph
pyAgrum.DAG
a copy of the DAG
"""
return _pyAgrum.MarkovBlanket_mb(self)
return _pyAgrum.MarkovBlanket_dag(self)
def toDot(self):
r"""
......
......@@ -45009,30 +45009,30 @@ fail:
}
SWIGINTERN PyObject *_wrap_MarkovBlanket_mb(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
SWIGINTERN PyObject *_wrap_MarkovBlanket_dag(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
gum::MarkovBlanket *arg1 = (gum::MarkovBlanket *) 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject *swig_obj[1] ;
gum::DiGraph result;
gum::DAG result;
if (!args) SWIG_fail;
swig_obj[0] = args;
res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_gum__MarkovBlanket, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MarkovBlanket_mb" "', argument " "1"" of type '" "gum::MarkovBlanket *""'");
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MarkovBlanket_dag" "', argument " "1"" of type '" "gum::MarkovBlanket *""'");
}
arg1 = reinterpret_cast< gum::MarkovBlanket * >(argp1);
{
try {
result = (arg1)->mb();
result = (arg1)->dag();
} catch (...) {
SetPythonizeAgrumException();
SWIG_fail;
}
}
resultobj = SWIG_NewPointerObj((new gum::DiGraph(static_cast< const gum::DiGraph& >(result))), SWIGTYPE_p_gum__DiGraph, SWIG_POINTER_OWN | 0 );
resultobj = SWIG_NewPointerObj((new gum::DAG(static_cast< const gum::DAG& >(result))), SWIGTYPE_p_gum__DAG, SWIG_POINTER_OWN | 0 );
return resultobj;
fail:
return NULL;
......@@ -119609,13 +119609,13 @@ static PyMethodDef SwigMethods[] = {
"MarkovBlanket(DAGmodel m, std::string const & name, int level=1)\n"
""},
{ "delete_MarkovBlanket", _wrap_delete_MarkovBlanket, METH_O, "delete_MarkovBlanket(MarkovBlanket self)"},
{ "MarkovBlanket_mb", _wrap_MarkovBlanket_mb, METH_O, "\n"
"MarkovBlanket_mb(MarkovBlanket self) -> DiGraph\n"
{ "MarkovBlanket_dag", _wrap_MarkovBlanket_dag, METH_O, "\n"
"MarkovBlanket_dag(MarkovBlanket self) -> DAG\n"
"\n"
"Returns\n"
"-------\n"
"pyAgrum.DiGraph\n"
" a copy of the directed graph\n"
"pyAgrum.DAG\n"
" a copy of the DAG\n"
"\n"
""},
{ "MarkovBlanket_toDot", _wrap_MarkovBlanket_toDot, METH_O, "\n"
......@@ -6751,17 +6751,17 @@ class MarkovBlanket(object):
_pyAgrum.MarkovBlanket_swiginit(self, _pyAgrum.new_MarkovBlanket(*args))
__swig_destroy__ = _pyAgrum.delete_MarkovBlanket
def mb(self) -> "gum::DiGraph":
def dag(self) -> "gum::DAG":
r"""
mb(MarkovBlanket self) -> DiGraph
dag(MarkovBlanket self) -> DAG
Returns
-------
pyAgrum.DiGraph
a copy of the directed graph
pyAgrum.DAG
a copy of the DAG
"""
return _pyAgrum.MarkovBlanket_mb(self)
return _pyAgrum.MarkovBlanket_dag(self)
def toDot(self) -> "std::string":
r"""
......
......@@ -45009,30 +45009,30 @@ fail:
}
SWIGINTERN PyObject *_wrap_MarkovBlanket_mb(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
SWIGINTERN PyObject *_wrap_MarkovBlanket_dag(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
gum::MarkovBlanket *arg1 = (gum::MarkovBlanket *) 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject *swig_obj[1] ;
gum::DiGraph result;
gum::DAG result;
if (!args) SWIG_fail;
swig_obj[0] = args;
res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_gum__MarkovBlanket, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MarkovBlanket_mb" "', argument " "1"" of type '" "gum::MarkovBlanket *""'");
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MarkovBlanket_dag" "', argument " "1"" of type '" "gum::MarkovBlanket *""'");
}
arg1 = reinterpret_cast< gum::MarkovBlanket * >(argp1);
{
try {
result = (arg1)->mb();
result = (arg1)->dag();
} catch (...) {
SetPythonizeAgrumException();
SWIG_fail;
}
}
resultobj = SWIG_NewPointerObj((new gum::DiGraph(static_cast< const gum::DiGraph& >(result))), SWIGTYPE_p_gum__DiGraph, SWIG_POINTER_OWN | 0 );
resultobj = SWIG_NewPointerObj((new gum::DAG(static_cast< const gum::DAG& >(result))), SWIGTYPE_p_gum__DAG, SWIG_POINTER_OWN | 0 );
return resultobj;
fail:
return NULL;
......@@ -119609,13 +119609,13 @@ static PyMethodDef SwigMethods[] = {
"MarkovBlanket(DAGmodel m, std::string const & name, int level=1)\n"
""},
{ "delete_MarkovBlanket", _wrap_delete_MarkovBlanket, METH_O, "delete_MarkovBlanket(MarkovBlanket self)"},
{ "MarkovBlanket_mb", _wrap_MarkovBlanket_mb, METH_O, "\n"
"MarkovBlanket_mb(MarkovBlanket self) -> DiGraph\n"
{ "MarkovBlanket_dag", _wrap_MarkovBlanket_dag, METH_O, "\n"
"MarkovBlanket_dag(MarkovBlanket self) -> DAG\n"
"\n"
"Returns\n"
"-------\n"
"pyAgrum.DiGraph\n"
" a copy of the directed graph\n"
"pyAgrum.DAG\n"
" a copy of the DAG\n"
"\n"
""},
{ "MarkovBlanket_toDot", _wrap_MarkovBlanket_toDot, METH_O, "\n"
......@@ -331,7 +331,7 @@ def _saveFigProba(p, filename):
plt.close(fig)
def BNinference2dot(bn, size=None, engine=None, evs={}, targets={}, nodeColor=None, arcWidth=None, arcColor=None, cmapNode=None, cmapArc=None):
def BNinference2dot(bn, size=None, engine=None, evs={}, targets={}, nodeColor=None, arcWidth=None, arcColor=None, cmapNode=None, cmapArc=None,dag=None):
"""
create a pydotplus representation of an inference in a BN
......@@ -345,6 +345,7 @@ def BNinference2dot(bn, size=None, engine=None, evs={}, targets={}, nodeColor=No
:param arcColor: a arcMap of values (between 0 and 1) to be shown as color of arcs
:param cmapNode: color map to show the vals of Nodes
:param cmapArc: color map to show the vals of Arcs
:param dag : only shows nodes that have their id in the dag (and not in the whole BN)
:return: the desired representation of the inference
"""
......@@ -381,8 +382,9 @@ def BNinference2dot(bn, size=None, engine=None, evs={}, targets={}, nodeColor=No
'", style=filled,color="' + \
gum.config["notebook", "default_node_fgcolor"]+'"];'+"\n"
dotstr += ' edge [color="'+getBlackInTheme()+'"];'+"\n"
for nid in bn.nodes():
showdag = bn.dag() if dag is None else dag
for nid in showdag.nodes():
name = bn.variable(nid).name()
# defaults
......@@ -413,7 +415,7 @@ def BNinference2dot(bn, size=None, engine=None, evs={}, targets={}, nodeColor=No
else:
dotstr += ' "{0}" [{1}]'.format(name, colorattribute)
for a in bn.arcs():
for a in showdag.arcs():
(n, j) = a
if arcWidth is None:
pw = 1
......
......@@ -613,7 +613,7 @@ def showInformation(bn, evs=None, size=None, cmap=_INFOcmap):
return _reprInformation(bn, evs, size, cmap, asString=False)
def showInference(bn, engine=None, evs=None, targets=None, size=None, nodeColor=None, arcWidth=None, arcColor=None, cmap=None, cmapArc=None):
def showInference(bn, engine=None, evs=None, targets=None, size=None, nodeColor=None, arcWidth=None, arcColor=None, cmap=None, cmapArc=None, dag=None):
"""
show pydot graph for an inference in a notebook
......@@ -627,6 +627,7 @@ def showInference(bn, engine=None, evs=None, targets=None, size=None, nodeColor
:param arcColor: a arcMap of values (between 0 and 1) to be shown as color of arcs
:param cmap: color map to show the color of nodes and arcs
:param cmapArc: color map to show the vals of Arcs.
:param dag : only shows nodes that have their id in the dag (and not in the whole BN)
:return: the desired representation of the inference
"""
......@@ -639,10 +640,10 @@ def showInference(bn, engine=None, evs=None, targets=None, size=None, nodeColor
if targets is None:
targets = {}
return showGraph(BNinference2dot(bn, size, engine, evs, targets, nodeColor, arcWidth, arcColor, cmap, cmapArc), size)
return showGraph(BNinference2dot(bn, size, engine, evs, targets, nodeColor, arcWidth, arcColor, cmap, cmapArc,dag), size)
def getInference(bn, engine=None, evs=None, targets=None, size=None, nodeColor=None, arcWidth=None, arcColor=None, cmap=None, cmapArc=None):
def getInference(bn, engine=None, evs=None, targets=None, size=None, nodeColor=None, arcWidth=None, arcColor=None, cmap=None, cmapArc=None, dag=None):
"""
get a HTML string for an inference in a notebook
......@@ -656,6 +657,8 @@ def getInference(bn, engine=None, evs=None, targets=None, size=None, nodeColor=
:param arcColor: a arcMap of values (between 0 and 1) to be shown as color of arcs
:param cmap: color map to show the color of nodes and arcs
:param cmapArc: color map to show the vals of Arcs.
:param dag : only shows nodes that have their id in the dag (and not in the whole BN)
:return: the desired representation of the inference
"""
if size is None:
......
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