aGrUM  0.14.2
gspan.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_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 will 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  ***************************************************************************/
27 #ifndef GUM_GSPAN_H
28 #define GUM_GSPAN_H
29 
30 #include <algorithm>
31 #include <list>
32 #include <ostream>
33 #include <string>
34 #include <vector>
35 
36 #include <agrum/core/timer.h>
37 
39 
40 #include <agrum/PRM/PRM.h>
43 
44 namespace gum {
45  namespace prm {
46 
67  template < typename GUM_SCALAR >
68  class GSpan {
69  public:
70  // ========================================================================
72  // ========================================================================
74 
83  GSpan(const PRM< GUM_SCALAR >& prm,
84  const PRMSystem< GUM_SCALAR >& sys,
85  gspan::SearchStrategy< GUM_SCALAR >* strategy = 0);
86 
88  ~GSpan();
89 
91  // ========================================================================
93  // ========================================================================
95 
101  Size getMaxDFSDepth() const;
102 
109  void setMaxDFSDepth(Size depth);
110 
115  gspan::DFSTree< GUM_SCALAR >& tree();
116 
121  const gspan::DFSTree< GUM_SCALAR >& tree() const;
122 
127  gspan::InterfaceGraph< GUM_SCALAR >& interfaceGraph();
128 
133  const gspan::InterfaceGraph< GUM_SCALAR >& interfaceGraph() const;
134 
136  // ========================================================================
138  // ========================================================================
140 
148  void discoverPatterns();
149 
156  std::vector< gspan::Pattern* >& patterns();
157 
164  const std::vector< gspan::Pattern* >& patterns() const;
165 
168 
175  MatchedInstances& matches(const gspan::Pattern& p);
176 
183  const MatchedInstances& matches(const gspan::Pattern& p) const;
184 
185  // /**
186  // * Returns the cumulative sum of all the cliques size created after
187  // lifting
188  // * the patterns.
189  // * @returns the cumulative sum of all the cliques size created after
190  // lifting
191  // * the patterns.
192  // */
193  // double patterns_cost() const;
194 
195  // /**
196  // * Returns the cumulative sum of all the cliques size created after
197  // lifting
198  // * the inner attributes.
199  // * @returns the cumulative sum of all the cliques size created after
200  // lifting
201  // * the inner attributes.
202  // */
203  // double sve_cost() const;
204 
206  private:
207  // ========================================================================
209  // ========================================================================
211 
214 
217 
220 
222  std::vector< gspan::Pattern* > __patterns;
223 
225  std::vector< gspan::LabelData* > __nodes;
226 
228  std::vector< gspan::LabelData* > __edges;
229 
232 
236 
239 
241  // ========================================================================
243  // ========================================================================
245 
247  void __sortNodesAndEdges();
248 
253  gspan::Pattern& p);
254 
261  Size __cost_func(Size interface_size, Size frequency);
262 
264  void __sortPatterns();
265 
270 
272 
273  // ========================================================================
275  // ========================================================================
277 
283  struct LabelSort {
288  LabelSort(GSpan* my_gspan);
289 
294  LabelSort(const LabelSort& source);
295 
299  ~LabelSort();
300 
308 
311  };
312 
318  struct PatternSort {
323  PatternSort(GSpan* my_gspan);
324 
329  PatternSort(const PatternSort& source);
330 
334  ~PatternSort();
335 
343 
346  };
347 
349  };
350 
351 
352 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
353  extern template class GSpan< double >;
354 #endif
355 
356 
357  } /* namespace prm */
358 } /* namespace gum */
359 
361 
362 #endif /* GUM_GSPAN_H */
GSpan * gspan
A pointer over an instance of the GSpan class using this class.
Definition: gspan.h:310
bool __isEdgeEligible(typename gspan::EdgeData< GUM_SCALAR > *e)
Returns true if e is an eligible root edge.
Definition: gspan_tpl.h:433
std::vector< gspan::LabelData *> __nodes
The vector of nodes in __graph, in decreasing order of interest.
Definition: gspan.h:225
Set< Sequence< PRMInstance< GUM_SCALAR > *> *> MatchedInstances
Code alias.
Definition: gspan.h:167
Inner class to handle data about labels in this interface graph.
HashTable< gspan::LabelData *, Idx > __cost
Mapping between labels and their cost.
Definition: gspan.h:231
Headers of the DFSTree class.
LabelSort(GSpan *my_gspan)
Default constructor.
Definition: gspan_tpl.h:442
Size __depth_stop
The max depth allowed for the DSF tree.
Definition: gspan.h:219
Headers of PRM.
Inner class to handle data about edges in __graph.
void __subgraph_mining(gspan::InterfaceGraph< GUM_SCALAR > &graph, gspan::Pattern &p)
Discovers new patterns by developing p.
Definition: gspan_tpl.h:100
This class represent the interface graph of a given gum::prm::PRMSystem<GUM_SCALAR>.
Class used to compute response times for benchmark purposes.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
void __sortPatterns()
Sort the patterns and compute their respective costs.
Definition: gspan_tpl.h:222
Implementation of a variable elimination algorithm for inference in Bayesian Networks.
The class for generic Hash Tables.
Definition: hashTable.h:676
Set< PRMInstance< GUM_SCALAR > *> __chosen
Contains all instance which belongs to a discovered and used pattern.
Definition: gspan.h:238
Representation of a setA Set is a structure that contains arbitrary elements.
Definition: set.h:162
gspan::DFSTree< GUM_SCALAR > __tree
The DFSTree used to discover new patters.
Definition: gspan.h:216
A DFSTree is used by gspan to sort lexicographically patterns discovered in an interface graph...
Definition: DFSTree.h:68
~GSpan()
Destructor.
Definition: gspan_tpl.h:361
~LabelSort()
Destructor.
Definition: gspan_tpl.h:454
std::vector< gspan::Pattern *> __patterns
The vector of discovered patters, in decreasing order of interest.
Definition: gspan.h:222
gspan::InterfaceGraph< GUM_SCALAR > * __graph
The interface graph used by this class.
Definition: gspan.h:213
Private class used to sort LabelData using STL sort algorithms.
Definition: gspan.h:283
GSpan * gspan
A pointer over an instance of the GSpan class using this class.
Definition: gspan.h:345
gspan::DFSTree< GUM_SCALAR > & tree()
Returns the DFSTree used to discover new patters.
Definition: gspan_tpl.h:381
gspan::InterfaceGraph< GUM_SCALAR > & interfaceGraph()
Returns the InterfaceGraph used by this.
Definition: gspan_tpl.h:421
void discoverPatterns()
This will methods will discover repeated patterns in the PRMSystem<GUM_SCALAR> assigned to this class...
Definition: gspan_tpl.h:33
This class discovers pattern in a PRM<GUM_SCALAR>&#39;s PRMSystem<GUM_SCALAR> to speed up structured infe...
Definition: DFSTree.h:54
std::vector< gspan::Pattern *> & patterns()
Returns the Pattern mined by this class in a decreasing order of interest.
Definition: gspan_tpl.h:397
Inline implementation of gspan.
void setMaxDFSDepth(Size depth)
Defines the maximal depth of the DFSTree used by this class to discover new patterns.
Definition: gspan_tpl.h:376
Headers of InterfaceGraph.
void __sortNodesAndEdges()
Sort the nodes and edges of __graph.
Definition: gspan_tpl.h:56
GSpan(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &sys, gspan::SearchStrategy< GUM_SCALAR > *strategy=0)
Default constructor.
Definition: gspan_tpl.h:352
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
std::vector< gspan::LabelData *> __edges
The vector of edges in __graph, in decreasing order of interest.
Definition: gspan.h:228
Private class used to sort Pattern using STL sort algorithms.
Definition: gspan.h:318
Size getMaxDFSDepth() const
Returns the maximal depth of the DFSTree used to discover new patterns.
Definition: gspan_tpl.h:371
MatchedInstances & matches(const gspan::Pattern &p)
Returns a mapping between patterns and the sequence of instance in the interface graph matching them...
Definition: gspan_tpl.h:409
This contains all the information we want for a node in a DFSTree.
Definition: pattern.h:70
Size __cost_func(Size interface_size, Size frequency)
Returns the cost with respect to an interface size and its frequency. TODO replace this by a class to...
Definition: gspan_tpl.h:391
bool operator()(gspan::LabelData *i, gspan::LabelData *j)
Returns true if i&#39;s cost is lesser than j&#39;s.
Definition: gspan_tpl.h:459
HashTable< gspan::Pattern *, MatchedInstances *> __matched_instances
Mapping between a pattern and the multiset of instances matched to it.
Definition: gspan.h:235