aGrUM  0.16.0
CNLoopyPropagation.h
Go to the documentation of this file.
1 
30 #ifndef __CN_LOOPY_PROPAGATION__H__
31 #define __CN_LOOPY_PROPAGATION__H__
32 
33 #include <cstdlib>
34 #include <ctime>
35 #include <limits>
36 
37 #include <agrum/CN/credalNet.h>
40 #include <agrum/core/math/pow.h>
41 #include <agrum/core/sequence.h>
42 
43 #define _INF std::numeric_limits< GUM_SCALAR >::infinity()
44 
45 namespace gum {
46  namespace credal {
47 
57  template < typename GUM_SCALAR >
58  class CNLoopyPropagation : public InferenceEngine< GUM_SCALAR > {
59  public:
60  using msg = std::vector< Potential< GUM_SCALAR >* >;
61  using cArcP = const Arc*;
62 
66  enum class InferenceType : char {
72  ordered,
82  };
83 
86 
88  void makeInference();
89 
91 
94 
99  void inferenceType(InferenceType inft);
100 
106 
108 
111 
119  void eraseAllEvidence();
120 
127  void saveInference(const std::string& path);
128 
130 
133 
137  explicit CNLoopyPropagation(const CredalNet< GUM_SCALAR >& cnet);
139  virtual ~CNLoopyPropagation();
141 
142  protected:
145 
148  void _initialize();
149 
151 
154 
160 
162  void _updateMarginals();
163 
171  void _msgL(
172  const NodeId X,
173  const NodeId demanding_parent); // allways sent from X to demanding_X
174 
195  void _compute_ext(GUM_SCALAR& msg_l_min,
196  GUM_SCALAR& msg_l_max,
197  std::vector< GUM_SCALAR >& lx,
198  GUM_SCALAR& num_min,
199  GUM_SCALAR& num_max,
200  GUM_SCALAR& den_min,
201  GUM_SCALAR& den_max);
202 
220  void _compute_ext(std::vector< std::vector< GUM_SCALAR > >& combi_msg_p,
221  const NodeId& id,
222  GUM_SCALAR& msg_l_min,
223  GUM_SCALAR& msg_l_max,
224  std::vector< GUM_SCALAR >& lx,
225  const Idx& pos);
226 
243  void _enum_combi(
244  std::vector< std::vector< std::vector< GUM_SCALAR > > >& msgs_p,
245  const NodeId& id,
246  GUM_SCALAR& msg_l_min,
247  GUM_SCALAR& msg_l_max,
248  std::vector< GUM_SCALAR >& lx,
249  const Idx& pos);
250 
258  void _msgP(const NodeId X, const NodeId demanding_child);
259 
272  void _enum_combi(
273  std::vector< std::vector< std::vector< GUM_SCALAR > > >& msgs_p,
274  const NodeId& id,
275  GUM_SCALAR& msg_p_min,
276  GUM_SCALAR& msg_p_max);
277 
289  void _compute_ext(std::vector< std::vector< GUM_SCALAR > >& combi_msg_p,
290  const NodeId& id,
291  GUM_SCALAR& msg_p_min,
292  GUM_SCALAR& msg_p_max);
293 
295  void _refreshLMsPIs(bool refreshIndic = false);
296 
301  GUM_SCALAR _calculateEpsilon();
302 
304 
307 
311  void _computeExpectations();
312 
315  void _updateIndicatrices();
316 
318 
327 
334 
337 
349 
361 
365 
366  private:
369 
372 
375 
378 
379  // typedef const CredalNet< GUM_SCALAR > * (infE::*cnfunc) ();
380  // cnfunc getCN = &infE::getCN;
381  public:
382  virtual void insertEvidenceFile(const std::string& path) {
384  };
385  };
386 
387 
388 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
389  extern template class CNLoopyPropagation< double >;
390 #endif
391  } // namespace credal
392 } // namespace gum
393 
395 
396 #endif
NodeProperty< bool > _update_p
Used to keep track of which node needs to update it&#39;s information coming from it&#39;s parents...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
NodeProperty< GUM_SCALAR > _NodesP_min
"Lower" node information obtained by combinaison of parent&#39;s messages.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void _makeInferenceByOrderedArcs()
Starts the inference with this inference type.
virtual void insertEvidenceFile(const std::string &path)
Insert evidence from file.
void eraseAllEvidence()
Erase all inference related data to perform another one.
virtual void insertEvidenceFile(const std::string &path)
Insert evidence from file.
InferenceType __inferenceType
The choosen inference type.
ArcProperty< GUM_SCALAR > _ArcsP_min
"Lower" information coming from one&#39;s parent.
NodeSet active_nodes_set
The current node-set to iterate through at this current step.
void _initialize()
Topological forward propagation to initialize old marginals & messages.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
const CredalNet< GUM_SCALAR > * __cn
A pointer to the CredalNet to be used.
<agrum/CN/CNLoopyPropagation.h>
ArcProperty< GUM_SCALAR > _ArcsP_max
"Upper" information coming from one&#39;s parent.
ArcProperty< GUM_SCALAR > _ArcsL_max
"Upper" information coming from one&#39;s children.
Chooses an arc ordering and sends messages accordingly at all steps.
Class representing the minimal interface for Bayesian Network.
Definition: IBayesNet.h:62
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
void _computeExpectations()
Since the network is binary, expectations can be computed from the final marginals which give us the ...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
The class for generic Hash Tables.
Definition: hashTable.h:679
void _makeInferenceByRandomOrder()
Starts the inference with this inference type.
const IBayesNet< GUM_SCALAR > * __bnet
A pointer to it&#39;s IBayesNet used as a DAG.
void _updateMarginals()
Compute marginals from up-to-date messages.
Class template representing a Credal Network.
Definition: credalNet.h:89
InferenceType inferenceType()
Get the inference type.
bool _InferenceUpToDate
TRUE if inference has already been performed, FALSE otherwise.
The base class for all directed edgesThis class is used as a basis for manipulating all directed edge...
CNLoopyPropagation(const CredalNet< GUM_SCALAR > &cnet)
Constructor.
Uses a node-set so we don&#39;t iterate on nodes that can&#39;t send a new message.
ArcProperty< GUM_SCALAR > _ArcsL_min
"Lower" information coming from one&#39;s children.
GUM_SCALAR _calculateEpsilon()
Compute epsilon.
void saveInference(const std::string &path)
void _msgL(const NodeId X, const NodeId demanding_parent)
Sends a message to one&#39;s parent, i.e.
void _enum_combi(std::vector< std::vector< std::vector< GUM_SCALAR > > > &msgs_p, const NodeId &id, GUM_SCALAR &msg_l_min, GUM_SCALAR &msg_l_max, std::vector< GUM_SCALAR > &lx, const Idx &pos)
Used by _msgL.
void makeInference()
Starts the inference.
NodeProperty< NodeSet *> _msg_l_sent
Used to keep track of one&#39;s messages sent to it&#39;s parents.
Abstract class template representing a CredalNet inference engine.
void _refreshLMsPIs(bool refreshIndic=false)
Get the last messages from one&#39;s parents and children.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
NodeProperty< GUM_SCALAR > _NodesL_min
"Lower" node information obtained by combinaison of children messages.
InferenceType
Inference type to be used by the algorithm.
Size Idx
Type for indexes.
Definition: types.h:53
void _compute_ext(GUM_SCALAR &msg_l_min, GUM_SCALAR &msg_l_max, std::vector< GUM_SCALAR > &lx, GUM_SCALAR &num_min, GUM_SCALAR &num_max, GUM_SCALAR &den_min, GUM_SCALAR &den_max)
Used by _msgL.
void _updateIndicatrices()
Only update indicatrices variables at the end of computations ( calls _msgP ).
void _msgP(const NodeId X, const NodeId demanding_child)
Sends a message to one&#39;s child, i.e.
Chooses a random arc ordering and sends messages accordingly.
NodeSet next_active_nodes_set
The next node-set, i.e.
NodeProperty< GUM_SCALAR > _NodesP_max
"Upper" node information obtained by combinaison of parent&#39;s messages.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
NodeProperty< bool > _update_l
Used to keep track of which node needs to update it&#39;s information coming from it&#39;s children...
NodeProperty< GUM_SCALAR > _NodesL_max
"Upper" node information obtained by combinaison of children messages.
void _makeInferenceNodeToNeighbours()
Starts the inference with this inference type.
std::vector< Potential< GUM_SCALAR > *> msg