File: igraph_community.h

package info (click to toggle)
igraph 0.10.2%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 16,176 kB
  • sloc: ansic: 121,500; cpp: 21,699; xml: 2,734; python: 411; makefile: 147; javascript: 20; sh: 9
file content (253 lines) | stat: -rw-r--r-- 14,399 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/* -*- mode: C -*-  */
/*
   IGraph library.
   Copyright (C) 2009-2012  Gabor Csardi <csardi.gabor@gmail.com>
   334 Harvard street, Cambridge, MA 02139 USA

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc.,  51 Franklin Street, Fifth Floor, Boston, MA
   02110-1301 USA

*/

#ifndef IGRAPH_COMMUNITY_H
#define IGRAPH_COMMUNITY_H

#include "igraph_decls.h"

#include "igraph_arpack.h"
#include "igraph_constants.h"
#include "igraph_datatype.h"
#include "igraph_error.h"
#include "igraph_types.h"
#include "igraph_vector_list.h"

__BEGIN_DECLS

/* -------------------------------------------------- */
/* K-Cores and K-Truss                                */
/* -------------------------------------------------- */

IGRAPH_EXPORT igraph_error_t igraph_coreness(
    const igraph_t *graph, igraph_vector_int_t *cores, igraph_neimode_t mode);
IGRAPH_EXPORT igraph_error_t igraph_trussness(
    const igraph_t* graph, igraph_vector_int_t* trussness);

/* -------------------------------------------------- */
/* Community Structure                                */
/* -------------------------------------------------- */

/* TODO: cut.community */
/* TODO: edge.type.matrix */
/* TODO:  */

IGRAPH_EXPORT igraph_error_t igraph_community_optimal_modularity(const igraph_t *graph,
                                                      igraph_real_t *modularity,
                                                      igraph_vector_int_t *membership,
                                                      const igraph_vector_t *weights);

IGRAPH_EXPORT igraph_error_t igraph_community_spinglass(const igraph_t *graph,
                                             const igraph_vector_t *weights,
                                             igraph_real_t *modularity,
                                             igraph_real_t *temperature,
                                             igraph_vector_int_t *membership,
                                             igraph_vector_int_t *csize,
                                             igraph_integer_t spins,
                                             igraph_bool_t parupdate,
                                             igraph_real_t starttemp,
                                             igraph_real_t stoptemp,
                                             igraph_real_t coolfact,
                                             igraph_spincomm_update_t update_rule,
                                             igraph_real_t gamma,
                                             igraph_spinglass_implementation_t implementation,
                                             igraph_real_t gamma_minus);

IGRAPH_EXPORT igraph_error_t igraph_community_spinglass_single(const igraph_t *graph,
                                                    const igraph_vector_t *weights,
                                                    igraph_integer_t vertex,
                                                    igraph_vector_int_t *community,
                                                    igraph_real_t *cohesion,
                                                    igraph_real_t *adhesion,
                                                    igraph_integer_t *inner_links,
                                                    igraph_integer_t *outer_links,
                                                    igraph_integer_t spins,
                                                    igraph_spincomm_update_t update_rule,
                                                    igraph_real_t gamma);

IGRAPH_EXPORT igraph_error_t igraph_community_walktrap(const igraph_t *graph,
                                            const igraph_vector_t *weights,
                                            igraph_integer_t steps,
                                            igraph_matrix_int_t *merges,
                                            igraph_vector_t *modularity,
                                            igraph_vector_int_t *membership);

IGRAPH_EXPORT igraph_error_t igraph_community_infomap(const igraph_t * graph,
                                           const igraph_vector_t *e_weights,
                                           const igraph_vector_t *v_weights,
                                           igraph_integer_t nb_trials,
                                           igraph_vector_int_t *membership,
                                           igraph_real_t *codelength);

IGRAPH_EXPORT igraph_error_t igraph_community_edge_betweenness(const igraph_t *graph,
                                                    igraph_vector_int_t *result,
                                                    igraph_vector_t *edge_betweenness,
                                                    igraph_matrix_int_t *merges,
                                                    igraph_vector_int_t *bridges,
                                                    igraph_vector_t *modularity,
                                                    igraph_vector_int_t *membership,
                                                    igraph_bool_t directed,
                                                    const igraph_vector_t *weights);
IGRAPH_EXPORT igraph_error_t igraph_community_eb_get_merges(const igraph_t *graph,
                                                 const igraph_bool_t directed,
                                                 const igraph_vector_int_t *edges,
                                                 const igraph_vector_t *weights,
                                                 igraph_matrix_int_t *merges,
                                                 igraph_vector_int_t *bridges,
                                                 igraph_vector_t *modularity,
                                                 igraph_vector_int_t *membership);

IGRAPH_EXPORT igraph_error_t igraph_community_fastgreedy(const igraph_t *graph,
                                              const igraph_vector_t *weights,
                                              igraph_matrix_int_t *merges,
                                              igraph_vector_t *modularity,
                                              igraph_vector_int_t *membership);

IGRAPH_EXPORT igraph_error_t igraph_community_to_membership(const igraph_matrix_int_t *merges,
                                                 igraph_integer_t nodes,
                                                 igraph_integer_t steps,
                                                 igraph_vector_int_t *membership,
                                                 igraph_vector_int_t *csize);
IGRAPH_EXPORT igraph_error_t igraph_le_community_to_membership(const igraph_matrix_int_t *merges,
                                                    igraph_integer_t steps,
                                                    igraph_vector_int_t *membership,
                                                    igraph_vector_int_t *csize);

