[aGrUM] add a `level` for the construction of `level`th-order Markov Blanket

parent 5436f1bc
......@@ -34,35 +34,24 @@
#endif // GUM_NOINLINE
namespace gum {
MarkovBlanket::MarkovBlanket(const DAGmodel& m, NodeId id) :
MarkovBlanket::MarkovBlanket(const DAGmodel& m, NodeId id, int level) :
__model(m), __node(id) {
__buildMarkovBlanket();
}
MarkovBlanket::MarkovBlanket(const DAGmodel& m, const std::string& name) :
MarkovBlanket(m, m.idFromName(name)) {}
MarkovBlanket::~MarkovBlanket() {}
void MarkovBlanket::__buildMarkovBlanket() {
if (!__model.nodes().exists(__node))
GUM_ERROR(InvalidArgument, "Node " << __node << " does not exist.");
__mb.addNodeWithId(__node);
for (const auto& parent : __model.parents(__node)) {
__mb.addNodeWithId(parent);
__mb.addArc(parent, __node);
}
for (const auto& child : __model.children(__node)) {
if (!__mb.nodes().exists(child)) __mb.addNodeWithId(child);
__mb.addArc(__node, child);
for (const auto& opar : __model.parents(child)) {
if (opar != __node) {
if (!__mb.nodes().exists(opar)) __mb.addNodeWithId(opar);
__mb.addArc(opar, child);
}
if (level < 1)
GUM_ERROR(InvalidArgument, "Argument level(=" << level << ") must be >0.")
NodeSet done;
__buildMarkovBlanket(__node);
done.insert(__node);
while (level > 1) {
level--;
auto todo = __mb.nodes().asNodeSet() - done;
bool anythingnew = false;
for (NodeId n : todo) {
done.insert(n);
if (__buildMarkovBlanket(n)) anythingnew = true;
}
if (!anythingnew) break;
}
// we add now some arcs that are between the nodes in __mb but are not part of
......@@ -78,6 +67,51 @@ namespace gum {
}
}
MarkovBlanket::MarkovBlanket(const DAGmodel& m,
const std::string& name,
int level) :
MarkovBlanket(m, m.idFromName(name), level) {}
MarkovBlanket::~MarkovBlanket() {}
bool MarkovBlanket::__buildMarkovBlanket(const NodeId node) {
bool change = false;
if (!__model.nodes().exists(node))
GUM_ERROR(InvalidArgument, "Node " << node << " does not exist.");
if (!__mb.nodes().exists(node)) {
__mb.addNodeWithId(node);
change = true;
}
for (const auto& parent : __model.parents(node)) {
if (!__mb.nodes().exists(parent)) {
__mb.addNodeWithId(parent);
change = true;
}
__mb.addArc(parent, node);
}
for (const auto& child : __model.children(node)) {
if (!__mb.nodes().exists(child)) {
__mb.addNodeWithId(child);
change = true;
}
__mb.addArc(node, child);
for (const auto& opar : __model.parents(child)) {
if (opar != node) {
if (!__mb.nodes().exists(opar)) {
__mb.addNodeWithId(opar);
change = true;
}
__mb.addArc(opar, child);
}
}
}
return change;
}
bool MarkovBlanket::hasSameStructure(const DAGmodel& other) {
if (size() != other.size()) return false;
......
......@@ -48,8 +48,8 @@ namespace gum {
*/
class MarkovBlanket {
public:
MarkovBlanket(const DAGmodel& m, NodeId n);
MarkovBlanket(const DAGmodel& m, const std::string& name);
MarkovBlanket(const DAGmodel& m, NodeId n,int level=1);
MarkovBlanket(const DAGmodel& m, const std::string& name,int level=1);
~MarkovBlanket();
......@@ -88,7 +88,7 @@ namespace gum {
bool hasSameStructure(const DAGmodel& other);
private:
void __buildMarkovBlanket();
bool __buildMarkovBlanket(const NodeId id);
const DAGmodel& __model;
DiGraph __mb;
......
......@@ -108,6 +108,15 @@ namespace gum_tests {
"cc->dd->ee;ff->dd->gg;ff->gg;ff->ii->gg");
TS_ASSERT(gum::MarkovBlanket(bn, "dd").hasSameStructure(mb));
}
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_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));
}
};
} // namespace gum_tests
......@@ -6745,8 +6745,8 @@ class MarkovBlanket(object):
def __init__(self, *args):
r"""
__init__(MarkovBlanket self, DAGmodel m, gum::NodeId n) -> MarkovBlanket
__init__(MarkovBlanket self, DAGmodel m, std::string const & name) -> MarkovBlanket
__init__(MarkovBlanket self, DAGmodel m, gum::NodeId n, int level=1) -> MarkovBlanket
__init__(MarkovBlanket self, DAGmodel m, std::string const & name, int level=1) -> MarkovBlanket
"""
_pyAgrum.MarkovBlanket_swiginit(self, _pyAgrum.new_MarkovBlanket(*args))
__swig_destroy__ = _pyAgrum.delete_MarkovBlanket
......
......@@ -44711,6 +44711,53 @@ SWIGINTERN PyObject *EssentialGraph_swiginit(PyObject *SWIGUNUSEDPARM(self), PyO
}
SWIGINTERN PyObject *_wrap_new_MarkovBlanket__SWIG_0(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
PyObject *resultobj = 0;
gum::DAGmodel *arg1 = 0 ;
gum::NodeId arg2 ;
int arg3 ;
void *argp1 = 0 ;
int res1 = 0 ;
size_t val2 ;
int ecode2 = 0 ;
int val3 ;
int ecode3 = 0 ;
gum::MarkovBlanket *result = 0 ;
if ((nobjs < 3) || (nobjs > 3)) SWIG_fail;
res1 = SWIG_ConvertPtr(swig_obj[0], &argp1, SWIGTYPE_p_gum__DAGmodel, 0 | 0);
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_MarkovBlanket" "', argument " "1"" of type '" "gum::DAGmodel const &""'");
}
if (!argp1) {
SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "new_MarkovBlanket" "', argument " "1"" of type '" "gum::DAGmodel const &""'");
}
arg1 = reinterpret_cast< gum::DAGmodel * >(argp1);
ecode2 = SWIG_AsVal_size_t(swig_obj[1], &val2);
if (!SWIG_IsOK(ecode2)) {
SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "new_MarkovBlanket" "', argument " "2"" of type '" "gum::NodeId""'");
}
arg2 = static_cast< gum::NodeId >(val2);
ecode3 = SWIG_AsVal_int(swig_obj[2], &val3);
if (!SWIG_IsOK(ecode3)) {
SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "new_MarkovBlanket" "', argument " "3"" of type '" "int""'");
}
arg3 = static_cast< int >(val3);
{
try {
result = (gum::MarkovBlanket *)new gum::MarkovBlanket((gum::DAGmodel const &)*arg1,arg2,arg3);
} catch (...) {
SetPythonizeAgrumException();
SWIG_fail;
}
}
resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_gum__MarkovBlanket, SWIG_POINTER_NEW | 0 );
return resultobj;
fail:
return NULL;
}
SWIGINTERN PyObject *_wrap_new_MarkovBlanket__SWIG_1(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
PyObject *resultobj = 0;
gum::DAGmodel *arg1 = 0 ;
gum::NodeId arg2 ;
......@@ -44749,7 +44796,61 @@ fail:
}
SWIGINTERN PyObject *_wrap_new_MarkovBlanket__SWIG_1(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
SWIGINTERN PyObject *_wrap_new_MarkovBlanket__SWIG_2(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
PyObject *resultobj = 0;
gum::DAGmodel *arg1 = 0 ;
std::string *arg2 = 0 ;
int arg3 ;
void *argp1 = 0 ;
int res1 = 0 ;
int res2 = SWIG_OLDOBJ ;
int val3 ;
int ecode3 = 0 ;
gum::MarkovBlanket *result = 0 ;
if ((nobjs < 3) || (nobjs > 3)) SWIG_fail;
res1 = SWIG_ConvertPtr(swig_obj[0], &argp1, SWIGTYPE_p_gum__DAGmodel, 0 | 0);
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_MarkovBlanket" "', argument " "1"" of type '" "gum::DAGmodel const &""'");
}
if (!argp1) {
SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "new_MarkovBlanket" "', argument " "1"" of type '" "gum::DAGmodel const &""'");
}
arg1 = reinterpret_cast< gum::DAGmodel * >(argp1);
{
std::string *ptr = (std::string *)0;
res2 = SWIG_AsPtr_std_string(swig_obj[1], &ptr);
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "new_MarkovBlanket" "', argument " "2"" of type '" "std::string const &""'");
}
if (!ptr) {
SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "new_MarkovBlanket" "', argument " "2"" of type '" "std::string const &""'");
}
arg2 = ptr;
}
ecode3 = SWIG_AsVal_int(swig_obj[2], &val3);
if (!SWIG_IsOK(ecode3)) {
SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "new_MarkovBlanket" "', argument " "3"" of type '" "int""'");
}
arg3 = static_cast< int >(val3);
{
try {
result = (gum::MarkovBlanket *)new gum::MarkovBlanket((gum::DAGmodel const &)*arg1,(std::string const &)*arg2,arg3);
} catch (...) {
SetPythonizeAgrumException();
SWIG_fail;
}
}
resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_gum__MarkovBlanket, SWIG_POINTER_NEW | 0 );
if (SWIG_IsNewObj(res2)) delete arg2;
return resultobj;
fail:
if (SWIG_IsNewObj(res2)) delete arg2;
return NULL;
}
SWIGINTERN PyObject *_wrap_new_MarkovBlanket__SWIG_3(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
PyObject *resultobj = 0;
gum::DAGmodel *arg1 = 0 ;
std::string *arg2 = 0 ;
......@@ -44797,11 +44898,11 @@ fail:
SWIGINTERN PyObject *_wrap_new_MarkovBlanket(PyObject *self, PyObject *args) {
Py_ssize_t argc;
PyObject *argv[3] = {
PyObject *argv[4] = {
0
};
if (!(argc = SWIG_Python_UnpackTuple(args, "new_MarkovBlanket", 0, 2, argv))) SWIG_fail;
if (!(argc = SWIG_Python_UnpackTuple(args, "new_MarkovBlanket", 0, 3, argv))) SWIG_fail;
--argc;
if (argc == 2) {
int _v;
......@@ -44813,7 +44914,7 @@ SWIGINTERN PyObject *_wrap_new_MarkovBlanket(PyObject *self, PyObject *args) {
_v = SWIG_CheckState(res);
}
if (_v) {
return _wrap_new_MarkovBlanket__SWIG_0(self, argc, argv);
return _wrap_new_MarkovBlanket__SWIG_1(self, argc, argv);
}
}
}
......@@ -44825,7 +44926,45 @@ SWIGINTERN PyObject *_wrap_new_MarkovBlanket(PyObject *self, PyObject *args) {
int res = SWIG_AsPtr_std_string(argv[1], (std::string**)(0));
_v = SWIG_CheckState(res);
if (_v) {
return _wrap_new_MarkovBlanket__SWIG_1(self, argc, argv);
return _wrap_new_MarkovBlanket__SWIG_3(self, argc, argv);
}
}
}
if (argc == 3) {
int _v;
int res = SWIG_ConvertPtr(argv[0], 0, SWIGTYPE_p_gum__DAGmodel, SWIG_POINTER_NO_NULL | 0);
_v = SWIG_CheckState(res);
if (_v) {
{
int res = SWIG_AsVal_size_t(argv[1], NULL);
_v = SWIG_CheckState(res);
}
if (_v) {
{
int res = SWIG_AsVal_int(argv[2], NULL);
_v = SWIG_CheckState(res);
}
if (_v) {
return _wrap_new_MarkovBlanket__SWIG_0(self, argc, argv);
}
}
}
}
if (argc == 3) {
int _v;
int res = SWIG_ConvertPtr(argv[0], 0, SWIGTYPE_p_gum__DAGmodel, SWIG_POINTER_NO_NULL | 0);
_v = SWIG_CheckState(res);
if (_v) {
int res = SWIG_AsPtr_std_string(argv[1], (std::string**)(0));
_v = SWIG_CheckState(res);
if (_v) {
{
int res = SWIG_AsVal_int(argv[2], NULL);
_v = SWIG_CheckState(res);
}
if (_v) {
return _wrap_new_MarkovBlanket__SWIG_2(self, argc, argv);
}
}
}
}
......@@ -44833,7 +44972,9 @@ SWIGINTERN PyObject *_wrap_new_MarkovBlanket(PyObject *self, PyObject *args) {
fail:
SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'new_MarkovBlanket'.\n"
" Possible C/C++ prototypes are:\n"
" gum::MarkovBlanket::MarkovBlanket(gum::DAGmodel const &,gum::NodeId,int)\n"
" gum::MarkovBlanket::MarkovBlanket(gum::DAGmodel const &,gum::NodeId)\n"
" gum::MarkovBlanket::MarkovBlanket(gum::DAGmodel const &,std::string const &,int)\n"
" gum::MarkovBlanket::MarkovBlanket(gum::DAGmodel const &,std::string const &)\n");
return 0;
}
......@@ -119464,8 +119605,8 @@ static PyMethodDef SwigMethods[] = {
{ "EssentialGraph_swigregister", EssentialGraph_swigregister, METH_O, NULL},
{ "EssentialGraph_swiginit", EssentialGraph_swiginit, METH_VARARGS, NULL},
{ "new_MarkovBlanket", _wrap_new_MarkovBlanket, METH_VARARGS, "\n"
"MarkovBlanket(DAGmodel m, gum::NodeId n)\n"
"new_MarkovBlanket(DAGmodel m, std::string const & name) -> MarkovBlanket\n"
"MarkovBlanket(DAGmodel m, gum::NodeId n, int level=1)\n"
"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"
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -5297,19 +5297,13 @@ namespace swig
return const_reference(_seq, n);
}
bool check(bool set_err = true) const
bool check() const
{
Py_ssize_t s = size();
for (Py_ssize_t i = 0; i < s; ++i) {
swig::SwigVar_PyObject item = PySequence_GetItem(_seq, i);
if (!swig::check<value_type>(item)) {
if (set_err) {
char msg[1024];
sprintf(msg, "in sequence element %d", (int)i);
SWIG_Error(SWIG_RuntimeError, msg);
}
if (!swig::check<value_type>(item))
return false;
}
}
return true;
}
......@@ -44717,6 +44711,53 @@ SWIGINTERN PyObject *EssentialGraph_swiginit(PyObject *SWIGUNUSEDPARM(self), PyO
}
SWIGINTERN PyObject *_wrap_new_MarkovBlanket__SWIG_0(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
PyObject *resultobj = 0;
gum::DAGmodel *arg1 = 0 ;
gum::NodeId arg2 ;
int arg3 ;
void *argp1 = 0 ;
int res1 = 0 ;
size_t val2 ;
int ecode2 = 0 ;
int val3 ;
int ecode3 = 0 ;
gum::MarkovBlanket *result = 0 ;
if ((nobjs < 3) || (nobjs > 3)) SWIG_fail;
res1 = SWIG_ConvertPtr(swig_obj[0], &argp1, SWIGTYPE_p_gum__DAGmodel, 0 | 0);
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_MarkovBlanket" "', argument " "1"" of type '" "gum::DAGmodel const &""'");
}
if (!argp1) {
SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "new_MarkovBlanket" "', argument " "1"" of type '" "gum::DAGmodel const &""'");
}
arg1 = reinterpret_cast< gum::DAGmodel * >(argp1);
ecode2 = SWIG_AsVal_size_t(swig_obj[1], &val2);
if (!SWIG_IsOK(ecode2)) {
SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "new_MarkovBlanket" "', argument " "2"" of type '" "gum::NodeId""'");
}
arg2 = static_cast< gum::NodeId >(val2);
ecode3 = SWIG_AsVal_int(swig_obj[2], &val3);
if (!SWIG_IsOK(ecode3)) {
SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "new_MarkovBlanket" "', argument " "3"" of type '" "int""'");
}
arg3 = static_cast< int >(val3);
{
try {
result = (gum::MarkovBlanket *)new gum::MarkovBlanket((gum::DAGmodel const &)*arg1,arg2,arg3);
} catch (...) {
SetPythonizeAgrumException();
SWIG_fail;
}
}
resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_gum__MarkovBlanket, SWIG_POINTER_NEW | 0 );
return resultobj;
fail:
return NULL;
}
SWIGINTERN PyObject *_wrap_new_MarkovBlanket__SWIG_1(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
PyObject *resultobj = 0;
gum::DAGmodel *arg1 = 0 ;
gum::NodeId arg2 ;
......@@ -44755,7 +44796,61 @@ fail:
}
SWIGINTERN PyObject *_wrap_new_MarkovBlanket__SWIG_1(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
SWIGINTERN PyObject *_wrap_new_MarkovBlanket__SWIG_2(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
PyObject *resultobj = 0;
gum::DAGmodel *arg1 = 0 ;
std::string *arg2 = 0 ;
int arg3 ;
void *argp1 = 0 ;
int res1 = 0 ;
int res2 = SWIG_OLDOBJ ;
int val3 ;
int ecode3 = 0 ;
gum::MarkovBlanket *result = 0 ;
if ((nobjs < 3) || (nobjs > 3)) SWIG_fail;
res1 = SWIG_ConvertPtr(swig_obj[0], &argp1, SWIGTYPE_p_gum__DAGmodel, 0 | 0);
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_MarkovBlanket" "', argument " "1"" of type '" "gum::DAGmodel const &""'");
}
if (!argp1) {
SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "new_MarkovBlanket" "', argument " "1"" of type '" "gum::DAGmodel const &""'");
}
arg1 = reinterpret_cast< gum::DAGmodel * >(argp1);
{
std::string *ptr = (std::string *)0;
res2 = SWIG_AsPtr_std_string(swig_obj[1], &ptr);
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "new_MarkovBlanket" "', argument " "2"" of type '" "std::string const &""'");
}
if (!ptr) {
SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "new_MarkovBlanket" "', argument " "2"" of type '" "std::string const &""'");
}
arg2 = ptr;
}
ecode3 = SWIG_AsVal_int(swig_obj[2], &val3);
if (!SWIG_IsOK(ecode3)) {
SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "new_MarkovBlanket" "', argument " "3"" of type '" "int""'");
}
arg3 = static_cast< int >(val3);
{
try {
result = (gum::MarkovBlanket *)new gum::MarkovBlanket((gum::DAGmodel const &)*arg1,(std::string const &)*arg2,arg3);
} catch (...) {
SetPythonizeAgrumException();
SWIG_fail;
}
}
resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_gum__MarkovBlanket, SWIG_POINTER_NEW | 0 );
if (SWIG_IsNewObj(res2)) delete arg2;
return resultobj;
fail:
if (SWIG_IsNewObj(res2)) delete arg2;
return NULL;
}
SWIGINTERN PyObject *_wrap_new_MarkovBlanket__SWIG_3(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
PyObject *resultobj = 0;
gum::DAGmodel *arg1 = 0 ;
std::string *arg2 = 0 ;
......@@ -44803,11 +44898,11 @@ fail:
SWIGINTERN PyObject *_wrap_new_MarkovBlanket(PyObject *self, PyObject *args) {
Py_ssize_t argc;
PyObject *argv[3] = {
PyObject *argv[4] = {
0
};
if (!(argc = SWIG_Python_UnpackTuple(args, "new_MarkovBlanket", 0, 2, argv))) SWIG_fail;
if (!(argc = SWIG_Python_UnpackTuple(args, "new_MarkovBlanket", 0, 3, argv))) SWIG_fail;
--argc;
if (argc == 2) {
int _v;
......@@ -44819,7 +44914,7 @@ SWIGINTERN PyObject *_wrap_new_MarkovBlanket(PyObject *self, PyObject *args) {
_v = SWIG_CheckState(res);
}
if (_v) {
return _wrap_new_MarkovBlanket__SWIG_0(self, argc, argv);
return _wrap_new_MarkovBlanket__SWIG_1(self, argc, argv);
}
}
}
......@@ -44831,7 +44926,45 @@ SWIGINTERN PyObject *_wrap_new_MarkovBlanket(PyObject *self, PyObject *args) {
int res = SWIG_AsPtr_std_string(argv[1], (std::string**)(0));
_v = SWIG_CheckState(res);
if (_v) {
return _wrap_new_MarkovBlanket__SWIG_1(self, argc, argv);
return _wrap_new_MarkovBlanket__SWIG_3(self, argc, argv);
}
}
}
if (argc == 3) {
int _v;
int res = SWIG_ConvertPtr(argv[0], 0, SWIGTYPE_p_gum__DAGmodel, SWIG_POINTER_NO_NULL | 0);
_v = SWIG_CheckState(res);
if (_v) {
{
int res = SWIG_AsVal_size_t(argv[1], NULL);
_v = SWIG_CheckState(res);
}
if (_v) {
{
int res = SWIG_AsVal_int(argv[2], NULL);
_v = SWIG_CheckState(res);
}
if (_v) {
return _wrap_new_MarkovBlanket__SWIG_0(self, argc, argv);
}
}
}
}
if (argc == 3) {
int _v;
int res = SWIG_ConvertPtr(argv[0], 0, SWIGTYPE_p_gum__DAGmodel, SWIG_POINTER_NO_NULL | 0);
_v = SWIG_CheckState(res);
if (_v) {
int res = SWIG_AsPtr_std_string(argv[1], (std::string**)(0));
_v = SWIG_CheckState(res);
if (_v) {
{
int res = SWIG_AsVal_int(argv[2], NULL);
_v = SWIG_CheckState(res);
}
if (_v) {
return _wrap_new_MarkovBlanket__SWIG_2(self, argc, argv);
}
}
}
}
......@@ -44839,7 +44972,9 @@ SWIGINTERN PyObject *_wrap_new_MarkovBlanket(PyObject *self, PyObject *args) {
fail:
SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'new_MarkovBlanket'.\n"
" Possible C/C++ prototypes are:\n"
" gum::MarkovBlanket::MarkovBlanket(gum::DAGmodel const &,gum::NodeId,int)\n"
" gum::MarkovBlanket::MarkovBlanket(gum::DAGmodel const &,gum::NodeId)\n"
" gum::MarkovBlanket::MarkovBlanket(gum::DAGmodel const &,std::string const &,int)\n"
" gum::MarkovBlanket::MarkovBlanket(gum::DAGmodel const &,std::string const &)\n");
return 0;
}
......@@ -119470,8 +119605,8 @@ static PyMethodDef SwigMethods[] = {
{ "EssentialGraph_swigregister", EssentialGraph_swigregister, METH_O, NULL},
{ "EssentialGraph_swiginit", EssentialGraph_swiginit, METH_VARARGS, NULL},
{ "new_MarkovBlanket", _wrap_new_MarkovBlanket, METH_VARARGS, "\n"
"MarkovBlanket(DAGmodel m, gum::NodeId n)\n"
"new_MarkovBlanket(DAGmodel m, std::string const & name) -> MarkovBlanket\n"
"MarkovBlanket(DAGmodel m, gum::NodeId n, int level=1)\n"
"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"
# -*- encoding: UTF-8 -*-
# -*- encoding: UTF-8 -*-
import unittest
import pyAgrum as gum
......@@ -40,6 +40,14 @@ class TestMarkovBlanket(pyAgrumTestCase):
self.assertTrue(gum.MarkovBlanket(bn, "i").hasSameStructure(
gum.fastBN("d->g;h->i->g;;")))
def testMarkovBlanketMultiLevel(self):
bn=gum.fastBN("Z<-A->B->C->D->E<-Y;X->G<-F<-C<-I<-H->W")
self.assertEquals(gum.MarkovBlanket(bn, "C", 1).size(),5)
self.assertEquals(gum.MarkovBlanket(bn, "C", 2).size(),11)
self.assertEquals(gum.MarkovBlanket(bn, "C", 3).size(),13)
with self.assertRaises(gum.InvalidArgument):
err=gum.MarkovBlanket(bn, "C", 0)
ts = unittest.TestSuite()
addTests(ts, TestMarkovBlanket)
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