35 template <
typename GUM_SCALAR >
40 if (this->
__bn ==
nullptr) {
48 template <
typename GUM_SCALAR >
55 template <
typename GUM_SCALAR >
69 template <
typename GUM_SCALAR >
72 if (this->
__bn ==
nullptr)
74 "No Bayes net has been assigned to the " 75 "inference algorithm");
77 const auto& dag = this->
__bn->dag();
78 for (
const auto var : vars) {
79 if (!dag.exists(var)) {
89 template <
typename GUM_SCALAR >
96 template <
typename GUM_SCALAR >
109 template <
typename GUM_SCALAR >
117 template <
typename GUM_SCALAR >
121 if (this->
__bn ==
nullptr)
123 "No Bayes net has been assigned to the " 124 "inference algorithm");
126 const auto& dag = this->
__bn->dag();
127 for (
const auto node : joint_target) {
128 if (!dag.exists(node)) {
130 "at least one one in " << joint_target
131 <<
" does not belong to the bn");
140 if (target.isSupersetOf(joint_target))
return;
145 for (
auto iter = __joint_targets.beginSafe();
146 iter != __joint_targets.endSafe();
152 __joint_targets.insert(joint_target);
160 template <
typename GUM_SCALAR >
164 if (this->
__bn ==
nullptr)
166 "No Bayes net has been assigned to the " 167 "inference algorithm");
169 const auto& dag = this->
__bn->dag();
170 for (
const auto node : joint_target) {
171 if (!dag.exists(node)) {
173 "at least one one in " << joint_target
174 <<
" does not belong to the bn");
191 template <
typename GUM_SCALAR >
198 template <
typename GUM_SCALAR >
210 template <
typename GUM_SCALAR >
215 bool found_exact_target =
false;
219 found_exact_target =
true;
231 " no joint target containing " << nodes <<
" could be found among " 237 if (found_exact_target)
245 template <
typename GUM_SCALAR >
255 template <
typename GUM_SCALAR >
272 template <
typename GUM_SCALAR >
288 if (pXY !=
nullptr) {
delete pXY; }
293 auto res = (GUM_SCALAR)0;
296 GUM_SCALAR vXY = (*pXY)[i];
297 GUM_SCALAR vX = pX[i];
298 GUM_SCALAR vY = pY[i];
300 if (vXY > (GUM_SCALAR)0) {
301 if (vX == (GUM_SCALAR)0 || vY == (GUM_SCALAR)0) {
303 "Mutual Information (X,Y) with P(X)=0 or P(Y)=0 " 307 res += vXY * (log2(vXY) - log2(vX) - log2(vY));
323 template <
typename GUM_SCALAR >
325 return this->
H(X) + this->
H(Y) - 2 *
I(X, Y);
329 template <
typename GUM_SCALAR >
333 if (!(evs * targets).empty()) {
335 "Targets (" << targets <<
") can not intersect evs (" << evs
338 auto condset = this->
BN().minimalCondSet(targets, evs);
345 for (
const auto& target : targets) {
346 res.
add(this->
BN().variable(target));
347 iTarget.
add(this->
BN().variable(target));
351 for (
const auto& n : condset) {
352 res.
add(this->
BN().variable(n));
359 for (
const auto& n : condset)
372 template <
typename GUM_SCALAR >
375 const std::vector< std::string >&
targets,
376 const std::vector< std::string >& evs) {
377 const auto& bn = this->
BN();
380 for (
const auto& targetname : targets) {
381 targetsId.
insert(bn.idFromName(targetname));
385 for (
const auto& evname : evs) {
386 evsId.
insert(bn.idFromName(evname));
393 template <
typename GUM_SCALAR >
396 const auto& bn = this->
BN();
400 "jointMutualInformation needs at least 2 variables (targets=" 412 for (
const auto nod : targets) {
415 caracteristic.
add(*pv);
421 const GUM_SCALAR start = (siz % 2 == 0) ? GUM_SCALAR(-1.0) : GUM_SCALAR(1.0);
423 GUM_SCALAR res = GUM_SCALAR(0.0);
426 for (caracteristic.
inc(); !caracteristic.
end(); caracteristic.
inc()) {
429 for (
Idx i = 0; i < caracteristic.
nbrDim(); i++) {
430 if (caracteristic.
val(i) == 1) {
435 res += sign * po.margSumIn(sov).entropy();
438 for (
Idx i = 0; i < caracteristic.
nbrDim(); i++) {
445 template <
typename GUM_SCALAR >
447 const std::vector< std::string >&
targets) {
448 const auto& bn = this->
BN();
451 for (
const auto& targetname : targets) {
452 targetsId.
insert(bn.idFromName(targetname));
void __setBayesNetDuringConstruction(const IBayesNet< GUM_SCALAR > *bn)
assigns a BN during the inference engine construction
virtual void eraseAllMarginalTargets() final
Clear all the previously defined marginal targets.
virtual void eraseAllTargets()
Clear all previously defined targets (marginal and joint targets)
aGrUM's Potential is a multi-dimensional array with tensor operators.
virtual void addJointTarget(const NodeSet &joint_target) final
Add a set of nodes as a new joint target. As a collateral effect, every node is added as a marginal t...
virtual void __setState(const StateOfInference state) final
set the state of the inference engine and call the notification _onStateChanged when necessary (i...
virtual ~JointTargetedInference()
destructor
virtual void _onBayesNetChanged(const IBayesNet< GUM_SCALAR > *bn)
fired after a new Bayes net has been assigned to the engine
JointTargetedInference(const IBayesNet< GUM_SCALAR > *bn)
default constructor
GUM_SCALAR I(NodeId X, NodeId Y)
Mutual information between X and Y.
virtual GUM_SCALAR H(NodeId X) final
Entropy Compute Shanon's entropy of a node given the observation.
virtual void _onAllJointTargetsErased()=0
fired before a all the joint targets are removed
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual bool isJointTarget(const NodeSet &vars) const final
return true if target is a joint target.
const Potential< GUM_SCALAR > & normalize() const
normalisation of this do nothing if sum is 0
bool isSubsetOf(const Set< Key, OtherAlloc > &s) const
const IBayesNet< GUM_SCALAR > * __bn
the Bayes net on which we perform inferences
virtual bool isTarget(NodeId node) const final
return true if variable is a (marginal) target
<agrum/BN/inference/marginalTargetedInference.h>
virtual Potential< GUM_SCALAR > * _unnormalizedJointPosterior(const NodeSet &set)=0
returns a fresh unnormalized joint posterior of a given set of variables
Class representing the minimal interface for Bayesian Network.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual void _onJointTargetAdded(const NodeSet &set)=0
fired after a new joint target is inserted
virtual void eraseJointTarget(const NodeSet &joint_target) final
removes an existing joint target
Idx val(Idx i) const
Returns the current value of the variable at position i.
Representation of a setA Set is a structure that contains arbitrary elements.
virtual void makeInference() final
perform the heavy computations needed to compute the targets' posteriors
void incOut(const Instantiation &i)
Operator increment for the variables not in i.
<agrum/BN/inference/BayesNetInference.h>
void setFirstIn(const Instantiation &i)
Assign the first values in the Instantiation for the variables in i.
void inc()
Operator increment.
virtual void chgEvidence(NodeId id, const Idx val) final
change the value of an already existing hard evidence
virtual bool isDone() const noexcept final
returns whether the inference object is in a done state
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
virtual void eraseAllJointTargets() final
Clear all previously defined joint targets.
<agrum/BN/inference/jointTargetedInference.h>
virtual const Set< NodeSet > & jointTargets() const noexcept final
returns the list of joint targets
virtual void eraseAllEvidence() final
removes all the evidence entered into the network
virtual const Potential< GUM_SCALAR > & jointPosterior(const NodeSet &nodes) final
Compute the joint posterior of a set of nodes.
virtual const Potential< GUM_SCALAR > & posterior(NodeId node)
Computes and returns the posterior of a node.
Potential< GUM_SCALAR > evidenceJointImpact(const NodeSet &targets, const NodeSet &evs)
Create a gum::Potential for P(joint targets|evs) (for all instanciation of targets and evs) ...
virtual void _onBayesNetChanged(const IBayesNet< GUM_SCALAR > *bn)
fired after a new Bayes net has been assigned to the engine
Defines a discrete random variable over an integer interval.
void incIn(const Instantiation &i)
Operator increment for the variables in i.
Potential< GUM_SCALAR > margSumOut(const Set< const DiscreteVariable * > &del_vars) const
Projection using sum as operation (and implementation-optimized operations)
Class for assigning/browsing values to tuples of discrete variables.
virtual const Potential< GUM_SCALAR > & _jointPosterior(const NodeSet &set)=0
asks derived classes for the joint posterior of a declared target set
virtual void add(const DiscreteVariable &v) final
Adds a new var to the variables of the multidimensional matrix.
virtual const Potential< GUM_SCALAR > & posterior(NodeId node) final
Computes and returns the posterior of a node.
virtual void set(const Instantiation &i, const GUM_SCALAR &value) const final
Default implementation of MultiDimContainer::set().
void setFirst()
Assign the first values to the tuple of the Instantiation.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual Size nbrJointTargets() const noexcept final
returns the number of joint targets
Size Idx
Type for indexes.
virtual const NodeSet & targets() const noexcept final
returns the list of marginal targets
GUM_SCALAR jointMutualInformation(const NodeSet &targets)
Mutual information between targets.
virtual void eraseAllTargets()
Clear all previously defined targets.
void add(const DiscreteVariable &v) final
Adds a new variable in the Instantiation.
void clear()
Removes all the elements, if any, from the set.
GUM_SCALAR VI(NodeId X, NodeId Y)
Variation of information between X and Y.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size size() const noexcept
Returns the number of elements in the set.
virtual void _onJointTargetErased(const NodeSet &set)=0
fired before a joint target is removed
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
Set< NodeSet > __joint_targets
the set of joint targets
virtual const IBayesNet< GUM_SCALAR > & BN() const final
Returns a constant reference over the IBayesNet referenced by this class.
Size NodeId
Type for node ids.
void insert(const Key &k)
Inserts a new element into the set.
#define GUM_ERROR(type, msg)
bool end() const
Returns true if the Instantiation reached the end.
void setFirstOut(const Instantiation &i)
Assign the first values in the Instantiation for the variables not in i.