aGrUM  0.16.0
Miic.h
Go to the documentation of this file.
1 
40 #ifndef GUM_LEARNING_3_OFF_2_H
41 #define GUM_LEARNING_3_OFF_2_H
42 
43 #include <string>
44 #include <vector>
45 
46 #include <agrum/BN/BayesNet.h>
47 #include <agrum/config.h>
50 #include <agrum/core/heap.h>
51 #include <agrum/graphs/DAG.h>
54 
55 namespace gum {
56 
57  namespace learning {
58 
60  public:
61  bool operator()(
62  const std::pair<
63  std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > >*,
64  double >& e1,
65  const std::pair<
66  std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > >*,
67  double >& e2) const;
68  };
69 
71  public:
72  bool operator()(
73  const std::pair< std::tuple< NodeId, NodeId, NodeId >*, double >& e1,
74  const std::pair< std::tuple< NodeId, NodeId, NodeId >*, double >& e2)
75  const;
76  };
77 
79  public:
80  bool operator()(
81  const std::
82  tuple< std::tuple< NodeId, NodeId, NodeId >*, double, double, double >&
83  e1,
84  const std::
85  tuple< std::tuple< NodeId, NodeId, NodeId >*, double, double, double >&
86  e2) const;
87  };
106  class Miic : public ApproximationScheme {
107  public:
108  // ##########################################################################
110  // ##########################################################################
112 
114  Miic();
115 
117  Miic(int maxLog);
118 
120  Miic(const Miic& from);
121 
123  Miic(Miic&& from);
124 
126  ~Miic();
127 
129 
131  Miic& operator=(const Miic& from);
132 
134  Miic& operator=(Miic&& from);
135 
136  // ##########################################################################
138  // ##########################################################################
140 
141 
143 
147  MixedGraph learnMixedStructure(CorrectedMutualInformation<>& I,
148  MixedGraph graph);
149 
152 
156  DAG learnStructure(CorrectedMutualInformation<>& I, MixedGraph graph);
157 
159 
169  template < typename GUM_SCALAR = double,
170  typename GRAPH_CHANGES_SELECTOR,
171  typename PARAM_ESTIMATOR >
172  BayesNet< GUM_SCALAR > learnBN(GRAPH_CHANGES_SELECTOR& selector,
173  PARAM_ESTIMATOR& estimator,
174  DAG initial_dag = DAG());
175 
177  const std::vector< Arc > latentVariables() const;
178 
180  void setMiicBehaviour();
182  void set3off2Behaviour();
183 
185  void addConstraints(
186  HashTable< std::pair< NodeId, NodeId >, char > constraints);
188 
189  protected:
190  // ##########################################################################
192  // ##########################################################################
194 
196 
206  void _initiation(
208  MixedGraph& graph,
209  HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > >& sep_set,
210  Heap< std::pair<
211  std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > >*,
212  double >,
213  GreaterPairOn2nd >& _rank);
214 
216 
227  void _iteration(
229  MixedGraph& graph,
230  HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > >& sep_set,
231  Heap< std::pair<
232  std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > >*,
233  double >,
234  GreaterPairOn2nd >& _rank);
235 
237 
243  void _orientation_3off2(CorrectedMutualInformation<>& I,
244  MixedGraph& graph,
245  const HashTable< std::pair< NodeId, NodeId >,
246  std::vector< NodeId > >& sep_set);
247 
250 
256  void _orientation_latents(CorrectedMutualInformation<>& I,
257  MixedGraph& graph,
258  const HashTable< std::pair< NodeId, NodeId >,
259  std::vector< NodeId > >& sep_set);
260 
263 
269  void _orientation_miic(CorrectedMutualInformation<>& I,
270  MixedGraph& graph,
271  const HashTable< std::pair< NodeId, NodeId >,
272  std::vector< NodeId > >& sep_set);
274 
276 
284  void _findBestContributor(
285  NodeId x,
286  NodeId y,
287  const std::vector< NodeId >& ui,
288  const MixedGraph& graph,
290  Heap< std::pair<
291  std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > >*,
292  double >,
293  GreaterPairOn2nd >& _rank);
294 
297  /*@param graph graph in which to find the triples
298  *@param I mutual information object to compute the scores
299  *@param sep_set hashtable storing the separation sets for pairs of variables
300  */
301  std::vector< std::pair< std::tuple< NodeId, NodeId, NodeId >*, double > >
302  _getUnshieldedTriples(const MixedGraph& graph,
304  const HashTable< std::pair< NodeId, NodeId >,
305  std::vector< NodeId > >& sep_set);
306 
309  /*@param graph graph in which to find the triples
310  *@param I mutual information object to compute the scores
311  *@param sep_set hashtable storing the separation sets for pairs of variables
312  * @param marks hashtable containing the orientation marks for edges
313  */
314  std::vector< std::tuple< std::tuple< NodeId, NodeId, NodeId >*,
315  double,
316  double,
317  double > >
318  _getUnshieldedTriplesMIIC(
319  const MixedGraph& graph,
321  const HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > >&
322  sep_set,
323  HashTable< std::pair< NodeId, NodeId >, char >& marks);
324 
326  /*@param graph graph in which to find the triples
327  *@param proba_triples probabilities for the different triples to update
328  */
329  std::vector< std::tuple< std::tuple< NodeId, NodeId, NodeId >*,
330  double,
331  double,
332  double > >
333  _updateProbaTriples(
334  const MixedGraph& graph,
335  std::vector< std::tuple< std::tuple< NodeId, NodeId, NodeId >*,
336  double,
337  double,
338  double > > proba_triples);
339 
341  /*@param dag graph in which to which to propagate arcs
342  *@param node node on which neighbours to propagate th orientation
343  *@todo : avoid exception driven programmation in circle detection
344  */
345  void _propagatesHead(MixedGraph& graph, NodeId node);
346 
347 
348  private:
350  int __maxLog = 100;
352  const std::vector< NodeId > __empty_set;
354  std::vector< Arc > __latent_couples;
355 
359  bool __usemiic{false};
360 
363 
366 
368  /*@param graph MixedGraph in which to search the path
369  *@param n1 tail of the path
370  *@param n2 head of the path
371  */
372  const bool __existsDirectedPath(const MixedGraph& graph,
373  const NodeId n1,
374  const NodeId n2) const;
375  };
376 
377  } /* namespace learning */
378 
379 } /* namespace gum */
380 
382 //#include <agrum/learning/threeOffTwo_tpl.h>
383 
384 #endif /* GUM_LEARNING_3_OFF_2_H */
Class representing a Bayesian Network.
Definition: BayesNet.h:78
ArcProperty< double > __arc_probas
Storing the propabilities for each arc set in the graph.
Definition: Miic.h:362
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
The class computing n times the corrected mutual information, as used in the 3off2 algorithm...
Approximation Scheme.
STL namespace.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
The class for generic Hash Tables.
Definition: hashTable.h:679
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
HashTable< std::pair< NodeId, NodeId >, char > __initial_marks
Initial marks for the orientation phase, used to convey constraints.
Definition: Miic.h:365
std::vector< Arc > __latent_couples
an empty vector of arcs
Definition: Miic.h:354
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
The miic learning algorithm.
Definition: Miic.h:106
bool operator()(const std::pair< std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > > *, double > &e1, const std::pair< std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > > *, double > &e2) const
Definition: Miic.cpp:76
Heap data structureThis structure is a basic heap data structure, i.e., it is a container in which el...
Definition: heap.h:48
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
const std::vector< NodeId > __empty_set
an empty conditioning set
Definition: Miic.h:352
Size __N
size of the database
Definition: Miic.h:357
Base class for dag.
Definition: DAG.h:102
Size NodeId
Type for node ids.
Definition: graphElements.h:98
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Base class for mixed graphs.
Definition: mixedGraph.h:127