IGRAPH_EXPORT igraph_error_t igraph_modularity(const igraph_t *graph,
                                    const igraph_vector_int_t *membership,
                                    const igraph_vector_t *weights,
                                    const igraph_real_t resolution,
                                    const igraph_bool_t directed,
                                    igraph_real_t *modularity);

IGRAPH_EXPORT igraph_error_t igraph_modularity_matrix(const igraph_t *graph,
                                           const igraph_vector_t *weights,
                                           const igraph_real_t resolution,
                                           igraph_matrix_t *modmat,
                                           igraph_bool_t directed);

IGRAPH_EXPORT igraph_error_t igraph_reindex_membership(igraph_vector_int_t *membership,
                                            igraph_vector_int_t *new_to_old,
                                            igraph_integer_t *nb_clusters);

typedef enum { IGRAPH_LEVC_HIST_SPLIT = 1,
               IGRAPH_LEVC_HIST_FAILED,
               IGRAPH_LEVC_HIST_START_FULL,
               IGRAPH_LEVC_HIST_START_GIVEN
             } igraph_leading_eigenvector_community_history_t;

/**
 * \typedef igraph_community_leading_eigenvector_callback_t
 * Callback for the leading eigenvector community finding method.
 *
 * The leading eigenvector community finding implementation in igraph
 * is able to call a callback function, after each eigenvalue
 * calculation. This callback function must be of \c
 * igraph_community_leading_eigenvector_callback_t type.
 * The following arguments are passed to the callback:
 * \param membership The actual membership vector, before recording
 *    the potential change implied by the newly found eigenvalue.
 * \param comm The id of the community that the algorithm tried to
 *    split in the last iteration. The community IDs are indexed from
 *    zero here!
 * \param eigenvalue The eigenvalue the algorithm has just found.
 * \param eigenvector The eigenvector corresponding to the eigenvalue
 *    the algorithm just found.
 * \param arpack_multiplier A function that was passed to \ref
 *    igraph_arpack_rssolve() to solve the last eigenproblem.
 * \param arpack_extra The extra argument that was passed to the
 *    ARPACK solver.
 * \param extra Extra argument that as passed to \ref
 *    igraph_community_leading_eigenvector().
 *
 * \sa \ref igraph_community_leading_eigenvector(), \ref
 * igraph_arpack_function_t, \ref igraph_arpack_rssolve().
 */

typedef igraph_error_t igraph_community_leading_eigenvector_callback_t(
    const igraph_vector_int_t *membership,
    igraph_integer_t comm,
    igraph_real_t eigenvalue,
    const igraph_vector_t *eigenvector,
    igraph_arpack_function_t *arpack_multiplier,
    void *arpack_extra,
    void *extra);

IGRAPH_EXPORT igraph_error_t igraph_community_leading_eigenvector(const igraph_t *graph,
                                                       const igraph_vector_t *weights,
                                                       igraph_matrix_int_t *merges,
                                                       igraph_vector_int_t *membership,
                                                       igraph_integer_t steps,
                                                       igraph_arpack_options_t *options,
                                                       igraph_real_t *modularity,
                                                       igraph_bool_t start,
                                                       igraph_vector_t *eigenvalues,
                                                       igraph_vector_list_t *eigenvectors,
                                                       igraph_vector_t *history,
                                                       igraph_community_leading_eigenvector_callback_t *callback,
                                                       void *callback_extra);

IGRAPH_EXPORT igraph_error_t igraph_community_fluid_communities(const igraph_t *graph,
                                                     igraph_integer_t no_of_communities,
                                                     igraph_vector_int_t *membership);

IGRAPH_EXPORT igraph_error_t igraph_community_label_propagation(const igraph_t *graph,
                                                     igraph_vector_int_t *membership,
                                                     igraph_neimode_t mode,
                                                     const igraph_vector_t *weights,
                                                     const igraph_vector_int_t *initial,
                                                     const igraph_vector_bool_t *fixed);

IGRAPH_EXPORT igraph_error_t igraph_community_multilevel(const igraph_t *graph,
                                              const igraph_vector_t *weights,
                                              const igraph_real_t resolution,
                                              igraph_vector_int_t *membership,
                                              igraph_matrix_int_t *memberships,
                                              igraph_vector_t *modularity);

IGRAPH_EXPORT igraph_error_t igraph_community_leiden(const igraph_t *graph,
                                          const igraph_vector_t *edge_weights,
                                          const igraph_vector_t *node_weights,
                                          const igraph_real_t resolution_parameter,
                                          const igraph_real_t beta,
                                          const igraph_bool_t start,
                                          const igraph_integer_t n_iterations,
                                          igraph_vector_int_t *membership,
                                          igraph_integer_t *nb_clusters,
                                          igraph_real_t *quality);
/* -------------------------------------------------- */
/* Community Structure Comparison                     */
/* -------------------------------------------------- */

IGRAPH_EXPORT igraph_error_t igraph_compare_communities(const igraph_vector_int_t *comm1,
                                             const igraph_vector_int_t *comm2,
                                             igraph_real_t* result,
                                             igraph_community_comparison_t method);
IGRAPH_EXPORT igraph_error_t igraph_split_join_distance(const igraph_vector_int_t *comm1,
                                             const igraph_vector_int_t *comm2,
                                             igraph_integer_t* distance12,
                                             igraph_integer_t* distance21);

__END_DECLS

#endif