57 template < GUM_Numeric GUM_SCALAR >
66 template < GUM_Numeric GUM_SCALAR >
72 template < GUM_Numeric GUM_SCALAR >
84 template < GUM_Numeric GUM_SCALAR >
88 "No Markov net has been assigned to the "
89 "inference algorithm");
91 const auto& gra = this->
MRF().internalGraph();
92 for (
const auto var: vars) {
93 if (!gra.exists(var)) {
102 template < GUM_Numeric GUM_SCALAR >
108 template < GUM_Numeric GUM_SCALAR >
119 template < GUM_Numeric GUM_SCALAR >
126 template < GUM_Numeric GUM_SCALAR >
131 "No Markov net has been assigned to the "
132 "inference algorithm");
134 const auto& dag = this->
MRF().internalGraph();
135 for (
const auto node: joint_target) {
136 if (!dag.exists(node)) {
138 "at least one one in " << joint_target <<
" does not belong to the mn");
147 if (target.isStrictSupersetOf(joint_target))
return;
163 template < GUM_Numeric GUM_SCALAR >
168 "No Markov net has been assigned to the "
169 "inference algorithm");
171 const auto& dag = this->
MRF().internalGraph();
172 for (
const auto node: joint_target) {
173 if (!dag.exists(node)) {
175 "at least one one in " << joint_target <<
" does not belong to the mn");
190 template < GUM_Numeric GUM_SCALAR >
196 template < GUM_Numeric GUM_SCALAR >
206 template < GUM_Numeric GUM_SCALAR >
207 const Tensor< GUM_SCALAR >&
210 for (
const auto& node: nodes) {
214 bool found_exact_target =
false;
218 found_exact_target =
true;
221 if (super_target.
empty()) {
223 "No joint target containing " << real_nodes <<
" could be found among "
235 template < GUM_Numeric GUM_SCALAR >
242 template < GUM_Numeric GUM_SCALAR >
243 const Tensor< GUM_SCALAR >&
252 template < GUM_Numeric GUM_SCALAR >
256 if (!(evs *
targets).empty()) {
258 "Targets (" <<
targets <<
") can not intersect evs (" << evs <<
").");
260 auto condset = this->
MRF().minimalCondSet(
targets, evs);
266 Tensor< GUM_SCALAR > res;
267 for (
const auto& target:
targets) {
268 res.add(this->
MRF().variable(target));
269 iTarget.
add(this->
MRF().variable(target));
273 for (
const auto& n: condset) {
274 res.add(this->
MRF().variable(n));
281 for (
const auto& n: condset)
294 template < GUM_Numeric GUM_SCALAR >
296 const std::vector< std::string >&
targets,
297 const std::vector< std::string >& evs) {
298 const auto& mn = this->
MRF();
302 template < GUM_Numeric GUM_SCALAR >
305 const auto& mn = this->
MRF();
309 "jointMutualInformation needs at least 2 variables (targets=" <<
targets <<
")");
320 for (
const auto nod:
targets) {
321 const auto& var = mn.variable(nod);
323 caracteristic.
add(*pv);
329 const GUM_SCALAR start = (siz % 2 == 0) ? GUM_SCALAR(-1.0) : GUM_SCALAR(1.0);
331 GUM_SCALAR res = GUM_SCALAR(0.0);
334 for (caracteristic.
inc(); !caracteristic.
end(); caracteristic.
inc()) {
337 for (
Idx i = 0; i < caracteristic.
nbrDim(); i++) {
338 if (caracteristic.
val(i) == 1) {
343 res += sign * po.sumIn(sov).entropy();
346 for (
Idx i = 0; i < caracteristic.
nbrDim(); i++) {
353 template < GUM_Numeric GUM_SCALAR >
355 const std::vector< std::string >&
targets) {
359 template < GUM_Numeric GUM_SCALAR >
366 template < GUM_Numeric GUM_SCALAR >
371 for (
const auto& factor: this->
MRF().factors()) {
virtual void chgEvidence(NodeId id, const Idx val) final
change the value of an already existing hard evidence
virtual bool isInferenceDone() const noexcept final
returns whether the inference object is in a InferenceDone state
virtual void setState_(const StateOfInference state) final
set the state of the inference engine and call the notification onStateChanged_ when necessary (i....
virtual bool hasHardEvidence(NodeId id) const final
indicates whether node id has received a hard evidence
virtual void eraseAllEvidence() final
removes all the evidence entered into the network
virtual void makeInference() final
perform the heavy computations needed to compute the targets' posteriors
virtual void addEvidence(NodeId id, const Idx val) final
adds a new hard evidence on node id
Virtual base class for probabilistic graphical models.
Class representing the minimal interface for Markov random field.
Class for assigning/browsing values to tuples of discrete variables.
bool end() const
Returns true if the Instantiation reached the end.
void inc()
Operator increment.
void incOut(const Instantiation &i)
Operator increment for the variables not in i.
void setFirstIn(const Instantiation &i)
Assign the first values in the Instantiation for the variables in i.
void add(const DiscreteVariable &v) final
Adds a new variable in the Instantiation.
void incIn(const Instantiation &i)
Operator increment for the variables in i.
Idx val(Idx i) const
Returns the current value of the variable at position i.
void setFirst()
Assign the first values to the tuple of the Instantiation.
void setFirstOut(const Instantiation &i)
Assign the first values in the Instantiation for the variables not in i.
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Exception: at least one argument passed to a function is not what was expected.
virtual void eraseJointTarget(const NodeSet &joint_target) final
removes an existing joint target
~JointTargetedMRFInference() override
destructor
GUM_SCALAR jointMutualInformation(const NodeSet &targets)
Mutual information between targets.
virtual const Set< NodeSet > & jointTargets() const noexcept final
returns the list of joint targets
virtual Size nbrJointTargets() const noexcept final
returns the number of joint targets
Set< NodeSet > _joint_targets_
the set of joint targets
void eraseAllTargets() final
Clear all previously defined targets (marginal and joint targets).
virtual const Tensor< GUM_SCALAR > & jointPosterior(const NodeSet &nodes) final
Compute the joint posterior of a set of nodes.
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 onJointTargetErased_(const NodeSet &set)=0
fired before a joint target is removed
virtual void eraseAllJointTargets() final
Clear all previously defined joint targets.
const Tensor< GUM_SCALAR > & posterior(NodeId node) final
Computes and returns the posterior of a node.
virtual const Tensor< GUM_SCALAR > & jointPosterior_(const NodeSet &set)=0
asks derived classes for the joint posterior of a declared target set
virtual void onAllJointTargetsErased_()=0
fired before a all the joint targets are removed
virtual void onJointTargetAdded_(const NodeSet &set)=0
fired after a new joint target is inserted
virtual bool isExactJointComputable_(const NodeSet &vars)
check if the vars form a possible computable joint (can be redefined by subclass)
Tensor< GUM_SCALAR > evidenceJointImpact(const NodeSet &targets, const NodeSet &evs)
Create a gum::Tensor for P(joint targets|evs) (for all instantiation of targets and evs).
JointTargetedMRFInference(const IMarkovRandomField< GUM_SCALAR > *mn)
default constructor
virtual NodeSet superForJointComputable_(const NodeSet &vars)
virtual void eraseAllMarginalTargets() final
Clear all the previously defined marginal targets.
virtual bool isJointTarget(const NodeSet &vars) const final
return true if target is a joint target.
void onModelChanged_(const GraphicalModel *mn) override
fired after a new Markov net has been assigned to the engine
void _setMRFDuringConstruction_(const IMarkovRandomField< GUM_SCALAR > *mn)
assigns a MRF during the inference engine construction
virtual const IMarkovRandomField< GUM_SCALAR > & MRF() const final
Returns a constant reference over the IMarkovRandomField referenced by this class.
virtual const NodeSet & targets() const noexcept final
returns the list of marginal targets
void onModelChanged_(const GraphicalModel *mn) override
fired after a new Markov net has been assigned to the engine
virtual void eraseAllTargets()
Clear all previously defined targets.
MarginalTargetedMRFInference(const IMarkovRandomField< GUM_SCALAR > *mn)
default constructor
virtual bool isTarget(NodeId node) const final
return true if variable is a (marginal) target
virtual const Tensor< GUM_SCALAR > & posterior(NodeId node)
Computes and returns the posterior of a node.
Exception : a pointer or a reference on a nullptr (0) object.
Defines a discrete random variable over an integer interval.
bool isSubsetOrEqual(const Set< Key > &s) const
void clear()
Removes all the elements, if any, from the set.
bool empty() const noexcept
Indicates whether the set is the empty set.
void insert(const Key &k)
Inserts a new element into the set.
Exception : a looked-for element could not be found.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
Size NodeId
Type for node ids.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
This file contains the abstract inference class definition for computing (incrementally) joint poster...
gum is the global namespace for all aGrUM entities
Set< const DiscreteVariable * > VariableSet
Header of gumRangeVariable.