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
9b659850
Commit
9b659850
authored
Aug 19, 2015
by
Tiago Peixoto
Browse files
(*)_blockmodel.py: Improve memory usage by clearing cache more frequently
parent
f44436b4
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/graph_tool/community/blockmodel.py
View file @
9b659850
...
@@ -198,6 +198,9 @@ class BlockState(object):
...
@@ -198,6 +198,9 @@ class BlockState(object):
if
self
.
ignore_degrees
is
None
:
if
self
.
ignore_degrees
is
None
:
self
.
ignore_degrees
=
g
.
new_vertex_property
(
"bool"
,
False
)
self
.
ignore_degrees
=
g
.
new_vertex_property
(
"bool"
,
False
)
self
.
clear_cache
()
def
clear_cache
(
self
):
# used by mcmc_sweep()
# used by mcmc_sweep()
self
.
egroups
=
None
self
.
egroups
=
None
self
.
nsampler
=
None
self
.
nsampler
=
None
...
@@ -205,6 +208,7 @@ class BlockState(object):
...
@@ -205,6 +208,7 @@ class BlockState(object):
self
.
overlap_stats
=
libcommunity
.
overlap_stats
()
self
.
overlap_stats
=
libcommunity
.
overlap_stats
()
self
.
partition_stats
=
libcommunity
.
partition_stats
()
self
.
partition_stats
=
libcommunity
.
partition_stats
()
self
.
edges_dl
=
False
self
.
edges_dl
=
False
self
.
emat
=
None
def
__repr__
(
self
):
def
__repr__
(
self
):
return
"<BlockState object with %d blocks,%s for graph %s, at 0x%x>"
%
\
return
"<BlockState object with %d blocks,%s for graph %s, at 0x%x>"
%
\
...
@@ -351,13 +355,6 @@ class BlockState(object):
...
@@ -351,13 +355,6 @@ class BlockState(object):
_prop
(
"e"
,
self
.
g
,
self
.
eweight
),
_prop
(
"e"
,
self
.
g
,
self
.
eweight
),
True
,
empty
)
True
,
empty
)
def
__cleanup_bg
(
self
):
emask
=
self
.
bg
.
new_edge_property
(
"bool"
)
emask
.
a
=
self
.
mrs
.
a
[:
len
(
emask
.
a
)]
>
0
self
.
bg
.
set_edge_filter
(
emask
)
self
.
bg
.
purge_edges
()
self
.
emat
=
None
def
get_blocks
(
self
):
def
get_blocks
(
self
):
r
"""Returns the property map which contains the block labels for each vertex."""
r
"""Returns the property map which contains the block labels for each vertex."""
return
self
.
b
return
self
.
b
...
@@ -1529,6 +1526,8 @@ def unilevel_minimize(state, nsweeps=10, adaptive_sweeps=True, epsilon=0,
...
@@ -1529,6 +1526,8 @@ def unilevel_minimize(state, nsweeps=10, adaptive_sweeps=True, epsilon=0,
bi
=
state
.
b
bi
=
state
.
b
state
.
clear_cache
()
return
t_dS
,
t_nmoves
return
t_dS
,
t_nmoves
...
...
src/graph_tool/community/covariate_blockmodel.py
View file @
9b659850
...
@@ -194,6 +194,13 @@ class CovariateBlockState(BlockState):
...
@@ -194,6 +194,13 @@ class CovariateBlockState(BlockState):
assert
state
.
mrs
.
fa
.
sum
()
==
state
.
eweight
.
fa
.
sum
(),
(
"inconsistent mrs!"
,
l
)
assert
state
.
mrs
.
fa
.
sum
()
==
state
.
eweight
.
fa
.
sum
(),
(
"inconsistent mrs!"
,
l
)
self
.
clear_cache
()
if
_bm_test
():
assert
self
.
mrs
.
fa
.
sum
()
==
self
.
eweight
.
fa
.
sum
(),
"inconsistent mrs!"
def
clear_cache
(
self
):
self
.
__bg
=
None
self
.
__bg
=
None
self
.
__mrs
=
None
self
.
__mrs
=
None
self
.
__bec
=
None
self
.
__bec
=
None
...
@@ -202,16 +209,15 @@ class CovariateBlockState(BlockState):
...
@@ -202,16 +209,15 @@ class CovariateBlockState(BlockState):
#self.wr = self.__dummy_bg.own_property(total_state.wr)
#self.wr = self.__dummy_bg.own_property(total_state.wr)
self
.
wr
=
total_state
.
wr
self
.
wr
=
total_state
.
wr
for
s
in
self
.
states
:
s
.
clear_cache
()
self
.
total_state
.
clear_cache
()
self
.
sweep_vertices
=
total_state
.
sweep_vertices
self
.
sweep_vertices
=
total_state
.
sweep_vertices
self
.
emat
=
None
self
.
emat
=
None
self
.
overlap_stats
=
self
.
total_state
.
overlap_stats
self
.
overlap_stats
=
self
.
total_state
.
overlap_stats
self
.
__layer_entropy
=
None
if
_bm_test
():
assert
self
.
mrs
.
fa
.
sum
()
==
self
.
eweight
.
fa
.
sum
(),
"inconsistent mrs!"
def
__get_base_u
(
self
,
u
):
def
__get_base_u
(
self
,
u
):
node_index
=
u
.
vp
[
"vmap"
].
copy
(
"int64_t"
)
node_index
=
u
.
vp
[
"vmap"
].
copy
(
"int64_t"
)
pmap
(
node_index
,
self
.
total_state
.
node_index
)
pmap
(
node_index
,
self
.
total_state
.
node_index
)
...
...
src/graph_tool/community/overlap_blockmodel.py
View file @
9b659850
...
@@ -214,23 +214,20 @@ class OverlapBlockState(BlockState):
...
@@ -214,23 +214,20 @@ class OverlapBlockState(BlockState):
else
:
else
:
self
.
clabel
=
self
.
g
.
new_vertex_property
(
"int"
)
self
.
clabel
=
self
.
g
.
new_vertex_property
(
"int"
)
self
.
emat
=
None
if
max_BE
is
None
:
if
max_BE
is
None
:
max_BE
=
1000
max_BE
=
1000
self
.
max_BE
=
max_BE
self
.
max_BE
=
max_BE
self
.
clear_cache
()
def
clear_cache
(
self
):
# used by mcmc_sweep()
# used by mcmc_sweep()
self
.
egroups
=
None
self
.
egroups
=
None
self
.
nsampler
=
None
self
.
nsampler
=
None
self
.
sweep_vertices
=
None
self
.
sweep_vertices
=
None
self
.
partition_stats
=
libcommunity
.
overlap_partition_stats
()
self
.
partition_stats
=
libcommunity
.
overlap_partition_stats
()
self
.
edges_dl
=
False
self
.
edges_dl
=
False
self
.
emat
=
None
def
__del__
(
self
):
try
:
BlockState
.
__del__
(
self
)
except
(
TypeError
,
AttributeError
):
pass
def
__repr__
(
self
):
def
__repr__
(
self
):
return
"<OverlapBlockState object with %d blocks,%s for graph %s, at 0x%x>"
%
\
return
"<OverlapBlockState object with %d blocks,%s for graph %s, at 0x%x>"
%
\
...
...
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