aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
gum::prm::GSpan< GUM_SCALAR > Class Template Reference

This class discovers pattern in a PRM<GUM_SCALAR>'s PRMSystem<GUM_SCALAR> to speed up structured inference. More...

#include <agrum/PRM/gspan.h>

+ Collaboration diagram for gum::prm::GSpan< GUM_SCALAR >:

Public Member Functions

Constructors & destructor.
 GSpan (const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &sys, gspan::SearchStrategy< GUM_SCALAR > *strategy=0)
 Default constructor. More...
 
 ~GSpan ()
 Destructor. More...
 
Getters and setters.
Size getMaxDFSDepth () const
 Returns the maximal depth of the DFSTree used to discover new patterns. More...
 
void setMaxDFSDepth (Size depth)
 Defines the maximal depth of the DFSTree used by this class to discover new patterns. More...
 
gspan::DFSTree< GUM_SCALAR > & tree ()
 Returns the DFSTree used to discover new patters. More...
 
const gspan::DFSTree< GUM_SCALAR > & tree () const
 Returns the DFSTree used to discover new patters. More...
 
gspan::InterfaceGraph< GUM_SCALAR > & interfaceGraph ()
 Returns the InterfaceGraph used by this. More...
 
const gspan::InterfaceGraph< GUM_SCALAR > & interfaceGraph () const
 Returns the InterfaceGraph used by this. More...
 

Classes

class  LabelSort
 Private class used to sort LabelData using STL sort algorithms. More...
 
class  PatternSort
 Private class used to sort Pattern using STL sort algorithms. More...
 

Pattern discovery methods.

typedef Set< Sequence< PRMInstance< GUM_SCALAR > *> *> MatchedInstances
 Code alias. More...
 
void discoverPatterns ()
 This will methods will discover repeated patterns in the PRMSystem<GUM_SCALAR> assigned to this class. More...
 
std::vector< gspan::Pattern *> & patterns ()
 Returns the Pattern mined by this class in a decreasing order of interest. More...
 
const std::vector< gspan::Pattern *> & patterns () const
 Returns the Pattern mined by this class in a decreasing order of interest. More...
 
MatchedInstancesmatches (const gspan::Pattern &p)
 Returns a mapping between patterns and the sequence of instance in the interface graph matching them. More...
 
const MatchedInstancesmatches (const gspan::Pattern &p) const
 Returns a mapping between patterns and the sequence of instance in the interface graph matching them. More...
 

Detailed Description

template<typename GUM_SCALAR>
class gum::prm::GSpan< GUM_SCALAR >

This class discovers pattern in a PRM<GUM_SCALAR>'s PRMSystem<GUM_SCALAR> to speed up structured inference.

This class is not an inference algorithm for PRM<GUM_SCALAR>, however it can be used to speed up structured inference as it will discover repeated patterns including more than one PRMInstance<GUM_SCALAR>.

This algorithm proceeds in three main steps represented by the private methods GSpan::sortNodesAndEdges__(), GSpan::subgraph_mining__() and GSpan::sortPatterns__().

Definition at line 56 of file DFSTree.h.

Member Typedef Documentation

◆ MatchedInstances

template<typename GUM_SCALAR >
typedef Set< Sequence< PRMInstance< GUM_SCALAR >* >* > gum::prm::GSpan< GUM_SCALAR >::MatchedInstances

Code alias.

Definition at line 169 of file gspan.h.

Constructor & Destructor Documentation

◆ GSpan()

template<typename GUM_SCALAR >
INLINE gum::prm::GSpan< GUM_SCALAR >::GSpan ( const PRM< GUM_SCALAR > &  prm,
const PRMSystem< GUM_SCALAR > &  sys,
gspan::SearchStrategy< GUM_SCALAR > *  strategy = 0 
)

Default constructor.

