Main MRPT website > C++ reference for MRPT 1.9.9
CGraphPartitioner.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef CGRAPHPARTITIONER_H
10 #define CGRAPHPARTITIONER_H
11 
12 #include <mrpt/utils/utils_defs.h>
14 #include <mrpt/math/CMatrix.h>
15 #include <mrpt/math/ops_matrices.h>
16 
17 namespace mrpt
18 {
19 /** Abstract graph and tree data structures, plus generic graph algorithms
20  * \ingroup mrpt_graphs_grp
21  */
22 namespace graphs
23 {
24 /** Algorithms for finding the min-normalized-cut of a weighted undirected
25  * graph.
26  * Two methods are provided, one for bisection and the other for
27  * iterative N-parts partition.
28  * It is an implementation of the Shi-Malik method proposed in:<br><br>
29  * <code>J. Shi and J. Malik, "Normalized Cuts and Image Segmentation,"IEEE
30  * Transactions on Pattern Analysis and Machine Intelligence, vol.22, no.8, pp.
31  * 888-905, Aug. 2000.</code><br>
32  *
33  * \tparam GRAPH_MATRIX The type of square matrices used to represent the
34  * connectivity in a graph (e.g. mrpt::math::CMatrix)
35  * \tparam num_t The type of matrix elements, thresholds, etc. (typ: float or
36  * double). Defaults to the type of matrix elements.
37  *
38  * \note Prior to MRPT 1.0.0 this class wasn't a template and provided static
39  * variables for debugging, which were removed since that version.
40  */
41 template <class GRAPH_MATRIX, typename num_t = typename GRAPH_MATRIX::Scalar>
42 class CGraphPartitioner : public mrpt::utils::COutputLogger
43 {
44  public:
45  /** Performs the spectral recursive partition into K-parts for a given
46  * graph.
47  * The default threshold for the N-cut is 1, which correspond to a cut
48  * equal
49  * of the geometric mean of self-associations of each pair of groups.
50  *
51  * \param in_A [IN] The weights matrix for the graph. It must be a
52  * square
53  * matrix, where element W<sub>ij</sub> is the "likelihood" between nodes
54  * "i" and "j", and typically W<sub>ii</sub> = 1.
55  * \param out_parts [OUT] An array of partitions, where each partition
56  * is
57  * represented as a vector of indexs for nodes.
58  * \param threshold_Ncut [IN] If it is desired to use other than the default
59  * threshold, it can be passed here.
60  * \param forceSimetry [IN] If set to true (default) the elements
61  * W<sub>ij</sub> and W<sub>ji</sub> are replaced by
62  * 0.5*(W<sub>ij</sub>+W<sub>ji</sub>). Set to false if matrix is known to
63  * be simetric.
64  * \param useSpectralBisection [IN] If set to true (default) a quick
65  * spectral bisection will be used. If set to false, a brute force, exact
66  * finding of the min-cut is performed.
67  * \param recursive [IN] Default=true, recursive algorithm for finding N
68  * partitions. Set to false to force 1 bisection as maximum.
69  * \param minSizeClusters [IN] Default=1, Minimum size of partitions to be
70  * accepted.
71  *
72  * \sa mrpt::math::CMatrix, SpectralBisection
73  *
74  * \exception Throws a std::logic_error if an invalid matrix is passed.
75  */
76  static void RecursiveSpectralPartition(
77  GRAPH_MATRIX& in_A, std::vector<vector_uint>& out_parts,
78  num_t threshold_Ncut = 1, bool forceSimetry = true,
79  bool useSpectralBisection = true, bool recursive = true,
80  unsigned minSizeClusters = 1, const bool verbose = false);
81 
82  /** Performs the spectral bisection of a graph. This method always perform
83  * the bisection, and a measure of the goodness for this cut is returned.
84  *
85  * \param in_A [IN] The weights matrix for the graph. It must be a
86  * square
87  * matrix, where element W<sub>ij</sub> is the "likelihood" between nodes
88  * "i" and "j", and typically W<sub>ii</sub> = 1.
89  * \param out_part1 [OUT] The indexs of the nodes that fall into the
90  * first
91  * group.
92  * \param out_part2 [OUT] The indexs of the nodes that fall into the
93  * second
94  * group.
95  * \param out_cut_value [OUT] The N-cut value for the proposed cut, in the
96  * range [0-2].
97  * \param forceSimetry [IN] If set to true (default) the elements
98  * W<sub>ij</sub> and W<sub>ji</sub> are replaced by
99  * 0.5*(W<sub>ij</sub>+W<sub>ji</sub>). Set to false if matrix is known to
100  * be simetric.
101  *
102  * \sa mrpt::math::CMatrix, RecursiveSpectralPartition
103  *
104  * \exception Throws a std::logic_error if an invalid matrix is passed.
105  */
106  static void SpectralBisection(
107  GRAPH_MATRIX& in_A, vector_uint& out_part1, vector_uint& out_part2,
108  num_t& out_cut_value, bool forceSimetry = true);
109 
110  /** Performs an EXACT minimum n-Cut graph bisection, (Use
111  * CGraphPartitioner::SpectralBisection for a faster algorithm)
112  *
113  * \param in_A [IN] The weights matrix for the graph. It must be a
114  * square
115  * matrix, where element W<sub>ij</sub> is the "likelihood" between nodes
116  * "i" and "j", and typically W<sub>ii</sub> = 1.
117  * \param out_part1 [OUT] The indexs of the nodes that fall into the
118  * first
119  * group.
120  * \param out_part2 [OUT] The indexs of the nodes that fall into the
121  * second
122  * group.
123  * \param out_cut_value [OUT] The N-cut value for the proposed cut, in the
124  * range [0-2].
125  * \param forceSimetry [IN] If set to true (default) the elements
126  * W<sub>ij</sub> and W<sub>ji</sub> are replaced by
127  * 0.5*(W<sub>ij</sub>+W<sub>ji</sub>). Set to false if matrix is known to
128  * be simetric.
129  *
130  * \sa mrpt::math::CMatrix, RecursiveSpectralPartition
131  *
132  * \exception Throws a std::logic_error if an invalid matrix is passed.
133  */
134  static void exactBisection(
135  GRAPH_MATRIX& in_A, vector_uint& out_part1, vector_uint& out_part2,
136  num_t& out_cut_value, bool forceSimetry = true);
137 
138  /** Returns the normaliced cut of a graph, given its adjacency matrix A and
139  * a bisection:
140  */
141  static num_t nCut(
142  const GRAPH_MATRIX& in_A, const vector_uint& in_part1,
143  const vector_uint& in_part2);
144 
145 }; // End of class def.
146 
147 } // End of namespace
148 } // End of namespace
149 
150 // Template implementation:
151 #include "CGraphPartitioner_impl.h"
152 
153 #endif
std::vector< uint32_t > vector_uint
Definition: types_simple.h:29
static void RecursiveSpectralPartition(GRAPH_MATRIX &in_A, std::vector< vector_uint > &out_parts, num_t threshold_Ncut=1, bool forceSimetry=true, bool useSpectralBisection=true, bool recursive=true, unsigned minSizeClusters=1, const bool verbose=false)
Performs the spectral recursive partition into K-parts for a given graph.
This file implements miscelaneous matrix and matrix/vector operations, and internal functions in mrpt...
static void SpectralBisection(GRAPH_MATRIX &in_A, vector_uint &out_part1, vector_uint &out_part2, num_t &out_cut_value, bool forceSimetry=true)
Performs the spectral bisection of a graph.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
static void exactBisection(GRAPH_MATRIX &in_A, vector_uint &out_part1, vector_uint &out_part2, num_t &out_cut_value, bool forceSimetry=true)
Performs an EXACT minimum n-Cut graph bisection, (Use CGraphPartitioner::SpectralBisection for a fast...
static num_t nCut(const GRAPH_MATRIX &in_A, const vector_uint &in_part1, const vector_uint &in_part2)
Returns the normaliced cut of a graph, given its adjacency matrix A and a bisection: ...
Algorithms for finding the min-normalized-cut of a weighted undirected graph.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019