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
b73b71e1
Commit
b73b71e1
authored
Mar 07, 2011
by
Tiago Peixoto
Browse files
Remove some 'undirected' parameters
This removes some 'undirected' parameters, in favour of graph views.
parent
086c6b21
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/graph_tool/clustering/__init__.py
View file @
b73b71e1
...
@@ -58,7 +58,7 @@ __all__ = ["local_clustering", "global_clustering", "extended_clustering",
...
@@ -58,7 +58,7 @@ __all__ = ["local_clustering", "global_clustering", "extended_clustering",
"motifs"
,
"motif_significance"
]
"motifs"
,
"motif_significance"
]
def
local_clustering
(
g
,
prop
=
None
,
undirected
=
Fals
e
):
def
local_clustering
(
g
,
prop
=
None
,
undirected
=
Tru
e
):
r
"""
r
"""
Return the local clustering coefficients for all vertices.
Return the local clustering coefficients for all vertices.
...
@@ -69,7 +69,7 @@ def local_clustering(g, prop=None, undirected=False):
...
@@ -69,7 +69,7 @@ def local_clustering(g, prop=None, undirected=False):
prop : :class:`~graph_tool.PropertyMap` or string, optional
prop : :class:`~graph_tool.PropertyMap` or string, optional
Vertex property map where results will be stored. If specified, this
Vertex property map where results will be stored. If specified, this
parameter will also be the return value.
parameter will also be the return value.
undirected : bool
, optional
undirected : bool
(default: True)
Calculate the *undirected* clustering coefficient, if graph is directed
Calculate the *undirected* clustering coefficient, if graph is directed
(this option has no effect if the graph is undirected).
(this option has no effect if the graph is undirected).
...
@@ -126,15 +126,9 @@ def local_clustering(g, prop=None, undirected=False):
...
@@ -126,15 +126,9 @@ def local_clustering(g, prop=None, undirected=False):
if
prop
==
None
:
if
prop
==
None
:
prop
=
g
.
new_vertex_property
(
"double"
)
prop
=
g
.
new_vertex_property
(
"double"
)
was_directed
=
g
.
is_directed
()
if
g
.
is_directed
()
and
undirected
:
if
g
.
is_directed
()
and
undirected
:
g
.
set_directed
(
False
)
g
=
GraphView
(
g
,
directed
=
False
)
try
:
_gt
.
extended_clustering
(
g
.
_Graph__graph
,
[
_prop
(
"v"
,
g
,
prop
)])
_gt
.
extended_clustering
(
g
.
_Graph__graph
,
[
_prop
(
"v"
,
g
,
prop
)])
finally
:
if
was_directed
and
undirected
:
g
.
set_directed
(
True
)
return
prop
return
prop
...
@@ -265,23 +259,18 @@ def extended_clustering(g, props=None, max_depth=3, undirected=False):
...
@@ -265,23 +259,18 @@ def extended_clustering(g, props=None, max_depth=3, undirected=False):
measure of the local topology of networks", :arxiv:`physics/0605235`
measure of the local topology of networks", :arxiv:`physics/0605235`
"""
"""
was_directed
=
g
.
is_directed
()
if
g
.
is_directed
()
and
undirected
:
if
g
.
is_directed
()
and
undirected
:
g
.
set_
directed
(
False
)
g
=
GraphView
(
g
,
directed
=
False
)
if
props
==
None
:
if
props
==
None
:
props
=
[]
props
=
[]
for
i
in
xrange
(
0
,
max_depth
):
for
i
in
xrange
(
0
,
max_depth
):
props
.
append
(
g
.
new_vertex_property
(
"double"
))
props
.
append
(
g
.
new_vertex_property
(
"double"
))
try
:
_gt
.
extended_clustering
(
g
.
_Graph__graph
,
_gt
.
extended_clustering
(
g
.
_Graph__graph
,
[
_prop
(
"v"
,
g
,
p
)
for
p
in
props
])
[
_prop
(
"v"
,
g
,
p
)
for
p
in
props
])
finally
:
if
was_directed
and
undirected
:
g
.
set_directed
(
True
)
return
props
return
props
def
motifs
(
g
,
k
,
p
=
1.0
,
motif_list
=
None
,
undirected
=
None
):
def
motifs
(
g
,
k
,
p
=
1.0
,
motif_list
=
None
):
r
"""
r
"""
Count the occurrence of k-size subgraphs (motifs). A tuple with two lists is
Count the occurrence of k-size subgraphs (motifs). A tuple with two lists is
returned: the list of motifs found, and the list with their respective
returned: the list of motifs found, and the list with their respective
...
@@ -301,9 +290,6 @@ def motifs(g, k, p=1.0, motif_list=None, undirected=None):
...
@@ -301,9 +290,6 @@ def motifs(g, k, p=1.0, motif_list=None, undirected=None):
motif_list : list of :class:`~graph_tool.Graph` objects, optional
motif_list : list of :class:`~graph_tool.Graph` objects, optional
If supplied, the algorithms will only search for the motifs in this list
If supplied, the algorithms will only search for the motifs in this list
(or isomorphisms).
(or isomorphisms).
undirected : bool, optional
Treat the graph as *undirected*, if graph is directed
(this option has no effect if the graph is undirected).
Returns
Returns
-------
-------
...
@@ -334,7 +320,7 @@ def motifs(g, k, p=1.0, motif_list=None, undirected=None):
...
@@ -334,7 +320,7 @@ def motifs(g, k, p=1.0, motif_list=None, undirected=None):
>>> from numpy.random import seed
>>> from numpy.random import seed
>>> seed(42)
>>> seed(42)
>>> g = gt.random_graph(1000, lambda: (5,5))
>>> g = gt.random_graph(1000, lambda: (5,5))
>>> motifs, counts = gt.motifs(g
, 4, undirected=True
)
>>> motifs, counts = gt.motifs(g
t.GraphView(g, directed=False), 4
)
>>> print len(motifs)
>>> print len(motifs)
14
14
>>> print counts
>>> print counts
...
@@ -352,40 +338,38 @@ def motifs(g, k, p=1.0, motif_list=None, undirected=None):
...
@@ -352,40 +338,38 @@ def motifs(g, k, p=1.0, motif_list=None, undirected=None):
seed
=
random
.
randint
(
0
,
sys
.
maxint
)
seed
=
random
.
randint
(
0
,
sys
.
maxint
)
sub_list
=
[]
sub_list
=
[]
directed_motifs
=
g
.
is_directed
()
if
undirected
==
None
else
not
undirected
directed_motifs
=
g
.
is_directed
()
if
motif_list
!=
None
:
if
motif_list
is
not
None
:
directed_motifs
=
motif_list
[
0
].
is_directed
()
directed_motifs
=
motif_list
[
0
].
is_directed
()
for
m
in
motif_list
:
for
m
in
motif_list
:
if
m
.
is_directed
()
!=
directed_motifs
:
if
m
.
is_directed
()
!=
directed_motifs
:
raise
ValueError
(
"all motif graphs must be either directed or undirected"
)
raise
ValueError
(
"all motif graphs must be either directed or undirected
!
"
)
if
m
.
num_vertices
()
!=
k
:
if
m
.
num_vertices
()
!=
k
:
raise
ValueError
(
"all motifs must have the same number of vertices: "
+
k
)
raise
ValueError
(
"all motifs must have the same number of vertices: "
+
k
)
sub_list
.
append
(
m
.
_Graph__graph
)
sub_list
.
append
(
m
.
_Graph__graph
)
if
directed_motifs
!=
g
.
is_directed
():
raise
ValueError
(
"motifs do not have the same directionality as the graph itself!"
)
if
type
(
p
)
==
float
:
if
type
(
p
)
==
float
:
pd
=
[
1.0
]
*
(
k
-
1
)
pd
=
[
1.0
]
*
(
k
-
1
)
pd
.
append
(
p
)
pd
.
append
(
p
)
if
type
(
p
)
==
list
:
if
type
(
p
)
==
list
:
pd
=
[
float
(
x
)
for
x
in
p
]
pd
=
[
float
(
x
)
for
x
in
p
]
hist
=
[]
hist
=
[]
was_directed
=
g
.
is_directed
()
was_directed
=
g
.
is_directed
()
if
g
.
is_directed
()
and
not
directed_motifs
:
_gt
.
get_motifs
(
g
.
_Graph__graph
,
k
,
sub_list
,
hist
,
pd
,
g
.
set_directed
(
False
)
True
,
len
(
sub_list
)
==
0
,
try
:
seed
)
_gt
.
get_motifs
(
g
.
_Graph__graph
,
k
,
sub_list
,
hist
,
pd
,
True
,
len
(
sub_list
)
==
0
,
seed
)
finally
:
if
was_directed
and
not
directed_motifs
:
g
.
set_directed
(
True
)
# assemble graphs
# assemble graphs
temp
=
[]
temp
=
[]
for
m
in
sub_list
:
for
m
in
sub_list
:
mg
=
Graph
()
mg
=
Graph
()
mg
.
_Graph__graph
=
m
mg
.
_Graph__graph
=
m
mg
.
reindex_edges
()
temp
.
append
(
mg
)
temp
.
append
(
mg
)
sub_list
=
temp
sub_list
=
temp
...
@@ -422,9 +406,8 @@ def _graph_sig(g):
...
@@ -422,9 +406,8 @@ def _graph_sig(g):
def
motif_significance
(
g
,
k
,
n_shuffles
=
100
,
p
=
1.0
,
motif_list
=
None
,
def
motif_significance
(
g
,
k
,
n_shuffles
=
100
,
p
=
1.0
,
motif_list
=
None
,
threshold
=
0
,
undirected
=
None
,
self_loops
=
False
,
threshold
=
0
,
self_loops
=
False
,
parallel_edges
=
False
,
parallel_edges
=
False
,
full_output
=
False
,
full_output
=
False
,
shuffle_strategy
=
"uncorrelated"
):
shuffle_strategy
=
"uncorrelated"
):
r
"""
r
"""
Obtain the motif significance profile, for subgraphs with k vertices. A
Obtain the motif significance profile, for subgraphs with k vertices. A
tuple with two lists is returned: the list of motifs found, and their
tuple with two lists is returned: the list of motifs found, and their
...
@@ -448,9 +431,6 @@ def motif_significance(g, k, n_shuffles=100, p=1.0, motif_list=None,
...
@@ -448,9 +431,6 @@ def motif_significance(g, k, n_shuffles=100, p=1.0, motif_list=None,
(isomorphisms)
(isomorphisms)
threshold : int (optional, default: 0)
threshold : int (optional, default: 0)
If a given motif count is below this level, it is not considered.
If a given motif count is below this level, it is not considered.
undirected : bool (optional, default: None)
Treat the graph as *undirected*, if graph is directed
(this option has no effect if the graph is undirected).
self_loops : bool (optional, default: False)
self_loops : bool (optional, default: False)
Whether or not the shuffled graphs are allowed to contain self-loops
Whether or not the shuffled graphs are allowed to contain self-loops
parallel_edges : bool (optional, default: False)
parallel_edges : bool (optional, default: False)
...
@@ -509,10 +489,10 @@ def motif_significance(g, k, n_shuffles=100, p=1.0, motif_list=None,
...
@@ -509,10 +489,10 @@ def motif_significance(g, k, n_shuffles=100, p=1.0, motif_list=None,
>>> print len(motifs)
>>> print len(motifs)
11
11
>>> print zscores
>>> print zscores
[-0.77247260114237382, -0.99569269406173944, -0.89282671051270046, 0.3239871430063806, 0.30808421357288784, 0.78512106107239443, 0.53748384988656916, 1.9
099999999999999, -0.12, -0.29999999999999999
, -0.12]
[-0.77247260114237382, -0.99569269406173944, -0.89282671051270046, 0.3239871430063806, 0.30808421357288784, 0.78512106107239443, 0.53748384988656916, 1.9
1, -0.12, -0.3
, -0.12]
"""
"""
s_ms
,
counts
=
motifs
(
g
,
k
,
p
,
motif_list
,
undirected
)
s_ms
,
counts
=
motifs
(
g
,
k
,
p
,
motif_list
)
if
threshold
>
0
:
if
threshold
>
0
:
s_ms
,
counts
=
zip
(
*
[
x
for
x
in
zip
(
s_ms
,
counts
)
if
x
[
1
]
>
threshold
])
s_ms
,
counts
=
zip
(
*
[
x
for
x
in
zip
(
s_ms
,
counts
)
if
x
[
1
]
>
threshold
])
s_ms
=
list
(
s_ms
)
s_ms
=
list
(
s_ms
)
...
@@ -530,7 +510,7 @@ def motif_significance(g, k, n_shuffles=100, p=1.0, motif_list=None,
...
@@ -530,7 +510,7 @@ def motif_significance(g, k, n_shuffles=100, p=1.0, motif_list=None,
for
i
in
xrange
(
0
,
n_shuffles
):
for
i
in
xrange
(
0
,
n_shuffles
):
random_rewire
(
sg
,
shuffle_strategy
,
self_loops
=
self_loops
,
random_rewire
(
sg
,
shuffle_strategy
,
self_loops
=
self_loops
,
parallel_edges
=
parallel_edges
)
parallel_edges
=
parallel_edges
)
m_temp
,
count_temp
=
motifs
(
sg
,
k
,
p
,
motif_list
,
undirected
)
m_temp
,
count_temp
=
motifs
(
sg
,
k
,
p
,
motif_list
)
if
threshold
>
0
:
if
threshold
>
0
:
m_temp
,
count_temp
=
zip
(
*
[
x
for
x
in
zip
(
m_temp
,
count_temp
)
\
m_temp
,
count_temp
=
zip
(
*
[
x
for
x
in
zip
(
m_temp
,
count_temp
)
\
if
x
[
1
]
>
threshold
])
if
x
[
1
]
>
threshold
])
...
...
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