Parameters
prmThe PRM<GUM_SCALAR> used by this class.
sysThe PRMSystem<GUM_SCALAR> on which this class searches for patterns.
strategyThe search strategy used for pattern mining, the default strategy is gspan::FrequenceSearch.

Definition at line 360 of file gspan_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

362  :
363  graph__(new gspan::InterfaceGraph< GUM_SCALAR >(sys)),
364  tree__(*graph__, strategy), depth_stop__(INT_MAX) {
365  GUM_CONSTRUCTOR(GSpan);
366  }
Size depth_stop__
The max depth allowed for the DSF tree.
Definition: gspan.h:221
gspan::InterfaceGraph< GUM_SCALAR > * graph__
The interface graph used by this class.
Definition: gspan.h:215
gspan::DFSTree< GUM_SCALAR > tree__
The DFSTree used to discover new patters.
Definition: gspan.h:218
GSpan(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &sys, gspan::SearchStrategy< GUM_SCALAR > *strategy=0)
Default constructor.
Definition: gspan_tpl.h:360
+ Here is the call graph for this function:

◆ ~GSpan()

template<typename GUM_SCALAR >
INLINE gum::prm::GSpan< GUM_SCALAR >::~GSpan ( )

Destructor.

Definition at line 369 of file gspan_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

369  {
370  GUM_DESTRUCTOR(GSpan);
371 
372  for (const auto& elt: matched_instances__)
373  delete elt.second;
374 
375  delete graph__;
376  }
gspan::InterfaceGraph< GUM_SCALAR > * graph__
The interface graph used by this class.
Definition: gspan.h:215
HashTable< gspan::Pattern *, MatchedInstances *> matched_instances__
Mapping between a pattern and the multiset of instances matched to it.
Definition: gspan.h:237
GSpan(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &sys, gspan::SearchStrategy< GUM_SCALAR > *strategy=0)
Default constructor.
Definition: gspan_tpl.h:360
+ Here is the call graph for this function:

Member Function Documentation

◆ cost_func__()

template<typename GUM_SCALAR >
INLINE Idx gum::prm::GSpan< GUM_SCALAR >::cost_func__ ( Size  interface_size,
Size  frequency 
)
private

Returns the cost with respect to an interface size and its frequency.

Parameters
interface_sizeThe size of all output nodes of a pattern.
frequencyThe frequency of the pattern in the current interface graph.
Returns
the cost with respect to an interface size and its frequency.

Definition at line 399 of file gspan_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

400  {
401  return Idx(interface_size * frequency);
402  }
Size Idx
Type for indexes.
Definition: types.h:52
+ Here is the call graph for this function:

◆ discoverPatterns()

template<typename GUM_SCALAR >
void gum::prm::GSpan< GUM_SCALAR >::discoverPatterns ( )

This will methods will discover repeated patterns in the PRMSystem<GUM_SCALAR> assigned to this class.

The results are saved in a vector of Patterns which can be obtained by calling GSpan::patterns().

Definition at line 35 of file gspan_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

35  {
36  Timer t;
38  gspan::InterfaceGraph< GUM_SCALAR > graph(*graph__);
39 
40  for (auto root = tree__.roots().begin(); root != tree__.roots().end();
41  ++root) {
42  if (tree__.strategy().accept_root(&(tree__.pattern(*root)))) {
43  gspan::Pattern& p = tree__.pattern(*root);
44  subgraph_mining__(graph, p);
45 
46  for (const auto node: tree__.iso_graph(p).nodes()) {
47  PRMInstance< GUM_SCALAR >* u = tree__.iso_map(p, node).atPos(0);
48  PRMInstance< GUM_SCALAR >* v = tree__.iso_map(p, node).atPos(1);
49  graph.graph().eraseEdge(Edge(graph.id(u), graph.id(v)));
50  }
51  }
52  }
53 
55  }
void subgraph_mining__(gspan::InterfaceGraph< GUM_SCALAR > &graph, gspan::Pattern &p)
Discovers new patterns by developing p.
Definition: gspan_tpl.h:102
gspan::InterfaceGraph< GUM_SCALAR > * graph__
The interface graph used by this class.
Definition: gspan.h:215
gspan::DFSTree< GUM_SCALAR > tree__
The DFSTree used to discover new patters.
Definition: gspan.h:218
void sortPatterns__()
Sort the patterns and compute their respective costs.
Definition: gspan_tpl.h:230
void sortNodesAndEdges__()
Sort the nodes and edges of graph__.
Definition: gspan_tpl.h:58
+ Here is the call graph for this function:

