Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
graph-tool
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
40
Issues
40
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tiago Peixoto
graph-tool
Commits
c153e0c0
Commit
c153e0c0
authored
Dec 01, 2008
by
Tiago Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Re-activate community detection code
This includes the community sub-module.
parent
6ba338ef
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
153 additions
and
101 deletions
+153
-101
configure.ac
configure.ac
+1
-0
src/graph/Makefile.am
src/graph/Makefile.am
+1
-1
src/graph/community/Makefile.am
src/graph/community/Makefile.am
+18
-0
src/graph/community/graph_community.cc
src/graph/community/graph_community.cc
+68
-95
src/graph/community/graph_community.hh
src/graph/community/graph_community.hh
+11
-5
src/graph_tool/Makefile.am
src/graph_tool/Makefile.am
+4
-0
src/graph_tool/all.py
src/graph_tool/all.py
+2
-0
src/graph_tool/community/__init__.py
src/graph_tool/community/__init__.py
+48
-0
No files found.
configure.ac
View file @
c153e0c0
...
@@ -273,6 +273,7 @@ src/graph/correlations/Makefile
...
@@ -273,6 +273,7 @@ src/graph/correlations/Makefile
src/graph/generation/Makefile
src/graph/generation/Makefile
src/graph/stats/Makefile
src/graph/stats/Makefile
src/graph/clustering/Makefile
src/graph/clustering/Makefile
src/graph/community/Makefile
src/graph/util/Makefile
src/graph/util/Makefile
src/graph/misc/Makefile
src/graph/misc/Makefile
src/graph_tool/Makefile
src/graph_tool/Makefile
...
...
src/graph/Makefile.am
View file @
c153e0c0
## Process this file with automake to produce Makefile.in
## Process this file with automake to produce Makefile.in
SUBDIRS
=
generation correlations stats clustering util misc
SUBDIRS
=
generation correlations stats clustering
community
util misc
AM_CPPFLAGS
=
\
AM_CPPFLAGS
=
\
-I
$(srcdir)
/..
\
-I
$(srcdir)
/..
\
...
...
src/graph/community/Makefile.am
0 → 100644
View file @
c153e0c0
## Process this file with automake to produce Makefile.in
AM_CPPFLAGS
=
$(MOD_CPPFLAGS)
AM_CFLAGS
=
$(AM_CXXFLAGS)
libgraph_tool_communitydir
=
$(pythondir)
/graph_tool/community
libgraph_tool_community_LTLIBRARIES
=
libgraph_tool_community.la
libgraph_tool_community_la_includedir
=
$(pythondir)
/graph_tool/include
libgraph_tool_community_la_LIBADD
=
$(MOD_LIBADD)
libgraph_tool_community_la_LDFLAGS
=
$(MOD_LDFLAGS)
libgraph_tool_community_la_SOURCES
=
\
graph_community.cc
src/graph/community/graph_community.cc
View file @
c153e0c0
...
@@ -22,125 +22,98 @@
...
@@ -22,125 +22,98 @@
#include <boost/lambda/bind.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/python.hpp>
#include "graph_community.hh"
#include "graph_community.hh"
using
namespace
std
;
using
namespace
std
;
using
namespace
boost
;
using
namespace
boost
;
using
namespace
boost
::
lambda
;
using
namespace
boost
::
lambda
;
using
namespace
graph_tool
;
using
namespace
graph_tool
;
void
GraphInterface
::
GetCommunityStructure
(
double
gamma
,
comm_corr_t
corr
,
size_t
n_iter
,
double
Tmin
,
void
community_structure
(
GraphInterface
&
g
,
double
gamma
,
string
corr_name
,
double
Tmax
,
size_t
Nspins
,
size_t
n_iter
,
double
Tmin
,
double
Tmax
,
size_t
Nspins
,
size_t
seed
,
bool
verbose
,
bool
new_spins
,
size_t
seed
,
bool
verbose
,
string
history_file
,
string
history_file
,
string
weight
,
boost
::
any
weight
,
boost
::
any
property
)
string
property
)
{
{
using
boost
::
lambda
::
bind
;
using
boost
::
lambda
::
_1
;
using
boost
::
lambda
::
_2
;
using
boost
::
lambda
::
_3
;
typedef
property_map_types
::
apply
<
mpl
::
vector
<
int32_t
,
int64_t
>
,
typedef
property_map_types
::
apply
<
mpl
::
vector
<
int32_t
,
int64_t
>
,
vertex_index_map_t
,
GraphInterface
::
vertex_index_map_t
,
mpl
::
bool_
<
false
>
>::
type
mpl
::
bool_
<
false
>
>::
type
allowed_spin_properties
;
allowed_spin_properties
;
boost
::
any
vertex_prop
;
if
(
!
belongs
<
allowed_spin_properties
>
()(
property
))
bool
new_spins
;
throw
GraphException
(
"vertex property is not of integer type int32_t "
try
"or int64_t"
);
{
find_property_map
(
_properties
,
property
,
typeid
(
vertex_t
));
typedef
DynamicPropertyMapWrap
<
double
,
GraphInterface
::
edge_t
>
weight_map_t
;
vertex_prop
=
prop
(
property
,
_vertex_index
,
_properties
);
typedef
ConstantPropertyMap
<
double
,
GraphInterface
::
edge_t
>
no_weight_map_t
;
if
(
!
belongs
<
allowed_spin_properties
>
()(
vertex_prop
))
throw
GraphException
(
"vertex property "
+
property
+
" is not of integer type int32_t or int64_t"
);
new_spins
=
false
;
}
catch
(
property_not_found
)
{
typedef
vector_property_map
<
int32_t
,
vertex_index_map_t
>
comm_map_t
;
comm_map_t
comm_map
(
_vertex_index
);
_properties
.
property
(
property
,
comm_map
);
vertex_prop
=
comm_map
;
new_spins
=
true
;
}
boost
::
any
edge_prop
;
typedef
DynamicPropertyMapWrap
<
double
,
edge_t
>
weight_map_t
;
typedef
ConstantPropertyMap
<
double
,
edge_t
>
no_weight_map_t
;
typedef
mpl
::
vector
<
weight_map_t
,
no_weight_map_t
>
weight_properties
;
typedef
mpl
::
vector
<
weight_map_t
,
no_weight_map_t
>
weight_properties
;
if
(
weight
!=
""
)
if
(
weight
.
empty
())
{
weight
=
no_weight_map_t
(
1.0
);
try
else
{
weight
=
weight_map_t
(
weight
,
edge_scalar_properties
());
weight_map_t
wrap
(
find_property_map
(
_properties
,
weight
,
typeid
(
edge_t
)));
comm_corr_t
corr
;
edge_prop
=
wrap
;
if
(
corr_name
==
"erdos"
)
}
corr
=
ERDOS_REYNI
;
catch
(
property_not_found
)
else
if
(
corr_name
==
"uncorrelated"
)
{
corr
=
UNCORRELATED
;
throw
GraphException
(
"edge property "
+
weight
+
" not found"
);
else
if
(
corr_name
==
"correlated"
)
}
corr
=
CORRELATED
;
}
else
else
{
throw
GraphException
(
"invalid correlation type: "
+
corr_name
);
edge_prop
=
no_weight_map_t
(
1.0
);
}
bool
directed
=
g
.
GetDirected
();
g
.
SetDirected
(
false
);
bool
directed
=
_directed
;
run_action
<
graph_tool
::
detail
::
never_directed
>
()
_directed
=
false
;
(
g
,
bind
<
void
>
(
get_communities_selector
(
corr
),
try
_1
,
_2
,
_3
,
gamma
,
n_iter
,
{
make_pair
(
Tmin
,
Tmax
),
run_action
<
detail
::
never_directed
>
()
make_pair
(
Nspins
,
new_spins
),
(
*
this
,
bind
<
void
>
(
get_communities_selector
(
corr
),
seed
,
make_pair
(
verbose
,
history_file
)),
_1
,
_2
,
_3
,
gamma
,
n_iter
,
weight_properties
(),
allowed_spin_properties
())
make_pair
(
Tmin
,
Tmax
),
(
weight
,
property
);
make_pair
(
Nspins
,
new_spins
),
g
.
SetDirected
(
directed
);
seed
,
make_pair
(
verbose
,
history_file
)),
weight_properties
(),
allowed_spin_properties
())
(
edge_prop
,
vertex_prop
);
}
catch
(
property_not_found
&
e
)
{
_directed
=
directed
;
throw
GraphException
(
"error getting scalar property: "
+
string
(
e
.
what
()));
}
_directed
=
directed
;
}
}
double
GraphInterface
::
GetModularity
(
string
weight
,
string
property
)
double
modularity
(
GraphInterface
&
g
,
boost
::
any
weight
,
boost
::
any
property
)
{
{
using
boost
::
lambda
::
bind
;
using
boost
::
lambda
::
_1
;
using
boost
::
lambda
::
_2
;
using
boost
::
lambda
::
_3
;
double
modularity
=
0
;
double
modularity
=
0
;
boost
::
any
vertex_prop
=
prop
(
property
,
_vertex_index
,
_properties
)
;
typedef
ConstantPropertyMap
<
int32_t
,
GraphInterface
::
edge_t
>
weight_map_t
;
boost
::
any
edge_prop
;
if
(
weight
.
empty
())
typedef
ConstantPropertyMap
<
int32_t
,
edge_t
>
weight_map_t
;
weight
=
weight_map_t
(
1
)
;
if
(
weight
!=
""
)
bool
directed
=
g
.
GetDirected
();
edge_prop
=
prop
(
weight
,
_edge_index
,
_properties
);
g
.
SetDirected
(
false
);
else
run_action
<
graph_tool
::
detail
::
never_directed
>
()
edge_prop
=
weight_map_t
(
1
);
(
g
,
bind
<
void
>
(
get_modularity
(),
_1
,
_2
,
_3
,
var
(
modularity
)),
edge_scalar_properties
(),
vertex_scalar_properties
())
typedef
mpl
::
push_back
<
edge_scalar_properties
,
weight_map_t
>::
type
(
weight
,
property
);
weight_properties
;
g
.
SetDirected
(
directed
);
bool
directed
=
_directed
;
_directed
=
false
;
try
{
run_action
<
detail
::
never_directed
>
()
(
*
this
,
bind
<
void
>
(
get_modularity
(),
_1
,
_2
,
_3
,
var
(
modularity
)),
weight_properties
(),
vertex_scalar_properties
())
(
edge_prop
,
vertex_prop
);
}
catch
(
property_not_found
&
e
)
{
_directed
=
directed
;
throw
GraphException
(
"error getting scalar property: "
+
string
(
e
.
what
()));
}
_directed
=
directed
;
return
modularity
;
return
modularity
;
}
}
using
namespace
boost
::
python
;
BOOST_PYTHON_MODULE
(
libgraph_tool_community
)
{
def
(
"community_structure"
,
&
community_structure
);
def
(
"modularity"
,
&
modularity
);
}
src/graph/community/graph_community.hh
View file @
c153e0c0
...
@@ -670,11 +670,17 @@ private:
...
@@ -670,11 +670,17 @@ private:
unordered_map
<
size_t
,
unordered_map
<
size_t
,
double
>
>
_NNks
;
unordered_map
<
size_t
,
unordered_map
<
size_t
,
double
>
>
_NNks
;
};
};
enum
comm_corr_t
{
ERDOS_REYNI
,
UNCORRELATED
,
CORRELATED
};
struct
get_communities_selector
struct
get_communities_selector
{
{
get_communities_selector
(
GraphInterface
::
comm_corr_t
corr
)
:
_corr
(
corr
)
{}
get_communities_selector
(
comm_corr_t
corr
)
:
_corr
(
corr
)
{}
GraphInterface
::
comm_corr_t
_corr
;
comm_corr_t
_corr
;
template
<
class
Graph
,
class
WeightMap
,
class
CommunityMap
>
template
<
class
Graph
,
class
WeightMap
,
class
CommunityMap
>
void
operator
()(
const
Graph
*
gp
,
WeightMap
weights
,
CommunityMap
s
,
double
gamma
,
void
operator
()(
const
Graph
*
gp
,
WeightMap
weights
,
CommunityMap
s
,
double
gamma
,
...
@@ -686,15 +692,15 @@ struct get_communities_selector
...
@@ -686,15 +692,15 @@ struct get_communities_selector
switch
(
_corr
)
switch
(
_corr
)
{
{
case
GraphInterface
::
ERDOS_REYNI
:
case
ERDOS_REYNI
:
get_communities
<
NNKSErdosReyni
>
()(
g
,
weights
,
s
,
gamma
,
n_iter
,
get_communities
<
NNKSErdosReyni
>
()(
g
,
weights
,
s
,
gamma
,
n_iter
,
Tinterval
,
Nspins
,
seed
,
verbose
);
Tinterval
,
Nspins
,
seed
,
verbose
);
break
;
break
;
case
GraphInterface
::
UNCORRELATED
:
case
UNCORRELATED
:
get_communities
<
NNKSUncorr
>
()(
g
,
weights
,
s
,
gamma
,
n_iter
,
get_communities
<
NNKSUncorr
>
()(
g
,
weights
,
s
,
gamma
,
n_iter
,
Tinterval
,
Nspins
,
seed
,
verbose
);
Tinterval
,
Nspins
,
seed
,
verbose
);
break
;
break
;
case
GraphInterface
::
CORRELATED
:
case
CORRELATED
:
get_communities
<
NNKSCorr
>
()(
g
,
weights
,
s
,
gamma
,
n_iter
,
get_communities
<
NNKSCorr
>
()(
g
,
weights
,
s
,
gamma
,
n_iter
,
Tinterval
,
Nspins
,
seed
,
verbose
);
Tinterval
,
Nspins
,
seed
,
verbose
);
break
;
break
;
...
...
src/graph_tool/Makefile.am
View file @
c153e0c0
...
@@ -38,6 +38,10 @@ graph_tool_clustering_PYTHON = \
...
@@ -38,6 +38,10 @@ graph_tool_clustering_PYTHON = \
clustering/__init__.py
clustering/__init__.py
graph_tool_clusteringdir
=
$(MOD_DIR)
/clustering
graph_tool_clusteringdir
=
$(MOD_DIR)
/clustering
graph_tool_community_PYTHON
=
\
community/__init__.py
graph_tool_communitydir
=
$(MOD_DIR)
/community
graph_tool_draw_PYTHON
=
\
graph_tool_draw_PYTHON
=
\
draw/__init__.py
draw/__init__.py
graph_tool_drawdir
=
$(MOD_DIR)
/draw
graph_tool_drawdir
=
$(MOD_DIR)
/draw
...
...
src/graph_tool/all.py
View file @
c153e0c0
...
@@ -39,6 +39,8 @@ from graph_tool.stats import *
...
@@ -39,6 +39,8 @@ from graph_tool.stats import *
import
graph_tool.stats
import
graph_tool.stats
from
graph_tool.clustering
import
*
from
graph_tool.clustering
import
*
import
graph_tool.clustering
import
graph_tool.clustering
from
graph_tool.community
import
*
import
graph_tool.community
from
graph_tool.run_action
import
*
from
graph_tool.run_action
import
*
graph_tool
.
run_action
graph_tool
.
run_action
from
graph_tool.misc
import
*
from
graph_tool.misc
import
*
...
...
src/graph_tool/community/__init__.py
0 → 100644
View file @
c153e0c0
#! /usr/bin/env python
# graph_tool.py -- a general graph manipulation python module
#
# Copyright (C) 2007 Tiago de Paula Peixoto <tiago@forked.de>
#
# 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 3 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, see <http://www.gnu.org/licenses/>.
from
..
dl_import
import
dl_import
dl_import
(
"import libgraph_tool_community"
)
from
..
core
import
_degree
,
_prop
import
random
,
sys
__all__
=
[
"community_structure"
,
"modularity"
]
def
community_structure
(
g
,
gamma
=
1.0
,
corr
=
"erdos"
,
spins
=
None
,
weights
=
None
,
max_iter
=
0
,
t_range
=
(
100.0
,
0.01
),
n_spins
=
0
,
verbose
=
False
,
history_file
=
""
,
seed
=
0
):
if
spins
==
None
:
spins
=
g
.
new_vertex_property
(
"int32_t"
)
new_spins
=
True
else
:
new_spins
=
False
if
seed
!=
0
:
seed
=
random
.
randint
(
0
,
sys
.
maxint
)
libgraph_tool_community
.
community_structure
(
g
.
_Graph__graph
,
gamma
,
corr
,
max_iter
,
t_range
[
1
],
t_range
[
0
],
n_spins
,
new_spins
,
seed
,
verbose
,
history_file
,
_prop
(
"e"
,
g
,
weights
),
_prop
(
"v"
,
g
,
spins
))
return
spins
def
modularity
(
g
):
c
=
libgraph_tool_clustering
.
global_clustering
(
g
.
_Graph__graph
)
return
c
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment