aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gspan.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
48
49#ifndef GUM_GSPAN_H
50#define GUM_GSPAN_H
51
52#include <algorithm>
53#include <list>
54#include <ostream>
55#include <string>
56#include <vector>
57
61
62namespace gum {
63 namespace prm {
64
85 template < typename GUM_SCALAR >
86 class GSpan {
87 public:
88 // ========================================================================
90 // ========================================================================
92
102 const PRMSystem< GUM_SCALAR >& sys,
104
106 ~GSpan();
107
109 // ========================================================================
111 // ========================================================================
113
119 Size getMaxDFSDepth() const;
120
127 void setMaxDFSDepth(Size depth);
128
134
139 const gspan::DFSTree< GUM_SCALAR >& tree() const;
140
146
152
154 // ========================================================================
156 // ========================================================================
158
166 void discoverPatterns();
167
174 std::vector< gspan::Pattern* >& patterns();
175
182 const std::vector< gspan::Pattern* >& patterns() const;
183
186
194
201 const MatchedInstances& matches(const gspan::Pattern& p) const;
202
203 // /**
204 // * Returns the cumulative sum of all the cliques size created after
205 // lifting
206 // * the patterns.
207 // * @returns the cumulative sum of all the cliques size created after
208 // lifting
209 // * the patterns.
210 // */
211 // double patterns_cost() const;
212
213 // /**
214 // * Returns the cumulative sum of all the cliques size created after
215 // lifting
216 // * the inner attributes.
217 // * @returns the cumulative sum of all the cliques size created after
218 // lifting
219 // * the inner attributes.
220 // */
221 // double sve_cost() const;
222
224
225 private:
226 // ========================================================================
228 // ========================================================================
230
233
236
239
241 std::vector< gspan::Pattern* > _patterns_;
242
244 std::vector< gspan::LabelData* > _nodes_;
245
247 std::vector< gspan::LabelData* > _edges_;
248
251
255
258
260 // ========================================================================
262 // ========================================================================
264
266 void _sortNodesAndEdges_();
267
272
278 Size _cost_func_(Size interface_size, Size frequency);
279
281 void _sortPatterns_();
282
287
289
290 // ========================================================================
292 // ========================================================================
294
300 struct LabelSort {
305 LabelSort(GSpan* my_gspan);
306
311 LabelSort(const LabelSort& source);
312
316 ~LabelSort();
317
325
328 };
329
335 struct PatternSort {
340 PatternSort(GSpan* my_gspan);
341
346 PatternSort(const PatternSort& source);
347
351 ~PatternSort();
352
360
363 };
364
366 };
367
368
369#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
370 extern template class GSpan< double >;
371#endif
372
373
374 } /* namespace prm */
375} /* namespace gum */
376
378
379#endif /* GUM_GSPAN_H */
Headers of the DFSTree class.
The class for generic Hash Tables.
Definition hashTable.h:637
Representation of a set.
Definition set.h:131
This class discovers pattern in a PRM<GUM_SCALAR>'s PRMSystem<GUM_SCALAR> to speed up structured infe...
Definition gspan.h:86
void discoverPatterns()
This will methods will discover repeated patterns in the PRMSystem<GUM_SCALAR> assigned to this class...
Definition gspan_tpl.h:56
HashTable< gspan::Pattern *, MatchedInstances * > _matched_instances_
Mapping between a pattern and the multiset of instances matched to it.
Definition gspan.h:254
std::vector< gspan::LabelData * > _nodes_
The vector of nodes in graph, in decreasing order of interest.
Definition gspan.h:244
std::vector< gspan::Pattern * > _patterns_
The vector of discovered patters, in decreasing order of interest.
Definition gspan.h:241
~GSpan()
Destructor.
Definition gspan_tpl.h:374
HashTable< gspan::LabelData *, Idx > _cost_
Mapping between labels and their cost.
Definition gspan.h:250
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:420
std::vector< gspan::Pattern * > & patterns()
Returns the Pattern mined by this class in a decreasing order of interest.
Definition gspan_tpl.h:409
gspan::InterfaceGraph< GUM_SCALAR > * _graph_
The interface graph used by this class.
Definition gspan.h:232
void setMaxDFSDepth(Size depth)
Defines the maximal depth of the DFSTree used by this class to discover new patterns.
Definition gspan_tpl.h:389
gspan::DFSTree< GUM_SCALAR > _tree_
The DFSTree used to discover new patters.
Definition gspan.h:235
Set< PRMInstance< GUM_SCALAR > * > _chosen_
Contains all instance which belongs to a discovered and used pattern.
Definition gspan.h:257
void _subgraph_mining_(gspan::InterfaceGraph< GUM_SCALAR > &graph, gspan::Pattern &p)
Discovers new patterns by developing p.
Definition gspan_tpl.h:120
std::vector< gspan::LabelData * > _edges_
The vector of edges in graph, in decreasing order of interest.
Definition gspan.h:247
GSpan(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &sys, gspan::SearchStrategy< GUM_SCALAR > *strategy=0)
Default constructor.
Definition gspan_tpl.h:365
Size getMaxDFSDepth() const
Returns the maximal depth of the DFSTree used to discover new patterns.
Definition gspan_tpl.h:384
gspan::DFSTree< GUM_SCALAR > & tree()
Returns the DFSTree used to discover new patters.
Definition gspan_tpl.h:394
gspan::InterfaceGraph< GUM_SCALAR > & interfaceGraph()
Returns the InterfaceGraph used by this.
Definition gspan_tpl.h:431
Set< Sequence< PRMInstance< GUM_SCALAR > * > * > MatchedInstances
Code alias.
Definition gspan.h:185
bool _isEdgeEligible_(typename gspan::EdgeData< GUM_SCALAR > *e)
Returns true if e is an eligible root edge.
Definition gspan_tpl.h:441
Size _depth_stop_
The max depth allowed for the DSF tree.
Definition gspan.h:238
void _sortNodesAndEdges_()
Sort the nodes and edges of graph.
Definition gspan_tpl.h:78
Size _cost_func_(Size interface_size, Size frequency)
Returns the cost with respect to an interface size and its frequency.
Definition gspan_tpl.h:404
void _sortPatterns_()
Sort the patterns and compute their respective costs.
Definition gspan_tpl.h:240
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
Definition PRMSystem.h:70
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
Definition PRM.h:74
A DFSTree is used by gspan to sort lexicographically patterns discovered in an interface graph.
Definition DFSTree.h:77
Inner class to handle data about edges in graph.
This class represent the interface graph of a given gum::prm::PRMSystem<GUM_SCALAR>.
This contains all the information we want for a node in a DFSTree.
Definition pattern.h:90
This is an abstract class used to tune search strategies in the gspan algorithm.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Inline implementation of gspan.
namespace for all probabilistic relational models entities
Definition agrum.h:68
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
LabelSort(GSpan *my_gspan)
Default constructor.
Definition gspan_tpl.h:449
GSpan * gspan
A pointer over an instance of the GSpan class using this class.
Definition gspan.h:327
bool operator()(gspan::LabelData *i, gspan::LabelData *j)
Returns true if i's cost is lesser than j's.
Definition gspan_tpl.h:465
bool operator()(gspan::Pattern *i, gspan::Pattern *j)
Returns true if i's cost is lesser than j's.
Definition gspan_tpl.h:491
GSpan * gspan
A pointer over an instance of the GSpan class using this class.
Definition gspan.h:362
PatternSort(GSpan *my_gspan)
Default constructor.
Definition gspan_tpl.h:475
Inner class to handle data about labels in this interface graph.
Class used to compute response times for benchmark purposes.
Implementation of a variable elimination algorithm for inference in Bayesian networks.