◆ getMaxDFSDepth()

template<typename GUM_SCALAR >
INLINE Size gum::prm::GSpan< GUM_SCALAR >::getMaxDFSDepth ( ) const

Returns the maximal depth of the DFSTree used to discover new patterns.

Returns
the maximal depth of the DFSTree used to discover new patterns.

Definition at line 379 of file gspan_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

379  {
380  return depth_stop__;
381  }
Size depth_stop__
The max depth allowed for the DSF tree.
Definition: gspan.h:221
+ Here is the call graph for this function:

◆ interfaceGraph() [1/2]

template<typename GUM_SCALAR >
INLINE gspan::InterfaceGraph< GUM_SCALAR > & gum::prm::GSpan< GUM_SCALAR >::interfaceGraph ( )

Returns the InterfaceGraph used by this.

Returns
the InterfaceGraph used by this.

Definition at line 429 of file gspan_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

429  {
430  return *graph__;
431  }
gspan::InterfaceGraph< GUM_SCALAR > * graph__
The interface graph used by this class.
Definition: gspan.h:215
+ Here is the call graph for this function:

◆ interfaceGraph() [2/2]

template<typename GUM_SCALAR >
INLINE const gspan::InterfaceGraph< GUM_SCALAR > & gum::prm::GSpan< GUM_SCALAR >::interfaceGraph ( ) const

Returns the InterfaceGraph used by this.

Returns
the InterfaceGraph used by this.

Definition at line 435 of file gspan_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

435  {
436  return *graph__;
437  }
gspan::InterfaceGraph< GUM_SCALAR > * graph__
The interface graph used by this class.
Definition: gspan.h:215
+ Here is the call graph for this function:

◆ isEdgeEligible__()

template<typename GUM_SCALAR >
INLINE bool gum::prm::GSpan< GUM_SCALAR >::isEdgeEligible__ ( typename gspan::EdgeData< GUM_SCALAR > *  e)
private

Returns true if e is an eligible root edge.

Parameters
eAn EdgeData<GUM_SCALAR>.
Returns
true if e is an eligible root edge.

Definition at line 441 of file gspan_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

441  {
442  return (graph__->edges(e->l).size() >= 2)
443  && (graph__->nodes(e->l_u).size() >= 2)
444  && (graph__->nodes(e->l_v).size() >= 2);
445  }
gspan::InterfaceGraph< GUM_SCALAR > * graph__
The interface graph used by this class.
Definition: gspan.h:215
+ Here is the call graph for this function:

◆ matches() [1/2]

template<typename GUM_SCALAR >
INLINE GSpan< GUM_SCALAR >::MatchedInstances & gum::prm::GSpan< GUM_SCALAR >::matches ( const gspan::Pattern p)

Returns a mapping between patterns and the sequence of instance in the interface graph matching them.

Returns
a mapping between patterns and the sequence of instance in the interface graph matching them.

Definition at line 417 of file gspan_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

417  {
418  return *(matched_instances__[const_cast< gspan::Pattern* >(&p)]);
419  }
HashTable< gspan::Pattern *, MatchedInstances *> matched_instances__
Mapping between a pattern and the multiset of instances matched to it.
Definition: gspan.h:237
+ Here is the call graph for this function:

◆ matches() [2/2]

