[aGrUM] testSuite for MarkovBlanket

parent 77542645
......@@ -63,6 +63,28 @@ namespace gum {
}
}
bool MarkovBlanket::hasSameStructure( const DAGmodel& other ) {
if ( size() != other.size() ) return false;
if ( sizeArcs() != other.sizeArcs() ) return false;
for ( const auto& nid : nodes() ) {
try {
other.idFromName( __dag.variable( nid ).name() );
} catch ( NotFound ) {
return false;
}
}
for ( const auto& arc : arcs() ) {
if ( !other.arcs().exists(
Arc( other.idFromName( __dag.variable( arc.tail() ).name() ),
other.idFromName( __dag.variable( arc.head() ).name() ) ) ) )
return false;
}
return true;
}
std::string MarkovBlanket::toDot( void ) const {
std::stringstream output;
......
......@@ -79,6 +79,10 @@ namespace gum {
/// wrapping @ref DiGraph::nodes()
const NodeGraphPart& nodes() const;
/// @return true if all the named node are the same and all the named arcs are
/// the same
bool hasSameStructure( const DAGmodel& other );
private:
void __buildMarkovBlanket();
......
......@@ -71,6 +71,32 @@ namespace gum_tests {
TS_ASSERT_EQUALS( mb.sizeArcs(), 1u );
}
}
void testMarkovBlanketStructure() {
const auto bn =
gum::BayesNet<int>::fastPrototype( "a->b->c->d->e;f->d->g;h->i->g" );
TS_ASSERT( !gum::MarkovBlanket( bn, "a" ).hasSameStructure(
gum::BayesNet<int>::fastPrototype( "b->a" ) ) );
TS_ASSERT( gum::MarkovBlanket( bn, "a" ).hasSameStructure(
gum::BayesNet<int>::fastPrototype( "a->b" ) ) );
TS_ASSERT( gum::MarkovBlanket( bn, "b" ).hasSameStructure(
gum::BayesNet<int>::fastPrototype( "a->b->c" ) ) );
TS_ASSERT( gum::MarkovBlanket( bn, "c" ).hasSameStructure(
gum::BayesNet<int>::fastPrototype( "b->c->d;f->d" ) ) );
TS_ASSERT( gum::MarkovBlanket( bn, "d" ).hasSameStructure(
gum::BayesNet<int>::fastPrototype( "c->d->e;f->d->g;i->g" ) ) );
TS_ASSERT( gum::MarkovBlanket( bn, "e" ).hasSameStructure(
gum::BayesNet<int>::fastPrototype( "d->e" ) ) );
TS_ASSERT( gum::MarkovBlanket( bn, "f" ).hasSameStructure(
gum::BayesNet<int>::fastPrototype( "c->d;f->d;" ) ) );
TS_ASSERT( gum::MarkovBlanket( bn, "g" ).hasSameStructure(
gum::BayesNet<int>::fastPrototype( "d->g;i->g;" ) ) );
TS_ASSERT( gum::MarkovBlanket( bn, "h" ).hasSameStructure(
gum::BayesNet<int>::fastPrototype( "h->i;" ) ) );
TS_ASSERT( gum::MarkovBlanket( bn, "i" ).hasSameStructure(
gum::BayesNet<int>::fastPrototype( "d->g;h->i->g;;" ) ) );
}
};
} // gum_tests
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