55 template <
typename GUM_SCALAR >
61 for (
auto root =
_tree_.roots().begin(); root !=
_tree_.roots().end(); ++root) {
62 if (
_tree_.strategy().accept_root(&(
_tree_.pattern(*root)))) {
66 for (
const auto node:
_tree_.iso_graph(p).nodes()) {
77 template <
typename GUM_SCALAR >
79 for (
auto iter =
_graph_->labels().begin(); iter !=
_graph_->labels().end(); ++iter) {
81 if (
_graph_->nodes(iter.second()).size() >= 2) {
93 _edges_.push_back(iter.second());
104 for (
auto iter =
_nodes_.begin(); iter !=
_nodes_.end(); ++iter) {
106 new_labels->
insert(idx, *iter);
109 for (
auto iter =
_edges_.begin(); iter !=
_edges_.end(); ++iter) {
111 new_labels->
insert(idx, *iter);
116 _graph_->_labels_ = new_labels;
119 template <
typename GUM_SCALAR >
122 std::vector< gspan::Pattern* > stack;
123 stack.push_back(&pat);
142 const std::list< NodeId >* children = 0;
144 while (!stack.empty()) {
151 std::list< NodeId > r_path;
156 std::vector< HashTable< std::string, gspan::EdgeGrowth< GUM_SCALAR >* >* > count_vector;
158 for (
size_t i = 0; i < r_path.size(); ++i)
159 count_vector.push_back(
165 for (
const auto iso_node:
_tree_.iso_graph(*p).nodes()) {
166 seq = &(
_tree_.iso_map(*p, iso_node));
169 for (
const auto node: r_path) {
170 edge_count = count_vector[idx];
172 current = seq->
atPos((
Idx)(node - 1));
173 current_id = ig.
id(current);
177 neighbor = ig.
node(neighbor_id).n;
182 if ((!seq->
exists(neighbor)) || (node == r_path.back())) {
186 edge_data = &(ig.
edge(current_id, neighbor_id));
187 neighbor_label = (neighbor == edge_data->
u) ? edge_data->
l_u : edge_data->
l_v;
188 neighbor_node = (seq->
exists(neighbor)) ? seq->
pos(neighbor) + 1 : 0;
196 edge_growth = (*edge_count)[temp_growth.
toString()];
197 edge_growth->
insert(current, neighbor);
203 edge_growth->
insert(current, neighbor);
212 for (
size_t node = 0; node < count_vector.size(); ++node) {
213 edge_count = count_vector[node];
215 for (
const auto& elt: *edge_count) {
217 _tree_.growPattern(*p, *elt.second, 2);
229 children = &(
_tree_.children(*p));
231 for (std::list< NodeId >::const_reverse_iterator child = children->rbegin();
232 child != children->rend();
234 stack.push_back(&(
_tree_.pattern(*child)));
239 template <
typename GUM_SCALAR >
242 std::vector< NodeId > stack;
244 for (std::list< NodeId >::reverse_iterator root =
tree().roots().rbegin();
245 root !=
tree().roots().rend();
247 stack.push_back(*root);
250 std::list< NodeId >* children =
nullptr;
252 while (!stack.empty()) {
256 children = &(
tree().children(
tree().pattern(
id)));
258 for (std::list< NodeId >::reverse_iterator child = children->rbegin();
259 child != children->rend();
261 stack.push_back(*child);
275 for (
const auto node:
tree().max_indep_set(*(
_patterns_.front()))) {
278 for (
const auto i: *match)
291 std::vector< NodeId > degree_list;
292 iso_graph = &(
tree().iso_graph(**patt));
294 for (
const auto node: iso_graph->
nodes()) {
296 match = &(
tree().iso_map(**patt, node));
298 for (
const auto i: *match)
311 for (
const auto iso: reduced_iso_graph.
nodes())
314 degree_list.push_back(node);
323 std::sort(degree_list.begin(), degree_list.end(), my_sort);
326 for (
const auto node: degree_list)
327 if (!removed.
exists(node)) {
332 for (
const auto neighbor: reduced_iso_graph.
neighbours(node))
337 match = &(
tree().iso_map(**patt, node));
340 for (
const auto elt: *match)
348 std::vector< size_t > trash;
350 for (
size_t idx = 0; idx <
_patterns_.size(); ++idx)
353 while (trash.size()) {
364 template <
typename GUM_SCALAR >
370 GUM_CONSTRUCTOR(
GSpan);
373 template <
typename GUM_SCALAR >
375 GUM_DESTRUCTOR(
GSpan);
383 template <
typename GUM_SCALAR >
388 template <
typename GUM_SCALAR >
393 template <
typename GUM_SCALAR >
398 template <
typename GUM_SCALAR >
403 template <
typename GUM_SCALAR >
405 return Idx(interface_size * frequency);
408 template <
typename GUM_SCALAR >
413 template <
typename GUM_SCALAR >
418 template <
typename GUM_SCALAR >
424 template <
typename GUM_SCALAR >
430 template <
typename GUM_SCALAR >
435 template <
typename GUM_SCALAR >
440 template <
typename GUM_SCALAR >
448 template <
typename GUM_SCALAR >
453 template <
typename GUM_SCALAR >
459 template <
typename GUM_SCALAR >
464 template <
typename GUM_SCALAR >
469 return gspan->_tree_.strategy()(i, j);
474 template <
typename GUM_SCALAR >
479 template <
typename GUM_SCALAR >
485 template <
typename GUM_SCALAR >
490 template <
typename GUM_SCALAR >
493 return gspan->tree().strategy().operator()(i, j);
void insert(const T1 &first, const T2 &second)
Inserts a new association in the gum::Bijection.
Set of pairs of elements with fast search for both elements.
virtual void eraseEdge(const Edge &edge)
removes an edge from the EdgeGraphPart
bool existsEdge(const Edge &edge) const
indicates whether a given edge exists
const NodeSet & neighbours(NodeId id) const
returns the set of node neighbours to a given node
The base class for all undirected edges.
The class for generic Hash Tables.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
Exception : the element we looked for cannot be found.
Exception : operation not allowed.
bool exists(const Key &k) const
Check the existence of k in the sequence.
const Key & atPos(Idx i) const
Returns the object at the pos i.
Idx pos(const Key &key) const
Returns the position of the object passed in argument (if it exists).
The generic class for storing (ordered) sequences of objects.
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
void insert(const Key &k)
Inserts a new element into the set.
Class used to compute response times for benchmark purposes.
Base class for undirected graphs.
void addEdge(NodeId first, NodeId second) override
insert a new edge into the undirected graph
void discoverPatterns()
This will methods will discover repeated patterns in the PRMSystem<GUM_SCALAR> assigned to this class...
HashTable< gspan::Pattern *, MatchedInstances * > _matched_instances_
Mapping between a pattern and the multiset of instances matched to it.
std::vector< gspan::LabelData * > _nodes_
The vector of nodes in graph, in decreasing order of interest.
std::vector< gspan::Pattern * > _patterns_
The vector of discovered patters, in decreasing order of interest.
HashTable< gspan::LabelData *, Idx > _cost_
Mapping between labels and their cost.
MatchedInstances & matches(const gspan::Pattern &p)
Returns a mapping between patterns and the sequence of instance in the interface graph matching them.
std::vector< gspan::Pattern * > & patterns()
Returns the Pattern mined by this class in a decreasing order of interest.
gspan::InterfaceGraph< GUM_SCALAR > * _graph_
The interface graph used by this class.
void setMaxDFSDepth(Size depth)
Defines the maximal depth of the DFSTree used by this class to discover new patterns.
gspan::DFSTree< GUM_SCALAR > _tree_
The DFSTree used to discover new patters.
Set< PRMInstance< GUM_SCALAR > * > _chosen_
Contains all instance which belongs to a discovered and used pattern.
void _subgraph_mining_(gspan::InterfaceGraph< GUM_SCALAR > &graph, gspan::Pattern &p)
Discovers new patterns by developing p.
std::vector< gspan::LabelData * > _edges_
The vector of edges in graph, in decreasing order of interest.
GSpan(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &sys, gspan::SearchStrategy< GUM_SCALAR > *strategy=0)
Default constructor.
Size getMaxDFSDepth() const
Returns the maximal depth of the DFSTree used to discover new patterns.
gspan::DFSTree< GUM_SCALAR > & tree()
Returns the DFSTree used to discover new patters.
gspan::InterfaceGraph< GUM_SCALAR > & interfaceGraph()
Returns the InterfaceGraph used by this.
Set< Sequence< PRMInstance< GUM_SCALAR > * > * > MatchedInstances
Code alias.
bool _isEdgeEligible_(typename gspan::EdgeData< GUM_SCALAR > *e)
Returns true if e is an eligible root edge.
Size _depth_stop_
The max depth allowed for the DSF tree.
void _sortNodesAndEdges_()
Sort the nodes and edges of graph.
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.
An PRMInstance is a Bayesian network fragment defined by a Class and used in a PRMSystem.
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
std::vector< EdgeCode * > codes
The vector containing the EdgeCode composing this DFSCode.
A DFSTree is used by gspan to sort lexicographically patterns discovered in an interface graph.
Inner class to handle data about edges in graph.
PRMInstance< GUM_SCALAR > * u
One of the two instance represented by this edge.
LabelData * l_u
The label data of u.
LabelData * l
The labal data of this edge.
LabelData * l_v
The label data of v.
This class is used to define an edge growth of a pattern in this DFSTree.
std::string toString()
Return a string representation of this.
void insert(PRMInstance< GUM_SCALAR > *u, PRMInstance< GUM_SCALAR > *v)
Add the pair (u,v) as a match for the current growth.
This class represent the interface graph of a given gum::prm::PRMSystem<GUM_SCALAR>.
NodeId id(const PRMInstance< GUM_SCALAR > &i) const
Returns the id of i in this interface graph.
EdgeData< GUM_SCALAR > & edge(NodeId u, NodeId v)
Returns data about an edge.
UndiGraph & graph()
Returns the graph of this interface graph.
NodeData< GUM_SCALAR > & node(const PRMInstance< GUM_SCALAR > *i)
Returns data about a node.
This contains all the information we want for a node in a DFSTree.
void rightmostPath(std::list< NodeId > &r_path) const
Fill r_path with the rightmost path of this Pattern. The list is supposed empty.
DFSCode & code()
Returns the DFSCode of this Pattern.
This is an abstract class used to tune search strategies in the gspan algorithm.
Headers of the DFSTree class.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
Size NodeId
Type for node ids.
namespace for all probabilistic relational models entities
gum is the global namespace for all aGrUM entities
Private class used to sort LabelData using STL sort algorithms.
LabelSort(GSpan *my_gspan)
Default constructor.
GSpan * gspan
A pointer over an instance of the GSpan class using this class.
bool operator()(gspan::LabelData *i, gspan::LabelData *j)
Returns true if i's cost is lesser than j's.
Private class used to sort Pattern using STL sort algorithms.
bool operator()(gspan::Pattern *i, gspan::Pattern *j)
Returns true if i's cost is lesser than j's.
~PatternSort()
Destructor.
GSpan * gspan
A pointer over an instance of the GSpan class using this class.
PatternSort(GSpan *my_gspan)
Default constructor.
This is used to generate the max_indep_set of a Pattern.
Inner class to handle data about labels in this interface graph.