template<typename GUM_SCALAR >
INLINE const GSpan< GUM_SCALAR >::MatchedInstances & gum::prm::GSpan< GUM_SCALAR >::matches ( const gspan::Pattern p) const

Returns a mapping between patterns and the sequence of instance in the interface graph matching them.

Returns
a mapping between patterns and the sequence of instance in the interface graph matching them.

Definition at line 423 of file gspan_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

423  {
424  return *(matched_instances__[const_cast< gspan::Pattern* >(&p)]);
425  }
HashTable< gspan::Pattern *, MatchedInstances *> matched_instances__
Mapping between a pattern and the multiset of instances matched to it.
Definition: gspan.h:237
+ Here is the call graph for this function:

◆ patterns() [1/2]

template<typename GUM_SCALAR >
INLINE std::vector< gspan::Pattern *> & gum::prm::GSpan< GUM_SCALAR >::patterns ( )

Returns the Pattern mined by this class in a decreasing order of interest.

Returns
the Pattern mined by this class in a decreasing order of interest.

Definition at line 405 of file gspan_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

405  {
406  return patterns__;
407  }
std::vector< gspan::Pattern *> patterns__
The vector of discovered patters, in decreasing order of interest.
Definition: gspan.h:224
+ Here is the call graph for this function:

◆ patterns() [2/2]

template<typename GUM_SCALAR >
INLINE const std::vector< gspan::Pattern *> & gum::prm::GSpan< GUM_SCALAR >::patterns ( ) const

Returns the Pattern mined by this class in a decreasing order of interest.

Returns
the Pattern mined by this class in a decreasing order of interest.

Definition at line 411 of file gspan_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

411  {
412  return patterns__;
413  }
std::vector< gspan::Pattern *> patterns__
The vector of discovered patters, in decreasing order of interest.
Definition: gspan.h:224
+ Here is the call graph for this function:

◆ setMaxDFSDepth()

template<typename GUM_SCALAR >
INLINE void gum::prm::GSpan< GUM_SCALAR >::setMaxDFSDepth ( Size  depth)

Defines the maximal depth of the DFSTree used by this class to discover new patterns.

Parameters
depthThe new maximal DFSTree depth.

Definition at line 384 of file gspan_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

384  {
385  depth_stop__ = depth;
386  }
Size depth_stop__
The max depth allowed for the DSF tree.
Definition: gspan.h:221
+ Here is the call graph for this function:

◆ sortNodesAndEdges__()

template<typename GUM_SCALAR >
void gum::prm::GSpan< GUM_SCALAR >::sortNodesAndEdges__ ( )
private

Sort the nodes and edges of graph__.

Definition at line 58 of file gspan_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

