Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tiago Peixoto
graph-tool
Commits
19d972a1
Commit
19d972a1
authored
Jun 28, 2011
by
Tiago Peixoto
Browse files
Use GraphView in community structure code to obtain undirected graphhs
parent
35c18b6a
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/graph/community/graph_community.cc
View file @
19d972a1
...
...
@@ -65,8 +65,6 @@ void community_structure(GraphInterface& g, double gamma, string corr_name,
else
throw
ValueException
(
"invalid correlation type: "
+
corr_name
);
bool
directed
=
g
.
GetDirected
();
g
.
SetDirected
(
false
);
run_action
<
graph_tool
::
detail
::
never_directed
>
()
(
g
,
bind
<
void
>
(
get_communities_selector
(
corr
,
g
.
GetVertexIndex
()),
_1
,
_2
,
_3
,
gamma
,
n_iter
,
...
...
@@ -74,7 +72,6 @@ void community_structure(GraphInterface& g, double gamma, string corr_name,
seed
,
make_pair
(
verbose
,
history_file
)),
weight_properties
(),
allowed_spin_properties
())
(
weight
,
property
);
g
.
SetDirected
(
directed
);
}
...
...
@@ -89,14 +86,10 @@ double modularity(GraphInterface& g, boost::any weight, boost::any property)
if
(
weight
.
empty
())
weight
=
weight_map_t
(
1
);
bool
directed
=
g
.
GetDirected
();
g
.
SetDirected
(
false
);
run_action
<
graph_tool
::
detail
::
never_directed
>
()
(
g
,
bind
<
void
>
(
get_modularity
(),
_1
,
_2
,
_3
,
ref
(
modularity
)),
edge_props_t
(),
vertex_scalar_properties
())
(
weight
,
property
);
g
.
SetDirected
(
directed
);
return
modularity
;
}
...
...
src/graph_tool/community/__init__.py
View file @
19d972a1
...
...
@@ -42,7 +42,7 @@ Contents
from
..
dl_import
import
dl_import
dl_import
(
"import libgraph_tool_community"
)
from
..
import
_degree
,
_prop
,
Graph
,
libcore
from
..
import
_degree
,
_prop
,
Graph
,
GraphView
,
libcore
import
random
import
sys
...
...
@@ -207,12 +207,13 @@ def community_structure(g, n_iter, n_spins, gamma=1.0, corr="erdos",
if
history_file
==
None
:
history_file
=
""
seed
=
random
.
randint
(
0
,
sys
.
maxint
)
libgraph_tool_community
.
community_structure
(
g
.
_Graph__graph
,
gamma
,
corr
,
ug
=
GraphView
(
g
,
directed
=
False
)
libgraph_tool_community
.
community_structure
(
ug
.
_Graph__graph
,
gamma
,
corr
,
n_iter
,
t_range
[
1
],
t_range
[
0
],
n_spins
,
new_spins
,
seed
,
verbose
,
history_file
,
_prop
(
"e"
,
g
,
weight
),
_prop
(
"v"
,
g
,
spins
))
_prop
(
"e"
,
u
g
,
weight
),
_prop
(
"v"
,
u
g
,
spins
))
return
spins
...
...
@@ -260,7 +261,7 @@ def modularity(g, prop, weight=None):
>>> from pylab import *
>>> from numpy.random import seed
>>> seed(42)
>>> g = gt.load_graph("community.
dot
")
>>> g = gt.load_graph("community.
xml
")
>>> spins = gt.community_structure(g, 10000, 10)
>>> gt.modularity(g, spins)
0.535314188562404
...
...
@@ -272,9 +273,10 @@ def modularity(g, prop, weight=None):
:doi:`10.1073/pnas.0601602103`, :arxiv:`physics/0602124`
"""
m
=
libgraph_tool_community
.
modularity
(
g
.
_Graph__graph
,
_prop
(
"e"
,
g
,
weight
),
_prop
(
"v"
,
g
,
prop
))
ug
=
GraphView
(
directed
=
False
)
m
=
libgraph_tool_community
.
modularity
(
ug
.
_Graph__graph
,
_prop
(
"e"
,
ug
,
weight
),
_prop
(
"v"
,
ug
,
prop
))
return
m
...
...
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