[pyAgrum] new sampling framework in pyAgrum

parent 167daa8e
#include <agrum/BN/inference/GibbsSampling.h>
template class gum::GibbsApproxInference<float>;
template class gum::GibbsApproxInference<double>;
template class gum::GibbsSampling<float>;
template class gum::GibbsSampling<double>;
......@@ -25,8 +25,8 @@
*/
#ifndef GUM_GIBBS_INFERENCE_2_H
#define GUM_GIBBS_INFERENCE_2_H
#ifndef GUM_GIBBS_SAMPLING_H
#define GUM_GIBBS_SAMPLING_H
#include <agrum/BN/inference/tools/approximateInference.h>
#include <agrum/BN/inference/tools/gibbsOperator.h>
......@@ -35,8 +35,8 @@
namespace gum {
/**
* @class GibbsApproxInference gibbsApproxInference.h
*<agrum/BN/inference/gibbsApproxInference.h>
* @class GibbsSampling gibbsSampling.h
*<agrum/BN/inference/gibbsSampling.h>
* @brief class for making Gibbs sampling inference in bayesian networks.
* @ingroup bn_approximation
*
......@@ -49,19 +49,19 @@ namespace gum {
*/
template <typename GUM_SCALAR>
class GibbsApproxInference : public ApproximateInference<GUM_SCALAR>,
class GibbsSampling : public ApproximateInference<GUM_SCALAR>,
public GibbsOperator<GUM_SCALAR> {
public:
/**
* Default constructor
*/
GibbsApproxInference( const IBayesNet<GUM_SCALAR>* BN );
GibbsSampling( const IBayesNet<GUM_SCALAR>* BN );
/**
* Destructor
*/
virtual ~GibbsApproxInference();
virtual ~GibbsSampling();
protected:
/// draws a defined number of samples without updating the estimators
......@@ -86,7 +86,7 @@ namespace gum {
*/
virtual Instantiation
_draw( float* w,
Instantiation prev = NULL,
Instantiation prev ,
const IBayesNet<GUM_SCALAR>& bn = BayesNet<GUM_SCALAR>(),
const NodeSet& hardEvNodes = NodeSet(),
const NodeProperty<Idx>& hardEv = NodeProperty<Idx>() );
......@@ -125,8 +125,8 @@ namespace gum {
virtual void _onEvidenceChanged( const NodeId id, bool hasChangedSoftHard );
};
extern template class GibbsApproxInference<float>;
extern template class GibbsApproxInference<double>;
extern template class GibbsSampling<float>;
extern template class GibbsSampling<double>;
}
#include <agrum/BN/inference/GibbsSampling_tpl.h>
......
......@@ -31,24 +31,24 @@ namespace gum {
/// default constructor
template <typename GUM_SCALAR>
GibbsApproxInference<GUM_SCALAR>::GibbsApproxInference(const IBayesNet<GUM_SCALAR>* BN)
GibbsSampling<GUM_SCALAR>::GibbsSampling(const IBayesNet<GUM_SCALAR>* BN)
: ApproximateInference<GUM_SCALAR>(BN), GibbsOperator<GUM_SCALAR>(*BN) {
GUM_CONSTRUCTOR(GibbsApproxInference);
GUM_CONSTRUCTOR(GibbsSampling);
}
/// destructor
template <typename GUM_SCALAR>
GibbsApproxInference<GUM_SCALAR>::~GibbsApproxInference() {
GibbsSampling<GUM_SCALAR>::~GibbsSampling() {
GUM_DESTRUCTOR(GibbsApproxInference);
GUM_DESTRUCTOR(GibbsSampling);
}
template <typename GUM_SCALAR>
Instantiation GibbsApproxInference<GUM_SCALAR>::_monteCarloSample(const IBayesNet<GUM_SCALAR>& bn){
Instantiation GibbsSampling<GUM_SCALAR>::_monteCarloSample(const IBayesNet<GUM_SCALAR>& bn){
return GibbsOperator<GUM_SCALAR>::_monteCarloSample(bn);
......@@ -56,7 +56,7 @@ namespace gum {
template <typename GUM_SCALAR>
Instantiation GibbsApproxInference<GUM_SCALAR>::_burnIn(){
Instantiation GibbsSampling<GUM_SCALAR>::_burnIn(){
gum::Instantiation Ip;
float w = 1.;
......@@ -76,7 +76,7 @@ namespace gum {
/// draws next sample for gibbs sampling
template <typename GUM_SCALAR>
Instantiation GibbsApproxInference<GUM_SCALAR>::_draw(float* w, Instantiation prev, const IBayesNet<GUM_SCALAR>& bn, const NodeSet& hardEvNodes, const NodeProperty<Idx>& hardEv){
Instantiation GibbsSampling<GUM_SCALAR>::_draw(float* w, Instantiation prev, const IBayesNet<GUM_SCALAR>& bn, const NodeSet& hardEvNodes, const NodeProperty<Idx>& hardEv){
return this->drawNextInstance(w, prev, this->BN());
}
......@@ -85,7 +85,7 @@ namespace gum {
/* initializing node properties after contextualizing the BN in order for the computation to be lighter */
template <typename GUM_SCALAR>
void GibbsApproxInference<GUM_SCALAR>::_onContextualize(BayesNetFragment<GUM_SCALAR>* bn, const NodeSet& targets, const NodeSet& hardEvNodes, const NodeProperty<Idx>& hardEv) {
void GibbsSampling<GUM_SCALAR>::_onContextualize(BayesNetFragment<GUM_SCALAR>* bn, const NodeSet& targets, const NodeSet& hardEvNodes, const NodeProperty<Idx>& hardEv) {
for (auto targ = targets.begin(); targ != targets.end(); ++targ)
this->addTarget(*targ);
......@@ -100,7 +100,7 @@ namespace gum {
template <typename GUM_SCALAR>
INLINE void GibbsApproxInference<GUM_SCALAR>::_onEvidenceAdded( const NodeId id,
INLINE void GibbsSampling<GUM_SCALAR>::_onEvidenceAdded( const NodeId id,
bool isHardEvidence ) {
if ( isHardEvidence )
this->addHardEvidence( id, this->hardEvidence()[id] );
......@@ -111,7 +111,7 @@ namespace gum {
}
template <typename GUM_SCALAR>
INLINE void GibbsApproxInference<GUM_SCALAR>::_onEvidenceErased( const NodeId id,
INLINE void GibbsSampling<GUM_SCALAR>::_onEvidenceErased( const NodeId id,
bool isHardEvidence ) {
if ( isHardEvidence )
this->eraseHardEvidence( id );
......@@ -120,13 +120,13 @@ namespace gum {
template <typename GUM_SCALAR>
INLINE void GibbsApproxInference<GUM_SCALAR>::_onAllEvidenceErased( bool contains_hard_evidence ){
INLINE void GibbsSampling<GUM_SCALAR>::_onAllEvidenceErased( bool contains_hard_evidence ){
this->eraseAllEvidenceOperator();
}
template <typename GUM_SCALAR>
INLINE void
GibbsApproxInference<GUM_SCALAR>::_onEvidenceChanged( const NodeId id,
GibbsSampling<GUM_SCALAR>::_onEvidenceChanged( const NodeId id,
bool hasChangedSoftHard ) {
if ( this->hardEvidence().exists( id ) ) {
// soft evidence has been removed
......
#include <agrum/BN/inference/MonteCarloSampling.h>
template class gum::MonteCarloApproxInference<float>;
template class gum::MonteCarloApproxInference<double>;
template class gum::MonteCarloSampling<float>;
template class gum::MonteCarloSampling<double>;
......@@ -32,70 +32,78 @@
namespace gum {
/**
* @class MonteCarloInference monteCarloInference.h
*<agrum/BN/inference/monteCarloInference.h>
* @brief class for making Monte Carlo sampling inference in bayesian networks.
* @ingroup bn_approximation
*
* This class overrides pure function declared in the inherited class ApproximateInference.
* It defines the way Monte Carlo sampling draws a sample.
*
*/
/**
* @class MonteCarloInference monteCarloInference.h
*<agrum/BN/inference/monteCarloInference.h>
* @brief class for making Monte Carlo sampling inference in bayesian networks.
* @ingroup bn_approximation
*
* This class overrides pure function declared in the inherited class ApproximateInference.
* It defines the way Monte Carlo sampling draws a sample.
*
*/
template <typename GUM_SCALAR>
class MonteCarloApproxInference : public ApproximateInference<GUM_SCALAR> {
template<typename GUM_SCALAR>
class MonteCarloSampling : public ApproximateInference<GUM_SCALAR> {
public:
/**
* Default constructor
*/
MonteCarloApproxInference(const IBayesNet<GUM_SCALAR>* BN);
/**
* Default constructor
*/
MonteCarloSampling(const IBayesNet<GUM_SCALAR> *BN);
/**
* Destructor
*/
virtual ~MonteCarloApproxInference();
/**
* Destructor
*/
virtual ~MonteCarloSampling();
protected:
/// draws a defined number of samples without updating the estimators
virtual Instantiation _burnIn ();
/// draws a sample according to classic Monte Carlo sampling
/**
* @param w the weight of sample being generated
* @param prev the previous sample generated
* @param bn the bayesian network containing the evidence
* @param hardEvNodes hard evidence nodes
* @param hardEv hard evidences values
*
* Generates a new sample using forward sampling, rejecting
* samples not consistent with evidence
*
*/
virtual Instantiation _draw (float* w , Instantiation prev = NULL, const IBayesNet<GUM_SCALAR>& bn = BayesNet<GUM_SCALAR>(), const NodeSet& hardEvNodes = NodeSet(), const NodeProperty<Idx>& hardEv = NodeProperty<Idx>());
///fired when Bayesian network is contextualized
/**
* @param bn the contextualized BayesNetFragment
* @param targets inference target variables
* @param hardEvNodes hard evidence nodes
* @param hardEv hard evidences values
*
* Adds the target and evidence variables.
*
*/
virtual void _onContextualize(BayesNetFragment<GUM_SCALAR>* bn, const NodeSet& targets ,const NodeSet& hardEvNodes, const NodeProperty<Idx>& hardEv);
};
extern template class MonteCarloApproxInference<float>;
extern template class MonteCarloApproxInference<double>;
/// draws a defined number of samples without updating the estimators
virtual Instantiation _burnIn();
/// draws a sample according to classic Monte Carlo sampling
/**
* @param w the weight of sample being generated
* @param prev the previous sample generated
* @param bn the bayesian network containing the evidence
* @param hardEvNodes hard evidence nodes
* @param hardEv hard evidences values
*
* Generates a new sample using forward sampling, rejecting
* samples not consistent with evidence
*
*/
virtual Instantiation
_draw(float *w, Instantiation prev, const IBayesNet<GUM_SCALAR> &bn = BayesNet<GUM_SCALAR>(),
const NodeSet &hardEvNodes = NodeSet(), const NodeProperty<Idx> &hardEv = NodeProperty<Idx>());
///fired when Bayesian network is contextualized
/**
* @param bn the contextualized BayesNetFragment
* @param targets inference target variables
* @param hardEvNodes hard evidence nodes
* @param hardEv hard evidences values
*
* Adds the target and evidence variables.
*
*/
virtual void
_onContextualize(BayesNetFragment<GUM_SCALAR> *bn, const NodeSet &targets, const NodeSet &hardEvNodes,
const NodeProperty<Idx> &hardEv);
};
extern template
class MonteCarloSampling<float>;
extern template
class MonteCarloSampling<double>;
}
#include <agrum/BN/inference/MonteCarloSampling_tpl.h>
#endif
......@@ -32,25 +32,25 @@ namespace gum {
/// Default constructor
template <typename GUM_SCALAR>
MonteCarloApproxInference<GUM_SCALAR>::MonteCarloApproxInference(const IBayesNet<GUM_SCALAR>* BN)
MonteCarloSampling<GUM_SCALAR>::MonteCarloSampling(const IBayesNet<GUM_SCALAR>* BN)
: ApproximateInference<GUM_SCALAR>(BN) {
this->setBurnIn(0);
GUM_CONSTRUCTOR(MonteCarloApproxInference);
GUM_CONSTRUCTOR(MonteCarloSampling);
}
/// Destructor
template <typename GUM_SCALAR>
MonteCarloApproxInference<GUM_SCALAR>::~MonteCarloApproxInference() {
MonteCarloSampling<GUM_SCALAR>::~MonteCarloSampling() {
GUM_DESTRUCTOR(MonteCarloApproxInference);
GUM_DESTRUCTOR(MonteCarloSampling);
}
/// no burn in needed for Monte Carlo sampling
template <typename GUM_SCALAR>
Instantiation MonteCarloApproxInference<GUM_SCALAR>::_burnIn(){
Instantiation MonteCarloSampling<GUM_SCALAR>::_burnIn(){
gum::Instantiation I;
return I;
}
......@@ -59,7 +59,7 @@ namespace gum {
template <typename GUM_SCALAR>
Instantiation MonteCarloApproxInference<GUM_SCALAR>::_draw(float* w, Instantiation prev, const IBayesNet<GUM_SCALAR>& bn, const NodeSet& hardEvNodes, const NodeProperty<Idx>& hardEv){
Instantiation MonteCarloSampling<GUM_SCALAR>::_draw(float* w, Instantiation prev, const IBayesNet<GUM_SCALAR>& bn, const NodeSet& hardEvNodes, const NodeProperty<Idx>& hardEv){
*w = 1.;
bool wrong_value = false;
......@@ -86,7 +86,7 @@ namespace gum {
template <typename GUM_SCALAR>
void MonteCarloApproxInference<GUM_SCALAR>::_onContextualize(BayesNetFragment<GUM_SCALAR>* bn, const NodeSet& targets, const NodeSet& hardEvNodes, const NodeProperty<Idx>& hardEv) {
void MonteCarloSampling<GUM_SCALAR>::_onContextualize(BayesNetFragment<GUM_SCALAR>* bn, const NodeSet& targets, const NodeSet& hardEvNodes, const NodeProperty<Idx>& hardEv) {
for (auto targ = targets.begin(); targ != targets.end(); ++targ)
this->addTarget(*targ);
......
#include <agrum/BN/inference/hybridApproxInference.h>
template class gum::HybridApproxInference<float, gum::WeightedApproxInference>;
template class gum::HybridApproxInference<double, gum::WeightedApproxInference>;
template class gum::HybridApproxInference<float, gum::WeightedSampling>;
template class gum::HybridApproxInference<double, gum::WeightedSampling>;
template class gum::HybridApproxInference<float, gum::ImportanceApproxInference>;
template class gum::HybridApproxInference<double, gum::ImportanceApproxInference>;
template class gum::HybridApproxInference<float, gum::ImportanceSampling>;
template class gum::HybridApproxInference<double, gum::ImportanceSampling>;
template class gum::HybridApproxInference<float, gum::GibbsApproxInference>;
template class gum::HybridApproxInference<double, gum::GibbsApproxInference>;
template class gum::HybridApproxInference<float, gum::GibbsSampling>;
template class gum::HybridApproxInference<double, gum::GibbsSampling>;
template class gum::HybridApproxInference<float, gum::MonteCarloApproxInference>;
template class gum::HybridApproxInference<double, gum::MonteCarloApproxInference>;
template class gum::HybridApproxInference<float, gum::MonteCarloSampling>;
template class gum::HybridApproxInference<double, gum::MonteCarloSampling>;
......@@ -70,17 +70,17 @@ namespace gum {
};
extern template class HybridApproxInference<float, WeightedApproxInference>;
extern template class HybridApproxInference<double, WeightedApproxInference>;
extern template class HybridApproxInference<float, WeightedSampling>;
extern template class HybridApproxInference<double, WeightedSampling>;
extern template class HybridApproxInference<float, ImportanceApproxInference>;
extern template class HybridApproxInference<double, ImportanceApproxInference>;
extern template class HybridApproxInference<float, ImportanceSampling>;
extern template class HybridApproxInference<double, ImportanceSampling>;
extern template class HybridApproxInference<float, MonteCarloApproxInference>;
extern template class HybridApproxInference<double, MonteCarloApproxInference>;
extern template class HybridApproxInference<float, MonteCarloSampling>;
extern template class HybridApproxInference<double, MonteCarloSampling>;
extern template class HybridApproxInference<float, GibbsApproxInference>;
extern template class HybridApproxInference<double, GibbsApproxInference>;
extern template class HybridApproxInference<float, GibbsSampling>;
extern template class HybridApproxInference<double, GibbsSampling>;
}
......
#include <agrum/BN/inference/importanceSampling.h>
template class gum::ImportanceApproxInference<float>;
template class gum::ImportanceApproxInference<double>;
template class gum::ImportanceSampling<float>;
template class gum::ImportanceSampling<double>;
......@@ -32,85 +32,93 @@
namespace gum {
/**
* @class ImportanceInference importanceInference.h
*<agrum/BN/inference/importanceInference.h>
* @brief class for making Importance sampling inference in bayesian networks.
* @ingroup bn_approximation
*
* This class overrides pure function declared in the inherited class ApproximateInference.
* It defines the way Importance sampling draws a sample.
*
*/
/**
* @class ImportanceInference importanceInference.h
*<agrum/BN/inference/importanceInference.h>
* @brief class for making Importance sampling inference in bayesian networks.
* @ingroup bn_approximation
*
* This class overrides pure function declared in the inherited class ApproximateInference.
* It defines the way Importance sampling draws a sample.
*
*/
template <typename GUM_SCALAR>
class ImportanceApproxInference : public ApproximateInference<GUM_SCALAR> {
template<typename GUM_SCALAR>
class ImportanceSampling : public ApproximateInference<GUM_SCALAR> {
public:
/**
* Default constructor
*/
ImportanceApproxInference(const IBayesNet<GUM_SCALAR>* BN);
/**
* Default constructor
*/
ImportanceSampling(const IBayesNet<GUM_SCALAR> *BN);
/**
* Destructor
*/
virtual ~ImportanceApproxInference();
/**
* Destructor
*/
virtual ~ImportanceSampling();
protected:
/// draws a defined number of samples without updating the estimators
virtual Instantiation _burnIn ();
/// draws a sample according to Importance sampling
/**
* @param w the weight of sample being generated
* @param prev the previous sample generated
* @param bn the bayesian network containing the evidence
* @param hardEvNodes hard evidence nodes
* @param hardEv hard evidences values
*
* uses the Importance sampling method to generate a new sample using an
* evidence-mutilated Bayesian network.
* Each node added to the sample (in a topological order) has a weight.
* The sample's weight is the product of all weights.
*/
virtual Instantiation _draw (float* w , Instantiation prev = NULL, const IBayesNet<GUM_SCALAR>& bn = BayesNet<GUM_SCALAR>(), const NodeSet& hardEvNodes = NodeSet(), const NodeProperty<Idx>& hardEv = NodeProperty<Idx>());
/// modifies the cpts of a BN in order to tend to uniform distributions
/**
* @param bn a BN fragment on which we wish to modify CPTs
* @param epsilon a default parameter used to scale the modification of the distributions
*
* For every CPT in the BN, epsilon is added to each potential value before normalizing
*
*/
virtual void _unsharpenBN (BayesNetFragment<GUM_SCALAR>* bn, float epsilon = 1e-2);
///fired when Bayesian network is contextualized
/**
* @param bn the contextualized BayesNetFragment
* @param targets inference target variables
* @param hardEvNodes hard evidence nodes
* @param hardEv hard evidences values
*
* Adds the target variables, erases the evidence variables and unsharpens the BN.
*
*/
virtual void _onContextualize(BayesNetFragment<GUM_SCALAR>* bn, const NodeSet& targets ,const NodeSet& hardEvNodes, const NodeProperty<Idx>& hardEv);
};
extern template class ImportanceApproxInference<float>;
extern template class ImportanceApproxInference<double>;
/// draws a defined number of samples without updating the estimators
virtual Instantiation _burnIn();
/// draws a sample according to Importance sampling
/**
* @param w the weight of sample being generated
* @param prev the previous sample generated
* @param bn the bayesian network containing the evidence
* @param hardEvNodes hard evidence nodes
* @param hardEv hard evidences values
*
* uses the Importance sampling method to generate a new sample using an
* evidence-mutilated Bayesian network.
* Each node added to the sample (in a topological order) has a weight.
* The sample's weight is the product of all weights.
*/
virtual Instantiation
_draw(float *w, Instantiation prev, const IBayesNet<GUM_SCALAR> &bn = BayesNet<GUM_SCALAR>(),
const NodeSet &hardEvNodes = NodeSet(), const NodeProperty<Idx> &hardEv = NodeProperty<Idx>());
/// modifies the cpts of a BN in order to tend to uniform distributions
/**
* @param bn a BN fragment on which we wish to modify CPTs
* @param epsilon a default parameter used to scale the modification of the distributions
*
* For every CPT in the BN, epsilon is added to each potential value before normalizing
*
*/
virtual void _unsharpenBN(BayesNetFragment<GUM_SCALAR> *bn, float epsilon = 1e-2);
///fired when Bayesian network is contextualized
/**
* @param bn the contextualized BayesNetFragment
* @param targets inference target variables
* @param hardEvNodes hard evidence nodes
* @param hardEv hard evidences values
*
* Adds the target variables, erases the evidence variables and unsharpens the BN.
*
*/
virtual void
_onContextualize(BayesNetFragment<GUM_SCALAR> *bn, const NodeSet &targets, const NodeSet &hardEvNodes,
const NodeProperty<Idx> &hardEv);
};
extern template
class ImportanceSampling<float>;
extern template
class ImportanceSampling<double>;
}
#include <agrum/BN/inference/importanceSampling_tpl.h>
#endif
......@@ -32,32 +32,32 @@ namespace gum {
/// default constructor
template <typename GUM_SCALAR>
ImportanceApproxInference<GUM_SCALAR>::ImportanceApproxInference(const IBayesNet<GUM_SCALAR>* BN)
ImportanceSampling<GUM_SCALAR>::ImportanceSampling(const IBayesNet<GUM_SCALAR>* BN)
: ApproximateInference<GUM_SCALAR>(BN) {
this->setBurnIn(0);
GUM_CONSTRUCTOR(ImportanceApproxInference);
GUM_CONSTRUCTOR(ImportanceSampling);
}
/// destructor
template <typename GUM_SCALAR>
ImportanceApproxInference<GUM_SCALAR>::~ImportanceApproxInference() {
ImportanceSampling<GUM_SCALAR>::~ImportanceSampling() {
GUM_DESTRUCTOR(ImportanceApproxInference);
GUM_DESTRUCTOR(ImportanceSampling);
}
/// no burn in needed for Importance sampling
template <typename GUM_SCALAR>
Instantiation ImportanceApproxInference<GUM_SCALAR>::_burnIn(){
Instantiation ImportanceSampling<GUM_SCALAR>::_burnIn(){
Instantiation I;
return I;
}
template <typename GUM_SCALAR>
Instantiation ImportanceApproxInference<GUM_SCALAR>::_draw(float* w, Instantiation prev, const IBayesNet<GUM_SCALAR>& bn, const NodeSet& hardEvNodes, const NodeProperty<Idx>& hardEv){
Instantiation ImportanceSampling<GUM_SCALAR>::_draw(float* w, Instantiation prev, const IBayesNet<GUM_SCALAR>& bn, const NodeSet& hardEvNodes, const NodeProperty<Idx>& hardEv){
float probaP = 1.; float probaQ = 1.;
......@@ -93,7 +93,7 @@ namespace gum {
template <typename GUM_SCALAR>
void ImportanceApproxInference<GUM_SCALAR>::_unsharpenBN (BayesNetFragment<GUM_SCALAR>* bn, float epsilon ){
void ImportanceSampling<GUM_SCALAR>::_unsharpenBN (BayesNetFragment<GUM_SCALAR>* bn, float epsilon ){
for (auto nod: bn->nodes().asNodeSet()) {
Potential<GUM_SCALAR> *p = new Potential<GUM_SCALAR>();
......@@ -105,7 +105,7 @@ namespace gum {
}
template <typename GUM_SCALAR>
void ImportanceApproxInference<GUM_SCALAR>::_onContextualize(BayesNetFragment<GUM_SCALAR>* bn, const NodeSet& targets ,const NodeSet& hardEvNodes, const NodeProperty<Idx>& hardEv){
void ImportanceSampling<GUM_SCALAR>::_onContextualize(BayesNetFragment<GUM_SCALAR>* bn, const NodeSet& targets ,const NodeSet& hardEvNodes, const NodeProperty<Idx>& hardEv){
Sequence<NodeId> sid;
for (NodeSet::iterator ev = hardEvNodes.begin(); ev != hardEvNodes.end(); ++ev)
......
#include <agrum/BN/inference/weightedSampling.h>
template class gum::WeightedApproxInference<float>;
template class gum::WeightedApproxInference<double>;
template class gum::WeightedSampling<float>;
template class gum::WeightedSampling<double>;
......@@ -32,70 +32,78 @@
namespace gum {
/**
* @class WeightedInference weightedInference.h
*<agrum/BN/inference/weightedInference.h>
* @brief class for making Weighted sampling inference in bayesian networks.
* @ingroup bn_approximation
*
* This class overrides pure function declared in the inherited class ApproximateInference.
* It defines the way Weighted sampling draws a sample.
*
*/
template <typename GUM_SCALAR>
class WeightedApproxInference : public ApproximateInference<GUM_SCALAR> {
/**
* @class WeightedInference weightedInference.h
*<agrum/BN/inference/weightedInference.h>
* @brief class for making Weighted sampling inference in bayesian networks.
* @ingroup bn_approximation
*
* This class overrides pure function declared in the inherited class ApproximateInference.
* It defines the way Weighted sampling draws a sample.
*
*/
template<typename GUM_SCALAR>
class WeightedSampling : public ApproximateInference<GUM_SCALAR> {
public:
/**
* Default constructor
*/
WeightedApproxInference(const IBayesNet<GUM_SCALAR>* BN);
/**
* Destructor
*/
virtual ~WeightedApproxInference();
protected:
/// draws a defined number of samples without updating the estimators
virtual Instantiation _burnIn ();
/// draws a sample according to Weighted sampling
/**
* @param w the weight of sample being generated
* @param prev the previous sample generated
* @param bn the bayesian network containing the evidence
* @param hardEvNodes hard evidence nodes
* @param hardEv hard evidences values
*
* Generates a new sample in topological order. Each sample has a weight bias.
* The sample weight is the product of each node's weight.
*
*/
virtual Instantiation _draw (float* w , Instantiation prev = NULL, const IBayesNet<GUM_SCALAR>& bn = BayesNet<GUM_SCALAR>(), const NodeSet& hardEvNodes = NodeSet(), const NodeProperty<Idx>& hardEv = NodeProperty<Idx>());
///fired when Bayesian network is contextualized
/**