58  {
59  for (auto iter = graph__->labels().begin(); iter != graph__->labels().end();
60  ++iter) {
61  try {
62  if (graph__->nodes(iter.second()).size() >= 2) {
63  cost__.insert(iter.second(),
64  cost_func__(iter.second()->tree_width,
65  graph__->nodes(iter.second()).size()));
66  nodes__.push_back(const_cast< gspan::LabelData* >(iter.second()));
67  }
68  } catch (NotFound&) {
69  // It's a label over edges
70  if (isEdgeEligible__(*(graph__->edges(iter.second()).begin()))) {
71  cost__.insert(iter.second(),
72  cost_func__(iter.second()->tree_width,
73  graph__->edges(iter.second()).size()));
74  edges__.push_back(iter.second());
75  }
76  }
77  }
78 
79  Bijection< Idx, gspan::LabelData* >* new_labels
80  = new Bijection< Idx, gspan::LabelData* >();
81  GSpan< GUM_SCALAR >::LabelSort my_sort(this);
82  std::sort(nodes__.begin(), nodes__.end(), my_sort);
83  std::sort(edges__.begin(), edges__.end(), my_sort);
84  Size idx = 0;
85 
86  for (auto iter = nodes__.begin(); iter != nodes__.end(); ++iter) {
87  (*iter)->id = ++idx;
88  new_labels->insert(idx, *iter);
89  }
90 
91  for (auto iter = edges__.begin(); iter != edges__.end(); ++iter) {
92  (*iter)->id = ++idx;
93  new_labels->insert(idx, *iter);
94  tree__.addRoot(**iter);
95  }
96 
97  delete graph__->labels__;
98  graph__->labels__ = new_labels;
99  }
gspan::InterfaceGraph< GUM_SCALAR > * graph__
The interface graph used by this class.
Definition: gspan.h:215
gspan::DFSTree< GUM_SCALAR > tree__
The DFSTree used to discover new patters.
Definition: gspan.h:218
Size cost_func__(Size interface_size, Size frequency)
Returns the cost with respect to an interface size and its frequency.
Definition: gspan_tpl.h:399
bool isEdgeEligible__(typename gspan::EdgeData< GUM_SCALAR > *e)
Returns true if e is an eligible root edge.
Definition: gspan_tpl.h:441
HashTable< gspan::LabelData *, Idx > cost__
Mapping between labels and their cost.
Definition: gspan.h:233
std::vector< gspan::LabelData *> edges__
The vector of edges in graph__, in decreasing order of interest.
Definition: gspan.h:230
std::vector< gspan::LabelData *> nodes__
The vector of nodes in graph__, in decreasing order of interest.
Definition: gspan.h:227
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ sortPatterns__()

template<typename GUM_SCALAR >
void gum::prm::GSpan< GUM_SCALAR >::sortPatterns__ ( )
private

Sort the patterns and compute their respective costs.

Definition at line 230 of file gspan_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

