[aGrUM] failed tests in MarginalTargetedInference

parent 1f62754f
......@@ -345,6 +345,7 @@ namespace gum_tests {
TS_ASSERT_DELTA( proba, proba2, 1e-5 );
}
void testAsia() {
std::string file = GET_RESSOURCES_PATH( "asia.bif" );
gum::BayesNet<float> bn;
......@@ -832,16 +833,16 @@ namespace gum_tests {
TS_ASSERT_EQUALS( res.nbrDim(),
gum::Size( 4 ) ); // MarkovBlanket(E)=(A,D,C)
try {
auto joint = bn.cpt("A") * bn.cpt("B") * bn.cpt("C") * bn.cpt("D") *
bn.cpt("E") * bn.cpt("F") * bn.cpt("H");
auto pADCE = joint.margSumIn({&bn.variableFromName("A"),
&bn.variableFromName("C"),
&bn.variableFromName("D"),
&bn.variableFromName("E")});
auto pADC = pADCE.margSumOut({&bn.variableFromName("E")});
TS_ASSERT_EQUALS(res, pADCE / pADC);
} catch (gum::Exception& e) {
GUM_SHOWERROR(e);
auto joint = bn.cpt( "A" ) * bn.cpt( "B" ) * bn.cpt( "C" ) *
bn.cpt( "D" ) * bn.cpt( "E" ) * bn.cpt( "F" ) * bn.cpt( "H" );
auto pADCE = joint.margSumIn( {&bn.variableFromName( "A" ),
&bn.variableFromName( "C" ),
&bn.variableFromName( "D" ),
&bn.variableFromName( "E" )} );
auto pADC = pADCE.margSumOut( {&bn.variableFromName( "E" )} );
TS_ASSERT_EQUALS( res, pADCE / pADC );
} catch ( gum::Exception& e ) {
GUM_SHOWERROR( e );
}
}
void testJointWithHardEvidence() {
......@@ -871,39 +872,39 @@ namespace gum_tests {
TS_ASSERT( false );
}
}
void testJointEvidenceImpact() {
/*
F A
\ / \
B |
| E
C |
/ \ /
H D
*/
auto bn =
gum::BayesNet<double>::fastPrototype( "A->B->C->D;A->E->D;F->B;C->H;" );
gum::LazyPropagation<double> ie( &bn );
gum::Potential<double> res;
TS_GUM_ASSERT_THROWS_NOTHING(
res = ie.evidenceJointImpact( {"D","E"}, {"A", "B", "C", "F"} ) );
TS_ASSERT_EQUALS( res.nbrDim(),
gum::Size( 4 ) ); // MarkovBlanket(E)=(A,D,C)
try {
auto joint = bn.cpt("A") * bn.cpt("B") * bn.cpt("C") * bn.cpt("D") *
bn.cpt("E") * bn.cpt("F") * bn.cpt("H");
auto pADCE = joint.margSumIn({&bn.variableFromName("A"),
&bn.variableFromName("C"),
&bn.variableFromName("D"),
&bn.variableFromName("E")});
auto pAC = pADCE.margSumOut({&bn.variableFromName("D"),&bn.variableFromName("E")});
TS_ASSERT_EQUALS(res, pADCE / pAC);
} catch (gum::Exception& e) {
GUM_SHOWERROR(e);
}
}
void testJointEvidenceImpact() {
/*
F A
\ / \
B |
| E
C |
/ \ /
H D
*/
auto bn =
gum::BayesNet<double>::fastPrototype( "A->B->C->D;A->E->D;F->B;C->H;" );
gum::LazyPropagation<double> ie( &bn );
gum::Potential<double> res;
TS_GUM_ASSERT_THROWS_NOTHING(
res = ie.evidenceJointImpact( {"D", "E"}, {"A", "B", "C", "F"} ) );
TS_ASSERT_EQUALS( res.nbrDim(),
gum::Size( 4 ) ); // MarkovBlanket(E)=(A,D,C)
try {
auto joint = bn.cpt( "A" ) * bn.cpt( "B" ) * bn.cpt( "C" ) *
bn.cpt( "D" ) * bn.cpt( "E" ) * bn.cpt( "F" ) * bn.cpt( "H" );
auto pADCE = joint.margSumIn( {&bn.variableFromName( "A" ),
&bn.variableFromName( "C" ),
&bn.variableFromName( "D" ),
&bn.variableFromName( "E" )} );
auto pAC = pADCE.margSumOut(
{&bn.variableFromName( "D" ), &bn.variableFromName( "E" )} );
TS_ASSERT_EQUALS( res, pADCE / pAC );
} catch ( gum::Exception& e ) {
GUM_SHOWERROR( e );
}
}
private:
// Builds a BN to test the inference
......
/***************************************************************************
* Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Christophe GONZALES *
* {prenom.nom}_at_lip6.fr *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <cmath>
#include <iostream>
#include <string>
#include <agrum/BN/inference/ShaferShenoyInference.h>
#include <agrum/BN/inference/lazyPropagation.h>
#include <agrum/BN/inference/variableElimination.h>
#include <cxxtest/AgrumTestSuite.h>
#include <cxxtest/testsuite_utils.h>
// The graph used for the tests:
// 1 2_ 1 -> 3
// / \ / / 1 -> 4
// 3 4 / 3 -> 5
// \ / / 4 -> 5
// 5_/ 2 -> 4
// 2 -> 5
namespace gum_tests {
class MarginalTargetedInferenceTestSuite : public CxxTest::TestSuite {
public:
void testAddTarget() {
auto bn =
gum::BayesNet<double>::fastPrototype( "A->B->C->D;A->E->D;F->B;C->H;" );
gum::LazyPropagation<double> lazy( &bn );
lazy.addTarget( "A" );
TS_ASSERT( lazy.targets() == gum::NodeSet( {0} ) );
lazy.addTarget( "B" );
TS_ASSERT( lazy.targets() == gum::NodeSet( {0, 1} ) );
gum::ShaferShenoyInference<double> shafer( &bn );
shafer.addTarget( "A" );
TS_ASSERT( shafer.targets() == gum::NodeSet( {0} ) );
shafer.addTarget( "B" );
TS_ASSERT( shafer.targets() == gum::NodeSet( {0, 1} ) );
gum::VariableElimination<double> ve( &bn );
ve.addTarget( "A" );
TS_ASSERT( ve.targets() == gum::NodeSet( {0} ) );
ve.addTarget( "B" );
TS_ASSERT( ve.targets() == gum::NodeSet( {0, 1} ) );
}
};
}
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