aGrUM  0.14.2
Miic.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}@lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it wil be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
37 #ifndef GUM_LEARNING_3_OFF_2_H
38 #define GUM_LEARNING_3_OFF_2_H
39 
40 #include <string>
41 #include <vector>
42 
43 #include <agrum/BN/BayesNet.h>
44 #include <agrum/config.h>
47 #include <agrum/core/heap.h>
48 #include <agrum/graphs/DAG.h>
51 
52 namespace gum {
53 
54  namespace learning {
55 
57  public:
58  bool operator()(
59  const std::pair<
60  std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > >*,
61  double >& e1,
62  const std::pair<
63  std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > >*,
64  double >& e2) const;
65  };
66 
68  public:
69  bool operator()(
70  const std::pair< std::tuple< NodeId, NodeId, NodeId >*, double >& e1,
71  const std::pair< std::tuple< NodeId, NodeId, NodeId >*, double >& e2)
72  const;
73  };
74 
76  public:
77  bool operator()(
78  const std::
79  tuple< std::tuple< NodeId, NodeId, NodeId >*, double, double, double >&
80  e1,
81  const std::
82  tuple< std::tuple< NodeId, NodeId, NodeId >*, double, double, double >&
83  e2) const;
84  };
103  class Miic : public ApproximationScheme {
104  public:
105  // ##########################################################################
107  // ##########################################################################
109 
111  Miic();
112 
114  Miic(int maxLog);
115 
117  Miic(const Miic& from);
118 
120  Miic(Miic&& from);
121 
123  ~Miic();
124 
126 
128  Miic& operator=(const Miic& from);
129 
131  Miic& operator=(Miic&& from);
132 
133  // ##########################################################################
135  // ##########################################################################
137 
138 
140 
144  MixedGraph learnMixedStructure(CorrectedMutualInformation<>& I,
145  MixedGraph graph);
146 
149 
153  DAG learnStructure(CorrectedMutualInformation<>& I, MixedGraph graph);
154 
156 
166  template < typename GUM_SCALAR = double,
167  typename GRAPH_CHANGES_SELECTOR,
168  typename PARAM_ESTIMATOR >
169  BayesNet< GUM_SCALAR > learnBN(GRAPH_CHANGES_SELECTOR& selector,
170  PARAM_ESTIMATOR& estimator,
171  DAG initial_dag = DAG());
172 
174  const std::vector< Arc > latentVariables() const;
175 
177  void setMiicBehaviour();
179  void set3off2Behaviour();
180 
182  void addConstraints(
183  HashTable< std::pair< NodeId, NodeId >, char > constraints);
185 
186  protected:
187  // ##########################################################################
189  // ##########################################################################
191 
193 
203  void _initiation(
205  MixedGraph& graph,
206  HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > >& sep_set,
207  Heap< std::pair<
208  std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > >*,
209  double >,
210  GreaterPairOn2nd >& _rank);
211 
213 
224  void _iteration(
226  MixedGraph& graph,
227  HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > >& sep_set,
228  Heap< std::pair<
229  std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > >*,
230  double >,
231  GreaterPairOn2nd >& _rank);
232 
234 
240  void _orientation_3off2(CorrectedMutualInformation<>& I,
241  MixedGraph& graph,
242  const HashTable< std::pair< NodeId, NodeId >,
243  std::vector< NodeId > >& sep_set);
244 
247 
253  void _orientation_latents(CorrectedMutualInformation<>& I,
254  MixedGraph& graph,
255  const HashTable< std::pair< NodeId, NodeId >,
256  std::vector< NodeId > >& sep_set);
257 
260 
266  void _orientation_miic(CorrectedMutualInformation<>& I,
267  MixedGraph& graph,
268  const HashTable< std::pair< NodeId, NodeId >,
269  std::vector< NodeId > >& sep_set);
271 
273 
281  void _findBestContributor(
282  NodeId x,
283  NodeId y,
284  const std::vector< NodeId >& ui,
285  const MixedGraph& graph,
287  Heap< std::pair<
288  std::tuple< NodeId, NodeId, NodeId, std::vector< NodeId > >*,
289  double >,
290  GreaterPairOn2nd >& _rank);
291 
294  /*@param graph graph in which to find the triples
295  *@param I mutual information object to compute the scores
296  *@param sep_set hashtable storing the separation sets for pairs of variables
297  */
298  std::vector< std::pair< std::tuple< NodeId, NodeId, NodeId >*, double > >
299  _getUnshieldedTriples(const MixedGraph& graph,
301  const HashTable< std::pair< NodeId, NodeId >,
302  std::vector< NodeId > >& sep_set);
303 
306  /*@param graph graph in which to find the triples
307  *@param I mutual information object to compute the scores
308  *@param sep_set hashtable storing the separation sets for pairs of variables
309  * @param marks hashtable containing the orientation marks for edges
310  */
311  std::vector< std::tuple< std::tuple< NodeId, NodeId, NodeId >*,
312  double,
313  double,
314  double > >
315  _getUnshieldedTriplesMIIC(
316  const MixedGraph& graph,
318  const HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > >&
319  sep_set,
320  HashTable< std::pair< NodeId, NodeId >, char >& marks);
321 
323  /*@param graph graph in which to find the triples
324  *@param proba_triples probabilities for the different triples to update
325  */
326  std::vector< std::tuple< std::tuple< NodeId, NodeId, NodeId >*,
327  double,
328  double,
329  double > >
330  _updateProbaTriples(
331  const MixedGraph& graph,
332  std::vector< std::tuple< std::tuple< NodeId, NodeId, NodeId >*,
333  double,
334  double,
335  double > > proba_triples);
336 
338  /*@param dag graph in which to which to propagate arcs
339  *@param node node on which neighbours to propagate th orientation
340  *@todo : avoid exception driven programmation in circle detection
341  */
342  void _propagatesHead(MixedGraph& graph, NodeId node);
343 
344 
345  private:
347  int __maxLog = 100;
349  const std::vector< NodeId > __empty_set;
351  std::vector< Arc > __latent_couples;
352 
356  bool __usemiic{false};
357 
360 
363 
365  /*@param graph MixedGraph in which to search the path
366  *@param n1 tail of the path
367  *@param n2 head of the path
368  */
369  const bool __existsDirectedPath(const MixedGraph& graph,
370  const NodeId n1,
371  const NodeId n2) const;
372  };
373 
374  } /* namespace learning */
375 
376 } /* namespace gum */
377 
379 //#include <agrum/learning/threeOffTwo_tpl.h>
380 
381 #endif /* GUM_LEARNING_3_OFF_2_H */
Class representing a Bayesian Network.
Definition: BayesNet.h:76
ArcProperty< double > __arc_probas
Storing the propabilities for each arc set in the graph.
Definition: Miic.h:359
This file contains general scheme for iteratively convergent algorithms.
The class computing n times the corrected mutual information, as used in the 3off2 algorithm...
The class computing n times the corrected mutual information, as used in the 3off2 algorithm...
Approximation Scheme.
STL namespace.
Class representing Bayesian networks.
This file contains getters and setters defintion for ApproximationSchem settings. ...
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
The class for generic Hash Tables.
Definition: hashTable.h:676
Heaps definition.
HashTable< std::pair< NodeId, NodeId >, char > __initial_marks
Initial marks for the orientation phase, used to convey constraints.
Definition: Miic.h:362
std::vector< Arc > __latent_couples
an empty vector of arcs
Definition: Miic.h:351
Base classes for mixed directed/undirected graphs.
The miic learning algorithm.
Definition: Miic.h:103
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:73
Heap data structureThis structure is a basic heap data structure, i.e., it is a container in which el...
Definition: heap.h:45
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
const std::vector< NodeId > __empty_set
an empty conditioning set
Definition: Miic.h:349
Size __N
size of the database
Definition: Miic.h:354
Base class for dag.
Definition: DAG.h:99
Size NodeId
Type for node ids.
Definition: graphElements.h:97
Base classes for directed acyclic graphs.
Base class for mixed graphs.
Definition: mixedGraph.h:124