230  {
231  // First we put all the patterns in patterns__.
232  std::vector< NodeId > stack;
233 
234  for (std::list< NodeId >::reverse_iterator root = tree().roots().rbegin();
235  root != tree().roots().rend();
236  ++root)
237  stack.push_back(*root);
238 
239  NodeId id = 0;
240  std::list< NodeId >* children = nullptr;
241 
242  while (!stack.empty()) {
243  id = stack.back();
244  stack.pop_back();
245  patterns__.push_back(&(tree().pattern(id)));
246  children = &(tree().children(tree().pattern(id)));
247 
248  for (std::list< NodeId >::reverse_iterator child = children->rbegin();
249  child != children->rend();
250  ++child)
251  stack.push_back(*child);
252  }
253 
254  if (!patterns__.empty()) {
255  // We sort patterns__.
256  GSpan< GUM_SCALAR >::PatternSort my_sort(this);
257  std::sort(patterns__.begin(), patterns__.end(), my_sort);
258  // Now we need to find all the matches we can, using patterns__.
259  // We start by the best Pattern and add it's maximal independent set to
260  // chosen__
263  Sequence< PRMInstance< GUM_SCALAR >* >* match = nullptr;
264 
265  for (const auto node: tree().max_indep_set(*(patterns__.front()))) {
266  match = &(tree().iso_map(*(patterns__.front()), node));
267 
268  for (const auto i: *match)
269  chosen__.insert(i);
270 
271  matches->insert(match);
272  }
273 
274  matched_instances__.insert(patterns__.front(), matches);
275  // Now we see what kind of pattern we can still use
276  bool found;
277  UndiGraph* iso_graph = nullptr;
278 
279  for (auto patt = patterns__.begin() + 1; patt != patterns__.end();
280  ++patt) {
281  UndiGraph reduced_iso_graph;
282  std::vector< NodeId > degree_list;
283  iso_graph = &(tree().iso_graph(**patt));
284 
285  for (const auto node: iso_graph->nodes()) {
286  found = false;
287  match = &(tree().iso_map(**patt, node));
288 
289  for (const auto i: *match)
290  if (chosen__.exists(i)) {
291  found = true;
292  break;
293  }
294 
295  if (!found) {
296  // We add the pattern to the reduced isomorphism graph to compute
297  // the
298  // max independent set
299  // over the remaining matches
300  reduced_iso_graph.addNodeWithId(node);
301 
302  for (const auto iso: reduced_iso_graph.nodes())
303  if (iso_graph->existsEdge(node, iso))
304  reduced_iso_graph.addEdge(node, iso);
305 
306  degree_list.push_back(node);
307  }
308  }
309 
310  // We create a new set to hold all the chosen matches of patt
312  // We can compute the max independent set and the matches belonging to
313  // it
314  typename gspan::DFSTree< GUM_SCALAR >::NeighborDegreeSort my_sort(
315  reduced_iso_graph);
316  std::sort(degree_list.begin(), degree_list.end(), my_sort);
317  Set< NodeId > removed;
318 
319  for (const auto node: degree_list)
320  if (!removed.exists(node)) {
321  // First we update removed to follow the max independent set
322  // algorithm
323  removed.insert(node);
324 
325  for (const auto neighbor: reduced_iso_graph.neighbours(node))
326  removed.insert(neighbor);
327 
328  // Second we update match and matches to keep track of the current
329  // match
330  match = &(tree().iso_map(**patt, node));
331  matches->insert(match);
332 
333  for (const auto elt: *match)
334  chosen__.insert(elt);
335  }
336 
337  matched_instances__.insert(*patt, matches);
338  }
339 
340  // // We remove patterns with 0 matches
341  std::vector< size_t > trash;
342 
343  for (size_t idx = 0; idx < patterns__.size(); ++idx)
344  if (matched_instances__[patterns__[idx]]->size() < 2)
345  trash.push_back(idx);
346 
347  while (trash.size()) {
348  delete matched_instances__[patterns__[trash.back()]];
349  matched_instances__.erase(patterns__[trash.back()]);
350  // delete patterns__[trash.back()];
351  patterns__[trash.back()] = patterns__.back();
352  patterns__.pop_back();
353  trash.pop_back();
354  }
355  }
356  }
Set< Sequence< PRMInstance< GUM_SCALAR > *> *> MatchedInstances
Code alias.
Definition: gspan.h:169
HashTable< gspan::Pattern *, MatchedInstances *> matched_instances__
Mapping between a pattern and the multiset of instances matched to it.
Definition: gspan.h:237
Set< PRMInstance< GUM_SCALAR > *> chosen__
Contains all instance which belongs to a discovered and used pattern.
Definition: gspan.h:240
std::vector< gspan::Pattern *> patterns__
The vector of discovered patters, in decreasing order of interest.
Definition: gspan.h:224
gspan::DFSTree< GUM_SCALAR > & tree()
Returns the DFSTree used to discover new patters.
Definition: gspan_tpl.h:389
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:417
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:632
+ Here is the call graph for this function:

◆ subgraph_mining__()

template<typename GUM_SCALAR >
void gum::prm::GSpan< GUM_SCALAR >::subgraph_mining__ ( gspan::InterfaceGraph< GUM_SCALAR > &  graph,
gspan::Pattern p 
)
private

Discovers new patterns by developing p.

Parameters
graphThe interface graph used in this discovery process.
pThe pattern used as a base for discovery.

Definition at line 102 of file gspan_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

