[aGrUM/pyAgrum] add samplingInference::currentEstimation() for anytime query +…

[aGrUM/pyAgrum] add samplingInference::currentEstimation() for anytime query + fix a small bug in notification for approximationSchemeListener
parent 2de256f0
Pipeline #13793882 passed with stages
in 31 minutes 53 seconds
......@@ -71,6 +71,38 @@ namespace gum {
/// destructor
virtual ~SamplingInference();
/// Computes and returns the actual estimation of the posterior of a node.
/**
* @returns a const ref to the posterior probability of the node.
* @param id the node for which we need a posterior probability
*
* @warning for efficiency reasons, the potential is returned by reference.
* In order to ensure that the potential may still exist even if the Inference
* object is destroyed, the user has to copy it explicitly.
*
* @throw UndefinedElement if node is not in the set of targets.
* @throw NotFound if node is not in the BN.
*/
const Potential< GUM_SCALAR >& currentPosterior(const NodeId id);
/// Computes and returns the actual estimation of the posterior of a node by
/// its name.
/**
* @returns a const ref to the posterior probability of the node referred by
* name.
* @param name the name of the node for which we need a posterior probability
*
* @warning for efficiency reasons, the potential is returned by reference.
* In order to ensure that the potential may still exist even if the Inference
* object is destroyed, the user has to copy it explicitly.
*
* @throw UndefinedElement if node corresponding to name is not in the set of
* targets.
* @throw NotFound if node corresponding to name is not in the BN.
*/
const Potential< GUM_SCALAR >& currentPosterior(const std::string& name);
/// @}
/// @}
......
......@@ -95,6 +95,18 @@ namespace gum {
template < typename GUM_SCALAR >
const Potential< GUM_SCALAR >&
SamplingInference< GUM_SCALAR >::currentPosterior(const NodeId id) {
return __estimator.posterior(this->BN().variable(id));
}
template < typename GUM_SCALAR >
const Potential< GUM_SCALAR >&
SamplingInference< GUM_SCALAR >::currentPosterior(const std::string& name) {
return currentPosterior(this->BN().idFromName(name));
}
template < typename GUM_SCALAR >
const Potential< GUM_SCALAR >&
SamplingInference< GUM_SCALAR >::_posterior(const NodeId id) {
return __estimator.posterior(this->BN().variable(id));
}
......
......@@ -67,7 +67,7 @@ namespace gum {
* @param time The time.
*/
virtual void whenProgress( const void* src,
const Size pourcent,
const Size step,
const double error,
const double time ) = 0;
......
......@@ -309,7 +309,7 @@ namespace gum {
if ( stateApproximationScheme() == ApproximationSchemeSTATE::Continue ) {
if ( onProgress.hasListener() ) {
GUM_EMIT3( onProgress,
( _current_step * 100 ) / _max_iter,
_current_step,
_current_epsilon,
timer_step );
}
......
......@@ -7751,6 +7751,14 @@ class GibbsSampling_double(_object):
return _pyAgrum.GibbsSampling_double_evidenceImpact(self, *args)
def currentPosterior(self, *args):
"""
currentPosterior(self, id) -> Potential_double
currentPosterior(self, name) -> Potential_double
"""
return _pyAgrum.GibbsSampling_double_currentPosterior(self, *args)
def nbrDrawnVar(self):
"""nbrDrawnVar(self) -> gum::Size"""
return _pyAgrum.GibbsSampling_double_nbrDrawnVar(self)
......@@ -8074,6 +8082,14 @@ class ImportanceSampling_double(_object):
"""
return _pyAgrum.ImportanceSampling_double_evidenceImpact(self, *args)
def currentPosterior(self, *args):
"""
currentPosterior(self, id) -> Potential_double
currentPosterior(self, name) -> Potential_double
"""
return _pyAgrum.ImportanceSampling_double_currentPosterior(self, *args)
ImportanceSampling_double_swigregister = _pyAgrum.ImportanceSampling_double_swigregister
ImportanceSampling_double_swigregister(ImportanceSampling_double)
......@@ -8378,6 +8394,14 @@ class WeightedSampling_double(_object):
"""
return _pyAgrum.WeightedSampling_double_evidenceImpact(self, *args)
def currentPosterior(self, *args):
"""
currentPosterior(self, id) -> Potential_double
currentPosterior(self, name) -> Potential_double
"""
return _pyAgrum.WeightedSampling_double_currentPosterior(self, *args)
WeightedSampling_double_swigregister = _pyAgrum.WeightedSampling_double_swigregister
WeightedSampling_double_swigregister(WeightedSampling_double)
......@@ -8682,6 +8706,14 @@ class MonteCarloSampling_double(_object):
"""
return _pyAgrum.MonteCarloSampling_double_evidenceImpact(self, *args)
def currentPosterior(self, *args):
"""
currentPosterior(self, id) -> Potential_double
currentPosterior(self, name) -> Potential_double
"""
return _pyAgrum.MonteCarloSampling_double_currentPosterior(self, *args)
MonteCarloSampling_double_swigregister = _pyAgrum.MonteCarloSampling_double_swigregister
MonteCarloSampling_double_swigregister(MonteCarloSampling_double)
......@@ -8996,6 +9028,14 @@ class LoopyImportanceSampling_double(_object):
"""
return _pyAgrum.LoopyImportanceSampling_double_evidenceImpact(self, *args)
def currentPosterior(self, *args):
"""
currentPosterior(self, id) -> Potential_double
currentPosterior(self, name) -> Potential_double
"""
return _pyAgrum.LoopyImportanceSampling_double_currentPosterior(self, *args)
LoopyImportanceSampling_double_swigregister = _pyAgrum.LoopyImportanceSampling_double_swigregister
LoopyImportanceSampling_double_swigregister(LoopyImportanceSampling_double)
......@@ -9310,6 +9350,14 @@ class LoopyWeightedSampling_double(_object):
"""
return _pyAgrum.LoopyWeightedSampling_double_evidenceImpact(self, *args)
def currentPosterior(self, *args):
"""
currentPosterior(self, id) -> Potential_double
currentPosterior(self, name) -> Potential_double
"""
return _pyAgrum.LoopyWeightedSampling_double_currentPosterior(self, *args)
LoopyWeightedSampling_double_swigregister = _pyAgrum.LoopyWeightedSampling_double_swigregister
LoopyWeightedSampling_double_swigregister(LoopyWeightedSampling_double)
......@@ -9625,6 +9673,14 @@ class LoopyGibbsSampling_double(_object):
return _pyAgrum.LoopyGibbsSampling_double_evidenceImpact(self, *args)
def currentPosterior(self, *args):
"""
currentPosterior(self, id) -> Potential_double
currentPosterior(self, name) -> Potential_double
"""
return _pyAgrum.LoopyGibbsSampling_double_currentPosterior(self, *args)
def nbrDrawnVar(self):
"""nbrDrawnVar(self) -> gum::Size"""
return _pyAgrum.LoopyGibbsSampling_double_nbrDrawnVar(self)
......
......@@ -7751,6 +7751,14 @@ class GibbsSampling_double(_object):
return _pyAgrum.GibbsSampling_double_evidenceImpact(self, *args)
def currentPosterior(self, *args) -> "gum::Potential< double > const &":
"""
currentPosterior(self, id) -> Potential_double
currentPosterior(self, name) -> Potential_double
"""
return _pyAgrum.GibbsSampling_double_currentPosterior(self, *args)
def nbrDrawnVar(self) -> "gum::Size":
"""nbrDrawnVar(self) -> gum::Size"""
return _pyAgrum.GibbsSampling_double_nbrDrawnVar(self)
......@@ -8074,6 +8082,14 @@ class ImportanceSampling_double(_object):
"""
return _pyAgrum.ImportanceSampling_double_evidenceImpact(self, *args)
def currentPosterior(self, *args) -> "gum::Potential< double > const &":
"""
currentPosterior(self, id) -> Potential_double
currentPosterior(self, name) -> Potential_double
"""
return _pyAgrum.ImportanceSampling_double_currentPosterior(self, *args)
ImportanceSampling_double_swigregister = _pyAgrum.ImportanceSampling_double_swigregister
ImportanceSampling_double_swigregister(ImportanceSampling_double)
......@@ -8378,6 +8394,14 @@ class WeightedSampling_double(_object):
"""
return _pyAgrum.WeightedSampling_double_evidenceImpact(self, *args)
def currentPosterior(self, *args) -> "gum::Potential< double > const &":
"""
currentPosterior(self, id) -> Potential_double
currentPosterior(self, name) -> Potential_double
"""
return _pyAgrum.WeightedSampling_double_currentPosterior(self, *args)
WeightedSampling_double_swigregister = _pyAgrum.WeightedSampling_double_swigregister
WeightedSampling_double_swigregister(WeightedSampling_double)
......@@ -8682,6 +8706,14 @@ class MonteCarloSampling_double(_object):
"""
return _pyAgrum.MonteCarloSampling_double_evidenceImpact(self, *args)
def currentPosterior(self, *args) -> "gum::Potential< double > const &":
"""
currentPosterior(self, id) -> Potential_double
currentPosterior(self, name) -> Potential_double
"""
return _pyAgrum.MonteCarloSampling_double_currentPosterior(self, *args)
MonteCarloSampling_double_swigregister = _pyAgrum.MonteCarloSampling_double_swigregister
MonteCarloSampling_double_swigregister(MonteCarloSampling_double)
......@@ -8996,6 +9028,14 @@ class LoopyImportanceSampling_double(_object):
"""
return _pyAgrum.LoopyImportanceSampling_double_evidenceImpact(self, *args)
def currentPosterior(self, *args) -> "gum::Potential< double > const &":
"""
currentPosterior(self, id) -> Potential_double
currentPosterior(self, name) -> Potential_double
"""
return _pyAgrum.LoopyImportanceSampling_double_currentPosterior(self, *args)
LoopyImportanceSampling_double_swigregister = _pyAgrum.LoopyImportanceSampling_double_swigregister
LoopyImportanceSampling_double_swigregister(LoopyImportanceSampling_double)
......@@ -9310,6 +9350,14 @@ class LoopyWeightedSampling_double(_object):
"""
return _pyAgrum.LoopyWeightedSampling_double_evidenceImpact(self, *args)
def currentPosterior(self, *args) -> "gum::Potential< double > const &":
"""
currentPosterior(self, id) -> Potential_double
currentPosterior(self, name) -> Potential_double
"""
return _pyAgrum.LoopyWeightedSampling_double_currentPosterior(self, *args)
LoopyWeightedSampling_double_swigregister = _pyAgrum.LoopyWeightedSampling_double_swigregister
LoopyWeightedSampling_double_swigregister(LoopyWeightedSampling_double)
......@@ -9625,6 +9673,14 @@ class LoopyGibbsSampling_double(_object):
return _pyAgrum.LoopyGibbsSampling_double_evidenceImpact(self, *args)
def currentPosterior(self, *args) -> "gum::Potential< double > const &":
"""
currentPosterior(self, id) -> Potential_double
currentPosterior(self, name) -> Potential_double
"""
return _pyAgrum.LoopyGibbsSampling_double_currentPosterior(self, *args)
def nbrDrawnVar(self) -> "gum::Size":
"""nbrDrawnVar(self) -> gum::Size"""
return _pyAgrum.LoopyGibbsSampling_double_nbrDrawnVar(self)
......
......@@ -353,6 +353,23 @@ ADD_INFERENCE_API(gum::LoopySamplingInference<double,gum::ImportanceSampling>)
ADD_INFERENCE_API(gum::LoopySamplingInference<double,gum::GibbsSampling>)
ADD_INFERENCE_API(gum::LoopySamplingInference<double,gum::WeightedSampling>)
%define ADD_SAMPLING_INFERENCE_API(classname...)
%extend classname {
const gum::Potential<double>& currentPosterior(const NodeId id)
{return self->gum::SamplingInference<double>::currentPosterior(id);};
const gum::Potential<double>& currentPosterior(const std::string& name)
{return self->gum::SamplingInference<double>::currentPosterior(name);};
}
%enddef
ADD_SAMPLING_INFERENCE_API(gum::GibbsSampling<double>)
ADD_SAMPLING_INFERENCE_API(gum::MonteCarloSampling<double>)
ADD_SAMPLING_INFERENCE_API(gum::WeightedSampling<double>)
ADD_SAMPLING_INFERENCE_API(gum::ImportanceSampling<double>)
ADD_SAMPLING_INFERENCE_API(gum::LoopySamplingInference<double,gum::ImportanceSampling>)
ADD_SAMPLING_INFERENCE_API(gum::LoopySamplingInference<double,gum::GibbsSampling>)
ADD_SAMPLING_INFERENCE_API(gum::LoopySamplingInference<double,gum::WeightedSampling>)
%define ADD_JOINT_INFERENCE_API(classname)
%extend classname {
const Potential<double> posterior( const NodeId var ) {
......
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