[aGrUM/pyAgrum] API : hybridApprox->loopySampling + sampling inference API in pyAgrum

parent d91a0d55
#include <agrum/BN/inference/hybridApproxInference.h>
template class gum::HybridApproxInference<float, gum::WeightedSampling>;
template class gum::HybridApproxInference<double, gum::WeightedSampling>;
template class gum::HybridApproxInference<float, gum::ImportanceSampling>;
template class gum::HybridApproxInference<double, gum::ImportanceSampling>;
template class gum::HybridApproxInference<float, gum::GibbsSampling>;
template class gum::HybridApproxInference<double, gum::GibbsSampling>;
template class gum::HybridApproxInference<float, gum::MonteCarloSampling>;
template class gum::HybridApproxInference<double, gum::MonteCarloSampling>;
......@@ -41,7 +41,7 @@ namespace gum {
/**
* Default constructor
*/
LoopyBeliefPropagation( const IBayesNet<GUM_SCALAR>* BN );
LoopyBeliefPropagation( const IBayesNet<GUM_SCALAR>* bn );
/**
* Destructor.
......
......@@ -43,8 +43,8 @@ namespace gum {
/// default constructor
template <typename GUM_SCALAR>
LoopyBeliefPropagation<GUM_SCALAR>::LoopyBeliefPropagation(
const IBayesNet<GUM_SCALAR>* BN )
: ApproximateInference<GUM_SCALAR>( BN ) {
const IBayesNet<GUM_SCALAR>* bn )
: ApproximateInference<GUM_SCALAR>( bn ) {
// for debugging purposes
GUM_CONSTRUCTOR( LoopyBeliefPropagation );
......
#include <agrum/BN/inference/loopySamplingInference.h>
template class gum::LoopySamplingInference<float, gum::WeightedSampling>;
template class gum::LoopySamplingInference<double, gum::WeightedSampling>;
template class gum::LoopySamplingInference<float, gum::ImportanceSampling>;
template class gum::LoopySamplingInference<double, gum::ImportanceSampling>;
template class gum::LoopySamplingInference<float, gum::GibbsSampling>;
template class gum::LoopySamplingInference<double, gum::GibbsSampling>;
template class gum::LoopySamplingInference<float, gum::MonteCarloSampling>;
template class gum::LoopySamplingInference<double, gum::MonteCarloSampling>;
......@@ -26,8 +26,8 @@
* @author Paul ALAM & Pierre-Henri WUILLEMIN
*/
#ifndef GUM_HYBRID_INFERENCE_H
#define GUM_HYBRID_INFERENCE_H
#ifndef GUM_LOOPY_INFERENCE_H
#define GUM_LOOPY_INFERENCE_H
#include <agrum/BN/inference/GibbsSampling.h>
#include <agrum/BN/inference/MonteCarloSampling.h>
#include <agrum/BN/inference/importanceSampling.h>
......@@ -38,37 +38,33 @@
namespace gum {
/**
* @class HybridApproxInference hybridApproxInference.h
*<agrum/BN/inference/hybridApproxInference.h>
* @class LoopySamplingInference LoopySamplingInference.h
*<agrum/BN/inference/loopySamplingInference.h>
* @brief class for making hybrid sampling inference with loopy belief propagation
*and
* an approximation inference method in bayesian networks.
* and an approximation inference method in bayesian networks.
* @ingroup bn_approximation
*
* This class inherits of template class APPROX, which SHOULD be one of the 4
*approximate
* inference methods (MonteCarlo, Weighted, Importance, Gibbs).
* approximate inference methods (MonteCarlo, Weighted, Importance, Gibbs).
* It makes the inference with respect to the inherited class' method, after
*having
* initialized the estimators with the posteriors obtained by running
*LoopyBeliefPropagation
* algorithm.
* having initialized the estimators with the posteriors obtained by running
* LoopyBeliefPropagation algorithm.
*
*/
template < typename GUM_SCALAR, template < typename > class APPROX >
class HybridApproxInference : public APPROX< GUM_SCALAR > {
class LoopySamplingInference : public APPROX< GUM_SCALAR > {
public:
/**
* Default constructor
*/
HybridApproxInference(const IBayesNet< GUM_SCALAR >* bn);
LoopySamplingInference(const IBayesNet< GUM_SCALAR >* bn);
/**
* destructor
*/
virtual ~HybridApproxInference();
virtual ~LoopySamplingInference();
/// makes the inference by generating samples w.r.t the mother class' sampling
/// method after initalizing estimators with loopy belief propagation
......@@ -82,30 +78,30 @@ namespace gum {
GUM_SCALAR _virtualLBPSize;
};
extern template class HybridApproxInference< float, WeightedSampling >;
extern template class HybridApproxInference< double, WeightedSampling >;
extern template class LoopySamplingInference< float, WeightedSampling >;
extern template class LoopySamplingInference< double, WeightedSampling >;
extern template class HybridApproxInference< float, ImportanceSampling >;
extern template class HybridApproxInference< double, ImportanceSampling >;
extern template class LoopySamplingInference< float, ImportanceSampling >;
extern template class LoopySamplingInference< double, ImportanceSampling >;
extern template class HybridApproxInference< float, MonteCarloSampling >;
extern template class HybridApproxInference< double, MonteCarloSampling >;
extern template class LoopySamplingInference< float, MonteCarloSampling >;
extern template class LoopySamplingInference< double, MonteCarloSampling >;
extern template class HybridApproxInference< float, GibbsSampling >;
extern template class HybridApproxInference< double, GibbsSampling >;
extern template class LoopySamplingInference< float, GibbsSampling >;
extern template class LoopySamplingInference< double, GibbsSampling >;
template < typename GUM_SCALAR >
using HybridMonteCarloSampling =
HybridApproxInference< GUM_SCALAR, MonteCarloSampling >;
LoopySamplingInference< GUM_SCALAR, MonteCarloSampling >;
template < typename GUM_SCALAR >
using HybridWeightedSampling =
HybridApproxInference< GUM_SCALAR, WeightedSampling >;
LoopySamplingInference< GUM_SCALAR, WeightedSampling >;
template < typename GUM_SCALAR >
using HybridImportanceSampling =
HybridApproxInference< GUM_SCALAR, ImportanceSampling >;
LoopySamplingInference< GUM_SCALAR, ImportanceSampling >;
template < typename GUM_SCALAR >
using HybridGibbsSampling = HybridApproxInference< GUM_SCALAR, GibbsSampling >;
using HybridGibbsSampling = LoopySamplingInference< GUM_SCALAR, GibbsSampling >;
}
#include <agrum/BN/inference/hybridApproxInference_tpl.h>
#include <agrum/BN/inference/loopySamplingInference_tpl.h>
#endif
......@@ -27,7 +27,7 @@
*/
#include <agrum/BN/inference/hybridApproxInference.h>
#include <agrum/BN/inference/loopySamplingInference.h>
#define DEFAULT_VIRTUAL_LBP_SIZE 5000
......@@ -35,23 +35,23 @@ namespace gum {
template < typename GUM_SCALAR, template < typename > class APPROX >
HybridApproxInference< GUM_SCALAR, APPROX >::HybridApproxInference(
LoopySamplingInference< GUM_SCALAR, APPROX >::LoopySamplingInference(
const IBayesNet< GUM_SCALAR >* BN)
: APPROX< GUM_SCALAR >(BN)
, _virtualLBPSize(DEFAULT_VIRTUAL_LBP_SIZE) {
GUM_CONSTRUCTOR(HybridApproxInference);
GUM_CONSTRUCTOR(LoopySamplingInference);
}
template < typename GUM_SCALAR, template < typename > class APPROX >
HybridApproxInference< GUM_SCALAR, APPROX >::~HybridApproxInference() {
LoopySamplingInference< GUM_SCALAR, APPROX >::~LoopySamplingInference() {
GUM_DESTRUCTOR(HybridApproxInference);
GUM_DESTRUCTOR(LoopySamplingInference);
}
template < typename GUM_SCALAR, template < typename > class APPROX >
void HybridApproxInference< GUM_SCALAR, APPROX >::_makeInference() {
void LoopySamplingInference< GUM_SCALAR, APPROX >::_makeInference() {
LoopyBeliefPropagation< GUM_SCALAR > lbp(&this->BN());
for (const auto x : this->hardEvidence()) {
......
......@@ -964,6 +964,13 @@ namespace gum_tests {
TS_ASSERT_THROWS( bn = gum::BayesNet<int>::fastPrototype( "a->b->c->a" ),
gum::InvalidDirectedCycle );
bn=gum.BayesNet<char>::fastPrototype("a{yes|maybe|no}->b->c;a->c");
TS_ASSERT_EQUALS( bn.size(), gum::Size( 3 ) );
TS_ASSERT_EQUALS( bn.sizeArcs(), gum::Size( 3 ) );
TS_ASSERT_EQUALS(
bn.dim(),
gum::Size( ( 3 - 1 ) + ( 3 * ( 2 - 1 ) ) + ( 3 * 2 * ( 2 - 1 ) ) ) );
}
};
......
......@@ -26,7 +26,7 @@
#include <agrum/BN/BayesNet.h>
#include <agrum/BN/inference/ShaferShenoyInference.h>
#include <agrum/BN/inference/hybridApproxInference.h>
#include <agrum/BN/inference/loopySamplingInference.h>
#include <agrum/BN/inference/lazyPropagation.h>
#include <agrum/BN/inference/variableElimination.h>
#include <agrum/BN/io/BIF/BIFReader.h>
......
......@@ -24,7 +24,7 @@
#include <cxxtest/testsuite_utils.h>
#include <agrum/BN/BayesNet.h>
#include <agrum/BN/inference/hybridApproxInference.h>
#include <agrum/BN/inference/loopySamplingInference.h>
#include <agrum/BN/inference/lazyPropagation.h>
#include <agrum/BN/inference/loopyBeliefPropagation.h>
#include <agrum/multidim/multiDimArray.h>
......@@ -65,7 +65,7 @@ namespace gum_tests {
std::string getMess() { return __mess; }
};
class HybridApproxTestSuite : public CxxTest::TestSuite {
class loopySamplingInferenceTestSuite : public CxxTest::TestSuite {
public:
void testHybridBinaryTreeWithoutEvidence() {
auto bn = gum::BayesNet< float >::fastPrototype(
......@@ -80,7 +80,7 @@ namespace gum_tests {
compareInference(__FILE__, __LINE__, bn, lazy, lbp);
GUM_APPROX_TEST_BEGIN_ITERATION
gum::HybridApproxInference< float, gum::WeightedSampling > inf(&bn);
gum::LoopySamplingInference< float, gum::WeightedSampling > inf(&bn);
inf.setEpsilon(EPSILON_FOR_HYBRID);
inf.setVerbosity(false);
inf.makeInference();
......@@ -105,7 +105,7 @@ namespace gum_tests {
lazy.makeInference();
GUM_APPROX_TEST_BEGIN_ITERATION
gum::HybridApproxInference< float, gum::ImportanceSampling > inf(&bn);
gum::LoopySamplingInference< float, gum::ImportanceSampling > inf(&bn);
inf.addEvidence(bn.idFromName(ev), 0);
inf.setEpsilon(EPSILON_FOR_HYBRID);
inf.makeInference();
......@@ -128,7 +128,7 @@ namespace gum_tests {
lazy.makeInference();
GUM_APPROX_TEST_BEGIN_ITERATION
gum::HybridApproxInference< float, gum::MonteCarloSampling > inf(&bn);
gum::LoopySamplingInference< float, gum::MonteCarloSampling > inf(&bn);
inf.addEvidence(bn.idFromName(ev), 0);
inf.setEpsilon(EPSILON_FOR_HYBRID);
inf.setVerbosity(false);
......@@ -153,7 +153,7 @@ namespace gum_tests {
lazy.makeInference();
GUM_APPROX_TEST_BEGIN_ITERATION
gum::HybridApproxInference< float, gum::WeightedSampling > inf(&bn);
gum::LoopySamplingInference< float, gum::WeightedSampling > inf(&bn);
inf.addEvidence(bn.idFromName(ev), 0);
inf.setEpsilon(EPSILON_FOR_HYBRID);
inf.setVerbosity(false);
......@@ -179,7 +179,7 @@ namespace gum_tests {
lazy.makeInference();
GUM_APPROX_TEST_BEGIN_ITERATION
gum::HybridApproxInference< float, gum::ImportanceSampling > inf(&bn);
gum::LoopySamplingInference< float, gum::ImportanceSampling > inf(&bn);
inf.addEvidence(bn.idFromName("e"), 0);
inf.addEvidence(bn.idFromName("b"), 1);
inf.addEvidence(bn.idFromName("h"), 0);
......@@ -209,7 +209,7 @@ namespace gum_tests {
lazy.makeInference();
GUM_APPROX_TEST_BEGIN_ITERATION
gum::HybridApproxInference< float, gum::ImportanceSampling > inf(&bn);
gum::LoopySamplingInference< float, gum::ImportanceSampling > inf(&bn);
inf.addEvidence(bn.idFromName("e"), 0);
inf.addEvidence(bn.idFromName("b"), 1);
inf.addEvidence(bn.idFromName("h"), 0);
......@@ -235,7 +235,7 @@ namespace gum_tests {
lazy.makeInference();
GUM_APPROX_TEST_BEGIN_ITERATION;
gum::HybridApproxInference< float, gum::GibbsSampling > inf(&bn);
gum::LoopySamplingInference< float, gum::GibbsSampling > inf(&bn);
inf.setVerbosity(false);
inf.setEpsilon(EPSILON_FOR_HYBRID);
inf.makeInference();
......@@ -254,7 +254,7 @@ namespace gum_tests {
lazy.makeInference();
GUM_APPROX_TEST_BEGIN_ITERATION;
gum::HybridApproxInference< float, gum::ImportanceSampling > inf(&bn);
gum::LoopySamplingInference< float, gum::ImportanceSampling > inf(&bn);
inf.addEvidence(bn.idFromName("a"), 0);
inf.setVerbosity(false);
inf.setEpsilon(EPSILON_FOR_HYBRID);
......@@ -274,7 +274,7 @@ namespace gum_tests {
lazy.makeInference();
GUM_APPROX_TEST_BEGIN_ITERATION;
gum::HybridApproxInference< float, gum::ImportanceSampling > inf(&bn);
gum::LoopySamplingInference< float, gum::ImportanceSampling > inf(&bn);
inf.addEvidence(bn.idFromName("d"), 0);
inf.setVerbosity(false);
inf.setEpsilon(EPSILON_FOR_HYBRID);
......@@ -299,7 +299,7 @@ namespace gum_tests {
lazy.makeInference();
GUM_APPROX_TEST_BEGIN_ITERATION;
gum::HybridApproxInference< float, gum::WeightedSampling > inf(&bn);
gum::LoopySamplingInference< float, gum::WeightedSampling > inf(&bn);
inf.setVerbosity(false);
inf.setEpsilon(EPSILON_FOR_HYBRID);
inf.makeInference();
......@@ -318,7 +318,7 @@ namespace gum_tests {
lazy.makeInference();
GUM_APPROX_TEST_BEGIN_ITERATION;
gum::HybridApproxInference< float, gum::ImportanceSampling > inf(&bn);
gum::LoopySamplingInference< float, gum::ImportanceSampling > inf(&bn);
inf.addEvidence(bn.idFromName("a"), 0);
inf.setVerbosity(false);
inf.setEpsilon(EPSILON_FOR_HYBRID);
......@@ -338,7 +338,7 @@ namespace gum_tests {
lazy.makeInference();
GUM_APPROX_TEST_BEGIN_ITERATION;
gum::HybridApproxInference< float, gum::GibbsSampling > inf(&bn);
gum::LoopySamplingInference< float, gum::GibbsSampling > inf(&bn);
inf.addEvidence(bn.idFromName("d"), 0);
inf.setVerbosity(false);
inf.setEpsilon(EPSILON_FOR_HARD_HYBRID);
......@@ -366,7 +366,7 @@ namespace gum_tests {
lazy.makeInference();
GUM_APPROX_TEST_BEGIN_ITERATION;
gum::HybridApproxInference< float, gum::GibbsSampling > inf(&bn);
gum::LoopySamplingInference< float, gum::GibbsSampling > inf(&bn);
inf.setVerbosity(false);
inf.setEpsilon(EPSILON_FOR_HARD_HYBRID);
inf.makeInference();
......@@ -396,7 +396,7 @@ namespace gum_tests {
GUM_APPROX_TEST_BEGIN_ITERATION;
gum::HybridApproxInference< float, gum::WeightedSampling > inf(&bn);
gum::LoopySamplingInference< float, gum::WeightedSampling > inf(&bn);
inf.setVerbosity(false);
inf.setEpsilon(EPSILON_FOR_HARD_HYBRID);
inf.makeInference();
......
......@@ -45,7 +45,7 @@ from .pyAgrum import Potential, Instantiation, UtilityTable
from .pyAgrum import BruteForceKL, GibbsSampling
from .pyAgrum import LazyPropagation, ShaferShenoyInference, VariableElimination
from .pyAgrum import LoopyBeliefPropagation, GibbsSampling, MonteCarloSampling, ImportanceSampling, WeightedSampling
from .pyAgrum import HybridImportanceSampling,HybridGibbsSampling,HybridWeightedSampling
from .pyAgrum import LoopyImportanceSampling,LoopyGibbsSampling,LoopyWeightedSampling
from .pyAgrum import PythonApproximationListener, PythonBNListener, PythonLoadListener
from .pyAgrum import BNGenerator, IDGenerator, JTGenerator
from .pyAgrum import BNLearner
......@@ -69,7 +69,7 @@ __all__=[
'Potential','Instantiation','UtilityTable',
'BruteForceKL','GibbsKL',
'LoopyBeliefPropagation','GibbsSampling','MonteCarloSampling', 'ImportanceSampling', 'WeightedSampling',
'HybridImportanceSampling','HybridGibbsSampling','HybridWeightedSampling',
'LoopyImportanceSampling','LoopyGibbsSampling','LoopyWeightedSampling',
'LazyPropagation','ShaferShenoyInference','VariableElimination',
'PythonApproximationListener','PythonBNListener','PythonLoadListener',
'BNGenerator','IDGenerator','JTGenerator',
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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