104  {
105  std::vector< gspan::Pattern* > stack;
106  stack.push_back(&pat);
107  // Pointers used in the following while
108  gspan::Pattern* p = nullptr;
109  HashTable< std::string, gspan::EdgeGrowth< GUM_SCALAR >* >* edge_count
110  = nullptr;
111  gspan::EdgeGrowth< GUM_SCALAR >* edge_growth = nullptr;
112  Sequence< PRMInstance< GUM_SCALAR >* >* seq = nullptr;
113  PRMInstance< GUM_SCALAR >* current = nullptr;
114  PRMInstance< GUM_SCALAR >* neighbor = nullptr;
115 
116  // Neighbor_id is the neighbor's id in the interface graph and
117  // neighbor_node
118  // is its id in the rightmost path in the case of a backward edge growth
119  NodeId current_id = 0;
120  NodeId neighbor_node = 0;
121  gspan::LabelData* neighbor_label = 0;
122 
123  typename gspan::EdgeData< GUM_SCALAR >* edge_data = nullptr;
124 
125  size_t idx;
126  const std::list< NodeId >* children = 0;
127 
128  while (!stack.empty()) {
129  // Getting next pattern
130  p = stack.back();
131  stack.pop_back();
132 
133  if (p->code().codes.size() < depth_stop__) {
134  // We need the rightmost path of p
135  std::list< NodeId > r_path;
136  p->rightmostPath(r_path);
137  // Mapping used to count each possible child of p, the position in the
138  // vector
139  // matches the one in the rightmost path
140  std::vector<
141  HashTable< std::string, gspan::EdgeGrowth< GUM_SCALAR >* >* >
142  count_vector;
143 
144  for (size_t i = 0; i < r_path.size(); ++i)
145  count_vector.push_back(
146  new HashTable< std::string, gspan::EdgeGrowth< GUM_SCALAR >* >());
147 
148  // For each subgraph represented by p, we look for a valid edge growth
149  // for
150  // each instance match of p in its isomorphism graph.
151  for (const auto iso_node: tree__.iso_graph(*p).nodes()) {
152  seq = &(tree__.iso_map(*p, iso_node));
153  idx = 0;
154 
155  for (const auto node: r_path) {
156  edge_count = count_vector[idx];
157  // Retrieving the equivalent instance in the current match
158  current = seq->atPos((Idx)(node - 1));
159  current_id = ig.id(current);
160  // Checking for edges not in p
161 
162  for (const auto neighbor_id: ig.graph().neighbours(current_id)) {
163  neighbor = ig.node(neighbor_id).n;
164 
165  // We want a forward edge in any case or a backward edge if
166  // current
167  // is the rightmost vertex
168  if ((!seq->exists(neighbor)) || (node == r_path.back())) {
169  // Things we need to know: the LabelData data of the neighbour
170  // and,
171  // if it's a backward edge, its node id in the rightmost path
172  edge_data = &(ig.edge(current_id, neighbor_id));
173  neighbor_label = (neighbor == edge_data->u) ? edge_data->l_u
174  : edge_data->l_v;
175  neighbor_node
176  = (seq->exists(neighbor)) ? seq->pos(neighbor) + 1 : 0;
177  // Adding the edge growth to the edge_growth hashtable
178  gspan::EdgeGrowth< GUM_SCALAR > temp_growth(node,
179  edge_data->l,
180  neighbor_label,
181  neighbor_node);
182 
183  try {
184  edge_growth = (*edge_count)[temp_growth.toString()];
185  edge_growth->insert(current, neighbor);
186  } catch (NotFound&) {
187  edge_growth
188  = new gspan::EdgeGrowth< GUM_SCALAR >(node,
189  edge_data->l,
190  neighbor_label,
191  neighbor_node);
192  edge_growth->insert(current, neighbor);
193  edge_count->insert(edge_growth->toString(), edge_growth);
194  }
195  }
196  }
197  }
198  }
199 
200  // Removing any infrequent child
201  for (size_t node = 0; node < count_vector.size(); ++node) {
202  edge_count = count_vector[node];
203 
204  for (const auto& elt: *edge_count) {
205  try {
206  tree__.growPattern(*p, *elt.second, 2);
207  } catch (OperationNotAllowed&) {
208  // The child was not minimal or was not worth considering
209  }
210 
211  delete elt.second;
212  }
213 
214  delete edge_count;
215  }
216 
217  // Calling subgraph_mining__ over children of p
218  children = &(tree__.children(*p));
219 
220  for (std::list< NodeId >::const_reverse_iterator child
221  = children->rbegin();
222  child != children->rend();
223  ++child)
224  stack.push_back(&(tree__.pattern(*child)));
225  }
226  }
227  }
Size depth_stop__
The max depth allowed for the DSF tree.
Definition: gspan.h:221
gspan::DFSTree< GUM_SCALAR > tree__
The DFSTree used to discover new patters.
Definition: gspan.h:218
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ tree() [1/2]

