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
e13b4d44
Commit
e13b4d44
authored
Apr 08, 2012
by
Tiago Peixoto
Browse files
Fix computation of modularity with edge weights
This fixes ticket
#92
.
parent
0e8e05fb
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/graph/community/graph_community.hh
View file @
e13b4d44
...
...
@@ -57,9 +57,9 @@ struct get_communities
template
<
class
Graph
,
class
VertexIndex
,
class
WeightMap
,
class
CommunityMap
>
void
operator
()(
const
Graph
&
g
,
VertexIndex
vertex_index
,
WeightMap
weights
,
CommunityMap
s
,
double
gamma
,
size_t
n_iter
,
pair
<
double
,
double
>
Tinterval
,
size_t
n_spins
,
size_t
seed
,
pair
<
bool
,
string
>
verbose
)
const
CommunityMap
s
,
double
gamma
,
size_t
n_iter
,
pair
<
double
,
double
>
Tinterval
,
size_t
n_spins
,
size_t
seed
,
pair
<
bool
,
string
>
verbose
)
const
{
typedef
typename
graph_traits
<
Graph
>::
vertex_descriptor
vertex_t
;
typedef
typename
graph_traits
<
Graph
>::
edge_descriptor
edge_t
;
...
...
@@ -505,7 +505,6 @@ struct get_modularity
typedef
typename
property_traits
<
CommunityMap
>::
value_type
s_val_t
;
modularity
=
0.0
;
size_t
E
=
0
;
double
W
=
0
;
typename
graph_traits
<
Graph
>::
edge_iterator
e
,
e_end
;
...
...
@@ -513,7 +512,6 @@ struct get_modularity
if
(
target
(
*
e
,
g
)
!=
source
(
*
e
,
g
))
{
W
+=
get
(
weights
,
*
e
);
E
++
;
if
(
get
(
s
,
target
(
*
e
,
g
))
==
get
(
s
,
source
(
*
e
,
g
)))
modularity
+=
2
*
get
(
weights
,
weight_key_t
(
*
e
));
}
...
...
@@ -522,10 +520,10 @@ struct get_modularity
typename
graph_traits
<
Graph
>::
vertex_iterator
v
,
v_end
;
for
(
tie
(
v
,
v_end
)
=
vertices
(
g
);
v
!=
v_end
;
++
v
)
Ks
[
get
(
s
,
*
v
)]
+=
out_degree_no_loops
(
*
v
,
g
);
Ks
[
get
(
s
,
*
v
)]
+=
out_degree_no_loops
_weighted
(
*
v
,
weights
,
g
);
for
(
typeof
(
Ks
.
begin
())
iter
=
Ks
.
begin
();
iter
!=
Ks
.
end
();
++
iter
)
modularity
-=
(
iter
->
second
*
iter
->
second
)
/
double
(
2
*
E
);
modularity
-=
(
iter
->
second
*
iter
->
second
)
/
double
(
2
*
W
);
modularity
/=
2
*
W
;
}
...
...
src/graph/graph_util.hh
View file @
e13b4d44
...
...
@@ -115,6 +115,20 @@ out_degree_no_loops(typename graph_traits<Graph>::vertex_descriptor v,
return
k
;
}
// computes the out-degree of a graph, ignoring self-edges
template
<
class
Graph
,
class
Weights
>
inline
typename
property_traits
<
Weights
>::
value_type
out_degree_no_loops_weighted
(
typename
graph_traits
<
Graph
>::
vertex_descriptor
v
,
Weights
w
,
const
Graph
&
g
)
{
typename
property_traits
<
Weights
>::
value_type
k
=
0
;
typename
graph_traits
<
Graph
>::
out_edge_iterator
e
,
e_end
;
for
(
tie
(
e
,
e_end
)
=
out_edges
(
v
,
g
);
e
!=
e_end
;
++
e
)
if
(
target
(
*
e
,
g
)
!=
v
)
k
+=
get
(
w
,
*
e
);
return
k
;
}
}
// namespace graph_tool
...
...
Tiago Peixoto
@count0
mentioned in issue
#77 (closed)
·
Aug 06, 2014
mentioned in issue
#77 (closed)
mentioned in issue #77
Toggle commit list
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