![]() |
aGrUM 3.2.0
a C++ library for (probabilistic) graphical models
|
This class discovers pattern in a PRM<GUM_SCALAR>'s PRMSystem<GUM_SCALAR> to speed up structured inference. More...
#include <agrum/PRM/gspan.h>
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... | |
Public Member Functions | |
Constructors & destructor. | |
| GSpan (const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &sys, gspan::SearchStrategy< GUM_SCALAR > *strategy=0) | |
| Default constructor. | |
| ~GSpan () | |
| Destructor. | |
Getters and setters. | |
| Size | getMaxDFSDepth () const |
| Returns the maximal depth of the DFSTree used to discover new patterns. | |
| void | setMaxDFSDepth (Size depth) |
| Defines the maximal depth of the DFSTree used by this class to discover new patterns. | |
| gspan::DFSTree< GUM_SCALAR > & | tree () |
| Returns the DFSTree used to discover new patters. | |
| const gspan::DFSTree< GUM_SCALAR > & | tree () const |
| Returns the DFSTree used to discover new patters. | |
| gspan::InterfaceGraph< GUM_SCALAR > & | interfaceGraph () |
| Returns the InterfaceGraph used by this. | |
| const gspan::InterfaceGraph< GUM_SCALAR > & | interfaceGraph () const |
| Returns the InterfaceGraph used by this. | |
Private Member Functions | |
Private Methods | |
| void | _sortNodesAndEdges_ () |
| Sort the nodes and edges of graph. | |
| void | _subgraph_mining_ (gspan::InterfaceGraph< GUM_SCALAR > &graph, gspan::Pattern &p) |
| Discovers new patterns by developing p. | |
| Size | _cost_func_ (Size interface_size, Size frequency) |
| Returns the cost with respect to an interface size and its frequency. | |
| void | _sortPatterns_ () |
| Sort the patterns and compute their respective costs. | |
| bool | _isEdgeEligible_ (typename gspan::EdgeData< GUM_SCALAR > *e) |
| Returns true if e is an eligible root edge. | |
Private Attributes | |
Private Members. | |
| gspan::InterfaceGraph< GUM_SCALAR > * | _graph_ |
| The interface graph used by this class. | |
| gspan::DFSTree< GUM_SCALAR > | _tree_ |
| The DFSTree used to discover new patters. | |
| Size | _depth_stop_ |
| The max depth allowed for the DSF tree. | |
| std::vector< gspan::Pattern * > | _patterns_ |
| The vector of discovered patters, in decreasing order of interest. | |
| std::vector< gspan::LabelData * > | _nodes_ |
| The vector of nodes in graph, in decreasing order of interest. | |
| std::vector< gspan::LabelData * > | _edges_ |
| The vector of edges in graph, in decreasing order of interest. | |
| HashTable< gspan::LabelData *, Idx > | _cost_ |
| Mapping between labels and their cost. | |
| HashTable< gspan::Pattern *, MatchedInstances * > | _matched_instances_ |
| Mapping between a pattern and the multiset of instances matched to it. | |
| Set< PRMInstance< GUM_SCALAR > * > | _chosen_ |
| Contains all instance which belongs to a discovered and used pattern. | |
Pattern discovery methods. | |
| using | MatchedInstances = Set< Sequence< PRMInstance< GUM_SCALAR >* >* > |
| Code alias. | |
| void | discoverPatterns () |
| This will methods will discover repeated patterns in the PRMSystem<GUM_SCALAR> assigned to this class. | |
| std::vector< gspan::Pattern * > & | patterns () |
| Returns the Pattern mined by this class in a decreasing order of interest. | |
| const std::vector< gspan::Pattern * > & | patterns () const |
| Returns the Pattern mined by this class in a decreasing order of interest. | |
| MatchedInstances & | matches (const gspan::Pattern &p) |
| Returns a mapping between patterns and the sequence of instance in the interface graph matching them. | |
| const MatchedInstances & | matches (const gspan::Pattern &p) const |
| Returns a mapping between patterns and the sequence of instance in the interface graph matching them. | |
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().
| using gum::prm::GSpan< GUM_SCALAR >::MatchedInstances = Set< Sequence< PRMInstance< GUM_SCALAR >* >* > |
| gum::prm::GSpan< GUM_SCALAR >::GSpan | ( | const PRM< GUM_SCALAR > & | prm, |
| const PRMSystem< GUM_SCALAR > & | sys, | ||
| gspan::SearchStrategy< GUM_SCALAR > * | strategy = 0 ) |
Default constructor.
| prm | The PRM<GUM_SCALAR> used by this class. |
| sys | The PRMSystem<GUM_SCALAR> on which this class searches for patterns. |
| strategy | The search strategy used for pattern mining, the default strategy is gspan::FrequenceSearch. |
Definition at line 366 of file gspan_tpl.h.
References GSpan(), _depth_stop_, _graph_, and _tree_.
Referenced by GSpan(), gum::prm::GSpan< GUM_SCALAR >::LabelSort::LabelSort(), gum::prm::GSpan< GUM_SCALAR >::PatternSort::PatternSort(), and ~GSpan().
| gum::prm::GSpan< GUM_SCALAR >::~GSpan | ( | ) |
Destructor.
Definition at line 375 of file gspan_tpl.h.
References GSpan(), _graph_, and _matched_instances_.
|
private |
Returns the cost with respect to an interface size and its frequency.
| interface_size | The size of all output nodes of a pattern. |
| frequency | The frequency of the pattern in the current interface graph. |
Definition at line 405 of file gspan_tpl.h.
Referenced by _sortNodesAndEdges_().
|
private |
Returns true if e is an eligible root edge.
| e | An EdgeData<GUM_SCALAR>. |
Definition at line 442 of file gspan_tpl.h.
References _graph_, gum::prm::gspan::EdgeData< GUM_SCALAR >::l, gum::prm::gspan::EdgeData< GUM_SCALAR >::l_u, and gum::prm::gspan::EdgeData< GUM_SCALAR >::l_v.
Referenced by _sortNodesAndEdges_().
|
private |
Sort the nodes and edges of graph.
Definition at line 79 of file gspan_tpl.h.
References _cost_, _cost_func_(), _edges_, _graph_, _isEdgeEligible_(), _nodes_, _tree_, and gum::BijectionImplementation< T1, T2, Gen >::insert().
Referenced by discoverPatterns().
|
private |
Sort the patterns and compute their respective costs.
Definition at line 241 of file gspan_tpl.h.
References _chosen_, _matched_instances_, _patterns_, gum::UndiGraph::addEdge(), gum::NodeGraphPart::addNodeWithId(), gum::Set< Key >::exists(), gum::EdgeGraphPart::existsEdge(), gum::SequenceImplementation< Key, Gen >::insert(), gum::Set< Key >::insert(), matches(), gum::EdgeGraphPart::neighbours(), gum::NodeGraphPart::nodes(), and tree().
Referenced by discoverPatterns().
|
private |
Discovers new patterns by developing p.
| graph | The interface graph used in this discovery process. |
| p | The pattern used as a base for discovery. |
Definition at line 121 of file gspan_tpl.h.
References _depth_stop_, _tree_, gum::SequenceImplementation< Key, Gen >::atPos(), gum::prm::gspan::Pattern::code(), gum::prm::gspan::DFSCode::codes, gum::prm::gspan::InterfaceGraph< GUM_SCALAR >::edge(), gum::HashTable< Key, Val >::exists(), gum::SequenceImplementation< Key, Gen >::exists(), gum::prm::gspan::InterfaceGraph< GUM_SCALAR >::id(), gum::HashTable< Key, Val >::insert(), gum::prm::gspan::EdgeGrowth< GUM_SCALAR >::insert(), gum::prm::gspan::InterfaceGraph< GUM_SCALAR >::internalGraph(), gum::prm::gspan::EdgeData< GUM_SCALAR >::l, gum::prm::gspan::EdgeData< GUM_SCALAR >::l_u, gum::prm::gspan::EdgeData< GUM_SCALAR >::l_v, gum::EdgeGraphPart::neighbours(), gum::prm::gspan::InterfaceGraph< GUM_SCALAR >::node(), gum::SequenceImplementation< Key, Gen >::pos(), gum::prm::gspan::Pattern::rightmostPath(), gum::prm::gspan::EdgeGrowth< GUM_SCALAR >::toString(), and gum::prm::gspan::EdgeData< GUM_SCALAR >::u.
Referenced by discoverPatterns().
| 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 57 of file gspan_tpl.h.
References gum::Edge::Edge(), _graph_, _sortNodesAndEdges_(), _sortPatterns_(), _subgraph_mining_(), and _tree_.
| Size gum::prm::GSpan< GUM_SCALAR >::getMaxDFSDepth | ( | ) | const |
Returns the maximal depth of the DFSTree used to discover new patterns.
Definition at line 385 of file gspan_tpl.h.
References _depth_stop_.
| gspan::InterfaceGraph< GUM_SCALAR > & gum::prm::GSpan< GUM_SCALAR >::interfaceGraph | ( | ) |
Returns the InterfaceGraph used by this.
Definition at line 432 of file gspan_tpl.h.
References _graph_.
| const gspan::InterfaceGraph< GUM_SCALAR > & gum::prm::GSpan< GUM_SCALAR >::interfaceGraph | ( | ) | const |
Returns the InterfaceGraph used by this.
Definition at line 437 of file gspan_tpl.h.
References _graph_.
| 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.
Definition at line 421 of file gspan_tpl.h.
References _matched_instances_.
Referenced by _sortPatterns_().
| 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.
Definition at line 427 of file gspan_tpl.h.
References _matched_instances_.
| std::vector< gspan::Pattern * > & gum::prm::GSpan< GUM_SCALAR >::patterns | ( | ) |
Returns the Pattern mined by this class in a decreasing order of interest.
Definition at line 410 of file gspan_tpl.h.
References _patterns_.
| 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.
Definition at line 415 of file gspan_tpl.h.
References _patterns_.
| void gum::prm::GSpan< GUM_SCALAR >::setMaxDFSDepth | ( | Size | depth | ) |
Defines the maximal depth of the DFSTree used by this class to discover new patterns.
| depth | The new maximal DFSTree depth. |
Definition at line 390 of file gspan_tpl.h.
References _depth_stop_.
| gspan::DFSTree< GUM_SCALAR > & gum::prm::GSpan< GUM_SCALAR >::tree | ( | ) |
Returns the DFSTree used to discover new patters.
Definition at line 395 of file gspan_tpl.h.
References _tree_.
Referenced by _sortPatterns_().
| const gspan::DFSTree< GUM_SCALAR > & gum::prm::GSpan< GUM_SCALAR >::tree | ( | ) | const |
Returns the DFSTree used to discover new patters.
Definition at line 400 of file gspan_tpl.h.
References _tree_.
|
private |
Contains all instance which belongs to a discovered and used pattern.
Definition at line 257 of file gspan.h.
Referenced by _sortPatterns_().
|
private |
Mapping between labels and their cost.
Definition at line 250 of file gspan.h.
Referenced by _sortNodesAndEdges_().
|
private |
The max depth allowed for the DSF tree.
Definition at line 238 of file gspan.h.
Referenced by GSpan(), _subgraph_mining_(), getMaxDFSDepth(), and setMaxDFSDepth().
|
private |
The vector of edges in graph, in decreasing order of interest.
Definition at line 247 of file gspan.h.
Referenced by _sortNodesAndEdges_().
|
private |
The interface graph used by this class.
Definition at line 232 of file gspan.h.
Referenced by GSpan(), ~GSpan(), _isEdgeEligible_(), _sortNodesAndEdges_(), discoverPatterns(), interfaceGraph(), and interfaceGraph().
|
private |
|
private |
The vector of nodes in graph, in decreasing order of interest.
Definition at line 244 of file gspan.h.
Referenced by _sortNodesAndEdges_().
|
private |
The vector of discovered patters, in decreasing order of interest.
Definition at line 241 of file gspan.h.
Referenced by _sortPatterns_(), patterns(), and patterns().
|
private |
The DFSTree used to discover new patters.
Definition at line 235 of file gspan.h.
Referenced by GSpan(), _sortNodesAndEdges_(), _subgraph_mining_(), discoverPatterns(), tree(), and tree().