template<typename GUM_SCALAR >
INLINE gspan::DFSTree< GUM_SCALAR > & gum::prm::GSpan< GUM_SCALAR >::tree ( )

Returns the DFSTree used to discover new patters.

Returns
the DFSTree used to discover new patters.

Definition at line 389 of file gspan_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

389  {
390  return tree__;
391  }
gspan::DFSTree< GUM_SCALAR > tree__
The DFSTree used to discover new patters.
Definition: gspan.h:218
+ Here is the call graph for this function:

◆ tree() [2/2]

template<typename GUM_SCALAR >
INLINE const gspan::DFSTree< GUM_SCALAR > & gum::prm::GSpan< GUM_SCALAR >::tree ( ) const

Returns the DFSTree used to discover new patters.

Returns
the DFSTree used to discover new patters.

Definition at line 394 of file gspan_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

394  {
395  return tree__;
396  }
gspan::DFSTree< GUM_SCALAR > tree__
The DFSTree used to discover new patters.
Definition: gspan.h:218
+ Here is the call graph for this function:

Member Data Documentation

◆ chosen__

template<typename GUM_SCALAR >
Set< PRMInstance< GUM_SCALAR >* > gum::prm::GSpan< GUM_SCALAR >::chosen__
private

Contains all instance which belongs to a discovered and used pattern.

Definition at line 240 of file gspan.h.

◆ cost__

template<typename GUM_SCALAR >
HashTable< gspan::LabelData*, Idx > gum::prm::GSpan< GUM_SCALAR >::cost__
private

Mapping between labels and their cost.

Definition at line 233 of file gspan.h.

◆ depth_stop__

template<typename GUM_SCALAR >
Size gum::prm::GSpan< GUM_SCALAR >::depth_stop__
private

The max depth allowed for the DSF tree.

Definition at line 221 of file gspan.h.

◆ edges__

template<typename GUM_SCALAR >
std::vector< gspan::LabelData* > gum::prm::GSpan< GUM_SCALAR >::edges__
private

The vector of edges in graph__, in decreasing order of interest.

Definition at line 230 of file gspan.h.

◆ graph__

template<typename GUM_SCALAR >
gspan::InterfaceGraph< GUM_SCALAR >* gum::prm::GSpan< GUM_SCALAR >::graph__
private

The interface graph used by this class.

Definition at line 215 of file gspan.h.

◆ matched_instances__

template<typename GUM_SCALAR >
HashTable< gspan::Pattern*, MatchedInstances* > gum::prm::GSpan< GUM_SCALAR >::matched_instances__
private

Mapping between a pattern and the multiset of instances matched to it.

Definition at line 237 of file gspan.h.

◆ nodes__

template<typename GUM_SCALAR >
std::vector< gspan::LabelData* > gum::prm::GSpan< GUM_SCALAR >::nodes__
private

The vector of nodes in graph__, in decreasing order of interest.

Definition at line 227 of file gspan.h.

◆ patterns__

template<typename GUM_SCALAR >
std::vector< gspan::Pattern* > gum::prm::GSpan< GUM_SCALAR >::patterns__
private

The vector of discovered patters, in decreasing order of interest.

Definition at line 224 of file gspan.h.

◆ tree__

template<typename GUM_SCALAR >
gspan::DFSTree< GUM_SCALAR > gum::prm::GSpan< GUM_SCALAR >::tree__
private

The DFSTree used to discover new patters.

Definition at line 218 of file gspan.h.


The documentation for this class was generated from the following files: