56 template < GUM_Numeric GUM_SCALAR >
62 for (
auto root =
_tree_.roots().begin(); root !=
_tree_.roots().end(); ++root) {
63 if (
_tree_.strategy().accept_root(&(
_tree_.pattern(*root)))) {
67 for (
const auto node:
_tree_.iso_graph(p).nodes()) {
78 template < GUM_Numeric GUM_SCALAR >
80 for (
auto iter =
_graph_->labels().begin(); iter !=
_graph_->labels().end(); ++iter) {
82 if (
_graph_->nodes(iter.second()).size() >= 2) {
94 _edges_.push_back(iter.second());
105 for (
auto iter =
_nodes_.begin(); iter !=
_nodes_.end(); ++iter) {
107 new_labels->
insert(idx, *iter);
110 for (
auto iter =
_edges_.begin(); iter !=
_edges_.end(); ++iter) {
112 new_labels->
insert(idx, *iter);
117 _graph_->_labels_ = new_labels;
120 template < GUM_Numeric GUM_SCALAR >
123 std::vector< gspan::Pattern* > stack;
124 stack.push_back(&pat);
143 const std::list< NodeId >* children = 0;
145 while (!stack.empty()) {
152 std::list< NodeId > r_path;
157 std::vector< HashTable< std::string, gspan::EdgeGrowth< GUM_SCALAR >* >* > count_vector;
159 for (
size_t i = 0; i < r_path.size(); ++i)
160 count_vector.push_back(
166 for (
const auto iso_node:
_tree_.iso_graph(*p).nodes()) {
167 seq = &(
_tree_.iso_map(*p, iso_node));
170 for (
const auto node: r_path) {
171 edge_count = count_vector[idx];
173 current = seq->
atPos((
Idx)(node - 1));
174 current_id = ig.
id(current);
178 neighbor = ig.
node(neighbor_id).n;
183 if ((!seq->
exists(neighbor)) || (node == r_path.back())) {
187 edge_data = &(ig.
edge(current_id, neighbor_id));
188 neighbor_label = (neighbor == edge_data->
u) ? edge_data->
l_u : edge_data->
l_v;
189 neighbor_node = (seq->
exists(neighbor)) ? seq->
pos(neighbor) + 1 : 0;
197 edge_growth = (*edge_count)[temp_growth.
toString()];
198 edge_growth->
insert(current, neighbor);
204 edge_growth->
insert(current, neighbor);
213 for (
size_t node = 0; node < count_vector.size(); ++node) {
214 edge_count = count_vector[node];
216 for (
const auto& elt: *edge_count) {
218 _tree_.growPattern(*p, *elt.second, 2);
230 children = &(
_tree_.children(*p));
232 for (std::list< NodeId >::const_reverse_iterator child = children->rbegin();
233 child != children->rend();
235 stack.push_back(&(
_tree_.pattern(*child)));
240 template < GUM_Numeric GUM_SCALAR >
243 std::vector< NodeId > stack;
245 for (std::list< NodeId >::reverse_iterator root =
tree().roots().rbegin();
246 root !=
tree().roots().rend();
248 stack.push_back(*root);
251 std::list< NodeId >* children =
nullptr;
253 while (!stack.empty()) {
257 children = &(
tree().children(
tree().pattern(
id)));
259 for (std::list< NodeId >::reverse_iterator child = children->rbegin();
260 child != children->rend();
262 stack.push_back(*child);
276 for (
const auto node:
tree().max_indep_set(*(
_patterns_.front()))) {
279 for (
const auto i: *match)
292 std::vector< NodeId > degree_list;
293 iso_graph = &(
tree().iso_graph(**patt));
295 for (
const auto node: iso_graph->
nodes()) {
297 match = &(
tree().iso_map(**patt, node));
299 for (
const auto i: *match)
312 for (
const auto iso: reduced_iso_graph.
nodes())
315 degree_list.push_back(node);
324 std::sort(degree_list.begin(), degree_list.end(), my_sort);
327 for (
const auto node: degree_list)
328 if (!removed.
exists(node)) {
333 for (
const auto neighbor: reduced_iso_graph.
neighbours(node))
338 match = &(
tree().iso_map(**patt, node));
341 for (
const auto elt: *match)
349 std::vector< size_t > trash;
351 for (
size_t idx = 0; idx <
_patterns_.size(); ++idx)
354 while (trash.size()) {
365 template < GUM_Numeric GUM_SCALAR >
371 GUM_CONSTRUCTOR(
GSpan);
374 template < GUM_Numeric GUM_SCALAR >
376 GUM_DESTRUCTOR(
GSpan);
384 template < GUM_Numeric GUM_SCALAR >
389 template < GUM_Numeric GUM_SCALAR >
394 template < GUM_Numeric GUM_SCALAR >
399 template < GUM_Numeric GUM_SCALAR >
404 template < GUM_Numeric GUM_SCALAR >
406 return Idx(interface_size * frequency);
409 template < GUM_Numeric GUM_SCALAR >
414 template < GUM_Numeric GUM_SCALAR >
419 template < GUM_Numeric GUM_SCALAR >
425 template < GUM_Numeric GUM_SCALAR >
431 template < GUM_Numeric GUM_SCALAR >
436 template < GUM_Numeric GUM_SCALAR >
441 template < GUM_Numeric GUM_SCALAR >
449 template < GUM_Numeric GUM_SCALAR >
454 template < GUM_Numeric GUM_SCALAR >
459 template < GUM_Numeric GUM_SCALAR >
464 template < GUM_Numeric GUM_SCALAR >
468 return gspan->_tree_.strategy()(i, j);
473 template < GUM_Numeric GUM_SCALAR >
478 template < GUM_Numeric GUM_SCALAR >
483 template < GUM_Numeric GUM_SCALAR >
488 template < GUM_Numeric GUM_SCALAR >
491 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.
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.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
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.
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).
bool exists(const Key &k) const
Check the existence of k in the sequence.
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.
void setMaxDFSDepth(Size depth)
Defines the maximal depth of the DFSTree used by this class to discover new patterns.
HashTable< gspan::LabelData *, Idx > _cost_
Mapping between labels and their cost.
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.
std::vector< gspan::Pattern * > & patterns()
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.
gspan::InterfaceGraph< GUM_SCALAR > * _graph_
The interface graph used by this class.
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.
Size _cost_func_(Size interface_size, Size frequency)
Returns the cost with respect to an interface size and its frequency.
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::InterfaceGraph< GUM_SCALAR > & interfaceGraph()
Returns the InterfaceGraph used by this.
Set< Sequence< PRMInstance< GUM_SCALAR > * > * > MatchedInstances
Code alias.
Size _depth_stop_
The max depth allowed for the DSF tree.
void _sortNodesAndEdges_()
Sort the nodes and edges of graph.
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.
GSpan(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &sys, gspan::SearchStrategy< GUM_SCALAR > *strategy=0)
Default constructor.
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>.
UndiGraph & internalGraph()
Returns the graph of this interface graph.
NodeData< GUM_SCALAR > & node(const PRMInstance< GUM_SCALAR > *i)
Returns data about a node.
EdgeData< GUM_SCALAR > & edge(NodeId u, NodeId v)
Returns data about an edge.
NodeId id(const PRMInstance< GUM_SCALAR > &i) const
Returns the id of i in this interface graph.
This contains all the information we want for a node in a DFSTree.
DFSCode & code()
Returns the DFSCode of this Pattern.
void rightmostPath(std::list< NodeId > &r_path) const
Fill r_path with the rightmost path of this Pattern. The list is supposed empty.
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.
bool operator()(gspan::LabelData *i, gspan::LabelData *j)
Returns true if i's cost is lesser than j's.
LabelSort(GSpan *my_gspan)
Default constructor.
GSpan * gspan
A pointer over an instance of the GSpan class using this class.
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.
GSpan * gspan
A pointer over an instance of the GSpan class using this class.
~PatternSort()
Destructor.
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.