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
0e958d61
Commit
0e958d61
authored
Mar 30, 2019
by
Tiago Peixoto
Browse files
Implement Bfield parameter
parent
aebfabed
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/graph/inference/blockmodel/graph_blockmodel.cc
View file @
0e958d61
...
...
@@ -161,7 +161,8 @@ void export_blockmodel_state()
.
def_readwrite
(
"degree_dl_kind"
,
&
entropy_args_t
::
degree_dl_kind
)
.
def_readwrite
(
"edges_dl"
,
&
entropy_args_t
::
edges_dl
)
.
def_readwrite
(
"recs_dl"
,
&
entropy_args_t
::
recs_dl
)
.
def_readwrite
(
"beta_dl"
,
&
entropy_args_t
::
beta_dl
);
.
def_readwrite
(
"beta_dl"
,
&
entropy_args_t
::
beta_dl
)
.
def_readwrite
(
"Bfield"
,
&
entropy_args_t
::
Bfield
);
enum_
<
deg_dl_kind
>
(
"deg_dl_kind"
)
.
value
(
"ent"
,
deg_dl_kind
::
ENT
)
...
...
src/graph/inference/blockmodel/graph_blockmodel.hh
View file @
0e958d61
...
...
@@ -89,6 +89,7 @@ typedef mpl::vector1<std::false_type> rmap_tr;
((bclabel,, vmap_t, 0)) \
((pclabel,, vmap_t, 0)) \
((bfield,, vprop_map_t<std::vector<double>>::type, 0)) \
((Bfield, &, std::vector<double>&, 0)) \
((merge_map,, vmap_t, 0)) \
((deg_corr,, bool, 0)) \
((rec_types,, std::vector<int32_t>, 0)) \
...
...
@@ -1456,6 +1457,26 @@ public:
dS_dl
+=
(
r
<
f
.
size
())
?
f
[
r
]
:
f
.
back
();
}
if
(
!
_Bfield
.
empty
()
&&
ea
.
Bfield
)
{
int
dB
=
0
;
if
(
virtual_remove_size
(
v
)
==
0
)
dB
--
;
if
(
_wr
[
nr
]
==
0
)
dB
++
;
if
(
dB
!=
0
)
{
size_t
actual_B
=
0
;
for
(
auto
&
ps
:
_partition_stats
)
actual_B
+=
ps
.
get_actual_B
();
dS_dl
+=
(
actual_B
<
_Bfield
.
size
())
?
_Bfield
[
actual_B
]
:
_Bfield
.
back
();
actual_B
+=
dB
;
dS_dl
-=
(
actual_B
<
_Bfield
.
size
())
?
_Bfield
[
actual_B
]
:
_Bfield
.
back
();
}
}
int
dL
=
0
;
if
(
ea
.
recs
&&
_rt
!=
weight_type
::
NONE
)
{
...
...
@@ -2091,6 +2112,15 @@ public:
S_dl
+=
get
<
1
>
(
rdS
);
}
if
(
!
_Bfield
.
empty
()
&&
ea
.
Bfield
)
{
size_t
actual_B
=
0
;
for
(
auto
&
ps
:
_partition_stats
)
actual_B
+=
ps
.
get_actual_B
();
S_dl
-=
(
actual_B
<
_Bfield
.
size
())
?
_Bfield
[
actual_B
]
:
_Bfield
.
back
();
}
if
(
_coupled_state
!=
nullptr
&&
propagate
)
S_dl
+=
_coupled_state
->
entropy
(
_coupled_entropy_args
,
true
);
...
...
src/graph/inference/blockmodel/graph_blockmodel_entropy.hh
View file @
0e958d61
...
...
@@ -48,6 +48,7 @@ struct entropy_args_t
bool
edges_dl
;
bool
recs_dl
;
double
beta_dl
;
double
Bfield
;
};
// Sparse entropy terms
...
...
src/graph_tool/inference/blockmodel.py
View file @
0e958d61
...
...
@@ -157,12 +157,14 @@ def get_entropy_args(kargs, ignore=None):
ea
.
recs_dl
=
False
ea
.
degree_dl_kind
=
kind
ea
.
beta_dl
=
args
.
beta_dl
ea
.
Bfield
=
args
.
Bfield
del
kargs
[
"dl"
]
del
kargs
[
"partition_dl"
]
del
kargs
[
"degree_dl"
]
del
kargs
[
"edges_dl"
]
del
kargs
[
"recs_dl"
]
del
kargs
[
"beta_dl"
]
del
kargs
[
"Bfield"
]
kargs
.
pop
(
"callback"
,
None
)
if
len
(
kargs
)
>
0
:
raise
ValueError
(
"unrecognized entropy arguments: "
+
...
...
@@ -260,7 +262,8 @@ class BlockState(object):
def
__init__
(
self
,
g
,
b
=
None
,
B
=
None
,
eweight
=
None
,
vweight
=
None
,
recs
=
[],
rec_types
=
[],
rec_params
=
[],
clabel
=
None
,
pclabel
=
None
,
bfield
=
None
,
deg_corr
=
True
,
allow_empty
=
False
,
max_BE
=
1000
,
**
kwargs
):
bfield
=
None
,
Bfield
=
None
,
deg_corr
=
True
,
allow_empty
=
False
,
max_BE
=
1000
,
**
kwargs
):
kwargs
=
kwargs
.
copy
()
# initialize weights to unity, if necessary
...
...
@@ -463,6 +466,11 @@ class BlockState(object):
self
.
bfield
=
g
.
new_vp
(
"vector<double>"
)
if
bfield
is
None
else
bfield
if
self
.
bfield
.
value_type
()
!=
"vector<double>"
:
raise
ValueError
(
"'bfield' property map must be of type 'vector<double>'"
)
if
Bfield
is
None
:
self
.
Bfield
=
Vector_double
()
else
:
self
.
Bfield
=
Vector_double
(
len
(
Bfield
))
self
.
Bfield
.
a
=
Bfield
self
.
allow_empty
=
allow_empty
self
.
_abg
=
self
.
bg
.
_get_any
()
self
.
_avweight
=
self
.
vweight
.
_get_any
()
...
...
@@ -480,7 +488,8 @@ class BlockState(object):
partition_dl
=
True
,
degree_dl
=
True
,
degree_dl_kind
=
"distributed"
,
edges_dl
=
True
,
dense
=
False
,
multigraph
=
True
,
exact
=
True
,
recs
=
True
,
recs_dl
=
True
,
beta_dl
=
1.
)
recs
=
True
,
recs_dl
=
True
,
beta_dl
=
1.
,
Bfield
=
True
)
if
len
(
kwargs
)
>
0
:
warnings
.
warn
(
"unrecognized keyword arguments: "
+
...
...
@@ -940,8 +949,8 @@ class BlockState(object):
def
entropy
(
self
,
adjacency
=
True
,
dl
=
True
,
partition_dl
=
True
,
degree_dl
=
True
,
degree_dl_kind
=
"distributed"
,
edges_dl
=
True
,
dense
=
False
,
multigraph
=
True
,
deg_entropy
=
True
,
recs
=
True
,
recs_dl
=
True
,
beta_dl
=
1.
,
exact
=
True
,
**
kwargs
):
dense
=
False
,
multigraph
=
True
,
deg_entropy
=
True
,
recs
=
True
,
recs_dl
=
True
,
beta_dl
=
1.
,
Bfield
=
True
,
exact
=
True
,
**
kwargs
):
r
"""Calculate the entropy (a.k.a. negative log-likelihood) associated
with the current block partition.
...
...
src/graph_tool/inference/overlap_blockmodel.py
View file @
0e958d61
...
...
@@ -268,7 +268,8 @@ class OverlapBlockState(BlockState):
partition_dl
=
True
,
degree_dl
=
True
,
degree_dl_kind
=
"distributed"
,
edges_dl
=
True
,
dense
=
False
,
multigraph
=
True
,
exact
=
True
,
recs
=
True
,
recs_dl
=
True
,
beta_dl
=
1.
)
recs
=
True
,
recs_dl
=
True
,
beta_dl
=
1.
,
Bfield
=
True
)
self
.
_coupled_state
=
None
...
...
Write
Preview
Supports
Markdown
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