aGrUM  0.16.0
DFSTree.h
Go to the documentation of this file.
1 
30 #ifndef GUM_DFS_TREE_H
31 #define GUM_DFS_TREE_H
32 
33 #include <list>
34 #include <ostream>
35 #include <utility>
36 #include <vector>
37 
38 #include <agrum/core/math/math.h>
39 #include <agrum/core/bijection.h>
40 #include <agrum/core/sequence.h>
41 #include <agrum/core/set.h>
42 
43 #include <agrum/graphs/diGraph.h>
44 
46 
50 
52 
53 namespace gum {
54  namespace prm {
55 
56  template < typename GUM_SCALAR >
57  class GSpan;
58 
59  namespace gspan {
60  template < typename GUM_SCALAR >
62 
70  template < typename GUM_SCALAR >
71  class DFSTree : private DiGraph {
72  public:
73  // =========================================================================
75  // ==========================================================================
77 
79  // DFSTree(InterfaceGraph<GUM_SCALAR>* graph);
82 
84  ~DFSTree();
85 
87  // =========================================================================
89  // ==========================================================================
91 
92  const InterfaceGraph< GUM_SCALAR >& graph() const;
93 
94  struct PatternData {
96  explicit PatternData(Pattern* p);
98  PatternData(const PatternData& from);
100  ~PatternData();
104  std::list< NodeId > children;
115  };
116 
118  std::list< NodeId >& roots();
119 
121  const std::list< NodeId >& roots() const;
122 
124  Pattern& parent(const Pattern& p);
125 
127  const Pattern& parent(const Pattern& p) const;
128 
130  std::list< NodeId >& children(const Pattern& p);
131 
133  const std::list< NodeId >& children(const Pattern& p) const;
134 
136  Pattern& pattern(NodeId id);
137 
139  const Pattern& pattern(NodeId id) const;
140 
147  void addRoot(LabelData& data);
148 
165  EdgeGrowth< GUM_SCALAR >& edge_growth,
166  Size min_freq);
167 
169  // =========================================================================
171  // ==========================================================================
173 
190  UndiGraph& iso_graph(const Pattern& p);
191 
217  NodeId node);
218 
227 
230  double frequency(const Pattern& p) const;
231 
233  PatternData& data(const Pattern& p);
235  const PatternData& data(const Pattern& p) const;
236 
239 
241  const SearchStrategy< GUM_SCALAR >& strategy() const;
242 
249  explicit NeighborDegreeSort(UndiGraph& graph);
251  NeighborDegreeSort(const NeighborDegreeSort& source);
255  bool operator()(NodeId i, NodeId j);
258  };
259 
261 
262  private:
265 
267  std::list< NodeId > __roots;
268 
272 
275 
278 
280  void __checkGrowth(Pattern& p,
281  Pattern* child,
282  EdgeGrowth< GUM_SCALAR >& edge_growth);
283 
285  void __addChild(Pattern& p,
286  Pattern* child,
287  EdgeGrowth< GUM_SCALAR >& edge_growth);
288 
290  bool __is_new_seq(
293 
297  void __initialiaze_root(Pattern* p,
299 
300  // Used by __find_sub_pattern.
303  };
304 
305 
306 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
307  extern template class DFSTree< double >;
308 #endif
309 
310 
311  } /* namespace gspan */
312  } /* namespace prm */
313 } /* namespace gum */
314 
316 
317 #endif /* GUM_DFS_TREE_H */
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
PatternData(Pattern *p)
Constructor.
Definition: DFSTree_tpl.h:570
const InterfaceGraph< GUM_SCALAR > * __graph
The interface graph on which this DFSTree applies.
Definition: DFSTree.h:264
~DFSTree()
Destructor.
Definition: DFSTree_tpl.h:37
This class is used to define an edge growth of a pattern in this DFSTree.
Definition: edgeGrowth.h:63
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
SearchStrategy< GUM_SCALAR > * __strategy
The strategy used to prune the search tree.
Definition: DFSTree.h:277
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void __addChild(Pattern &p, Pattern *child, EdgeGrowth< GUM_SCALAR > &edge_growth)
Add a child to this DFSTree.
Definition: DFSTree_tpl.h:161
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Inner class to handle data about labels in this interface graph.
Pattern * pattern
The pattern.
Definition: DFSTree.h:102
An PRMInstance is a Bayesian Network fragment defined by a Class and used in a PRMSystem.
Definition: PRMInstance.h:63
The generic class for storing (ordered) sequences of objects.
Definition: sequence.h:1022
Pattern & growPattern(Pattern &p, EdgeGrowth< GUM_SCALAR > &edge_growth, Size min_freq)
Add a one edge growth of p as one of its child.
Definition: DFSTree_tpl.h:228
Abstract class representing an element of PRM class.
std::list< NodeId > __roots
The list of root patterns in this DFSTree.
Definition: DFSTree.h:267
UndiGraph & g
The isomorphism graph.
Definition: DFSTree.h:257
Inner class to handle data about edges in __graph.
This is used to generate the max_indep_set of a Pattern.
Definition: DFSTree.h:247
This class represent the interface graph of a given gum::prm::PRMSystem<GUM_SCALAR>.
void addRoot(LabelData &data)
Add a one edge Pattern in this DFSTree.
Definition: DFSTree_tpl.h:49
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
bool __is_new_seq(Sequence< PRMInstance< GUM_SCALAR > * > &seq, NodeProperty< Sequence< PRMInstance< GUM_SCALAR > * > * > &iso_map)
Check if an instance match is redundant.
Definition: DFSTree_tpl.h:142
The class for generic Hash Tables.
Definition: hashTable.h:679
std::list< NodeId > & roots()
Returns the list of root patterns in this DFSTree.
Definition: DFSTree_tpl.h:388
const InterfaceGraph< GUM_SCALAR > & graph() const
Returns the list of root patterns in this DFSTree.
Definition: DFSTree_tpl.h:500
A DFSTree is used by gspan to sort lexicographically patterns discovered in an interface graph...
Definition: DFSTree.h:71
Size cost
The cost of this Pattern.
Definition: DFSTree.h:112
Base class for all oriented graphs.
Definition: diGraph.h:111
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.
Set< NodeId > max_indep_set
The maximal independent set of p.
Definition: DFSTree.h:110
Set of pairs of elements with fast search for both elements.
Definition: bijection.h:1805
NodeProperty< Sequence< PRMInstance< GUM_SCALAR > *> *> iso_map
The instances matching p in the interface graph.
Definition: DFSTree.h:108
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
SearchStrategy< GUM_SCALAR > & strategy()
strategy getter
Definition: DFSTree_tpl.h:530
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
This class discovers pattern in a PRM<GUM_SCALAR>&#39;s PRMSystem<GUM_SCALAR> to speed up structured infe...
Definition: DFSTree.h:57
void __initialiaze_root(Pattern *p, Sequence< EdgeData< GUM_SCALAR > * > &seq)
This initialize the DSFTree with a new root.
Definition: DFSTree_tpl.h:93
Base class for undirected graphs.
Definition: undiGraph.h:109
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Size gain
The gain of this Pattern.
Definition: DFSTree.h:114
PatternData & data(const Pattern &p)
Definition: DFSTree_tpl.h:519
HashTable< Pattern *, PatternData *> __data
Data about patterns in this DFSTree.
Definition: DFSTree.h:274
double frequency(const Pattern &p) const
Returns the frequency of p respecting it&#39;s maximal independent set.
Definition: DFSTree_tpl.h:513
bool __test_equality(HashTable< PRMClassElement< GUM_SCALAR > *, Size > &x, HashTable< PRMClassElement< GUM_SCALAR > *, Size > &y)
Definition: DFSTree_tpl.h:342
void __checkGrowth(Pattern &p, Pattern *child, EdgeGrowth< GUM_SCALAR > &edge_growth)
Raise different exceptions if child is invalid or illegal.
Definition: DFSTree_tpl.h:188
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
Pattern & parent(const Pattern &p)
Returns the parent of p in this DFSTree.
Definition: DFSTree_tpl.h:398
UndiGraph iso_graph
The isomorphism graph of the pattern.
Definition: DFSTree.h:106
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Bijection< NodeId, Pattern *> __node_map
The mapping between nodes in this DFSTree and the patterns they represents.
Definition: DFSTree.h:271
std::list< NodeId > children
The list of the pattern&#39;s children, sorted lexicographically.
Definition: DFSTree.h:104
This contains all the information we want for a node in a DFSTree.
Definition: pattern.h:73
DFSTree(const InterfaceGraph< GUM_SCALAR > &graph, SearchStrategy< GUM_SCALAR > *strategy=0)
Default constructor.
Definition: DFSTree_tpl.h:375
This is an abstract class used to tune search strategies in the gspan algorithm.
Definition: DFSTree.h:61
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.