Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
graph-tool
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
40
Issues
40
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tiago Peixoto
graph-tool
Commits
17cfac1f
Commit
17cfac1f
authored
Nov 27, 2016
by
Tiago Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
inference.rst: Update doctests
parent
187b6c04
Pipeline
#234
failed with stage
in 289 minutes and 20 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
33 deletions
+37
-33
doc/demos/inference/inference.rst
doc/demos/inference/inference.rst
+16
-16
doc/test_inference.py
doc/test_inference.py
+21
-17
No files found.
doc/demos/inference/inference.rst
View file @
17cfac1f
...
...
@@ -456,7 +456,7 @@ case of the `C. elegans` network we have
:options: +NORMALIZE_WHITESPACE
Non-degree-corrected DL: 8507.97432099
Degree-corrected DL: 82
28.11609772
Degree-corrected DL: 82
49.76252971
Since it yields the smallest description length, the degree-corrected
fit should be preferred. The statistical significance of the choice can
...
...
@@ -482,12 +482,12 @@ fits. In our particular case, we have
.. testoutput:: model-selection
:options: +NORMALIZE_WHITESPACE
ln Λ: -2
79.85822327
2
ln Λ: -2
58.21179128
2
The precise threshold that should be used to decide when to `reject a
hypothesis <https://en.wikipedia.org/wiki/Hypothesis_testing>`_ is
subjective and context-dependent, but the value above implies that the
particular degree-corrected fit is around :math:`e^{2
80} \sim 10^{121
}`
particular degree-corrected fit is around :math:`e^{2
58} \sim 10^{112
}`
times more likely than the non-degree corrected one, and hence it can be
safely concluded that it provides a substantially better fit.
...
...
@@ -509,12 +509,12 @@ example, for the American football network above, we have:
.. testoutput:: model-selection
:options: +NORMALIZE_WHITESPACE
Non-degree-corrected DL: 17
49.51938237
Degree-corrected DL: 17
80.57671694
ln Λ: -
31.0573345685
Non-degree-corrected DL: 17
38.71605436
Degree-corrected DL: 17
95.27140372
ln Λ: -
56.5553493622
Hence, with a posterior odds ratio of :math:`\Lambda \sim e^{-
3
6} \sim
10^{-
16
}` in favor of the non-degree-corrected model, it seems like the
Hence, with a posterior odds ratio of :math:`\Lambda \sim e^{-
5
6} \sim
10^{-
24
}` in favor of the non-degree-corrected model, it seems like the
degree-corrected variant is an unnecessarily complex description for
this network.
...
...
@@ -1068,8 +1068,8 @@ evidence efficiently, as we show below, using
.. testoutput:: model-evidence
Model evidence for deg_corr = True: -575.8
64972067 (mean field), -802.39062289
(Bethe)
Model evidence for deg_corr = False: -
584.307313493 (mean field), -707.827204203
(Bethe)
Model evidence for deg_corr = True: -575.8
89667037 (mean field), -794.733483508
(Bethe)
Model evidence for deg_corr = False: -
618.120673252 (mean field), -729.104723167
(Bethe)
If we consider the more accurate approximation, the outcome shows a
preference for the non-degree-corrected model.
...
...
@@ -1133,8 +1133,8 @@ approach for the same network, using the nested model.
.. testoutput:: model-evidence
Model evidence for deg_corr = True: -3
46.618790006 (mean field), -601.313781849
(Bethe)
Model evidence for deg_corr = False: -3
74.614350884 (mean field), -563.256840699
(Bethe)
Model evidence for deg_corr = True: -3
33.948404832 (mean field), -651.91054824
(Bethe)
Model evidence for deg_corr = False: -3
60.235692786 (mean field), -549.293909028
(Bethe)
The results are similar: If we consider the most accurate approximation,
the non-degree-corrected model possesses the largest evidence. Note also
...
...
@@ -1363,11 +1363,11 @@ above).
..
testoutput
::
missing
-
edges
likelihood
-
ratio
for
(
101
,
102
):
0.
37230
8
likelihood
-
ratio
for
(
17
,
56
):
0.
62769
2
likelihood
-
ratio
for
(
101
,
102
):
0.
43655
8
likelihood
-
ratio
for
(
17
,
56
):
0.
56344
2
From
which
we
can
conclude
that
edge
:
math
:`(
17
,
56
)`
is
around
twice
as
likely
as
:
math
:`(
101
,
102
)`
to
be
a
missing
edge
.
From
which
we
can
conclude
that
edge
:
math
:`(
17
,
56
)`
is
more
likely
than
:
math
:`(
101
,
102
)`
to
be
a
missing
edge
.
The
prediction
using
the
non
-
nested
model
can
be
performed
in
an
entirely
analogous
fashion
.
...
...
doc/test_inference.py
View file @
17cfac1f
...
...
@@ -28,23 +28,26 @@ rec_p = g.new_ep("double", random(g.num_edges()))
rec_s
=
g
.
new_ep
(
"double"
,
normal
(
0
,
10
,
g
.
num_edges
()))
def
gen_state
(
directed
,
deg_corr
,
layers
,
overlap
,
rec
,
allow_empty
):
def
gen_state
(
directed
,
deg_corr
,
layers
,
overlap
,
rec
,
rec_type
,
allow_empty
):
u
=
GraphView
(
g
,
directed
=
directed
)
if
layers
!=
False
:
state
=
graph_tool
.
inference
.
LayeredBlockState
(
u
,
B
=
u
.
num_vertices
(),
deg_corr
=
deg_corr
,
ec
=
ec
.
copy
(),
rec
=
rec
,
recs
=
[
rec
]
if
rec
is
not
None
else
[],
rec_types
=
[
rec_type
]
if
rec
is
not
None
else
[],
overlap
=
overlap
,
layers
=
layers
==
True
,
allow_empty
=
allow_empty
)
elif
overlap
:
state
=
graph_tool
.
inference
.
OverlapBlockState
(
u
,
B
=
2
*
u
.
num_edges
(),
rec
=
rec
,
recs
=
[
rec
]
if
rec
is
not
None
else
[],
rec_types
=
[
rec_type
]
if
rec
is
not
None
else
[],
deg_corr
=
deg_corr
)
else
:
state
=
graph_tool
.
inference
.
BlockState
(
u
,
B
=
u
.
num_vertices
(),
rec
=
rec
,
recs
=
[
rec
]
if
rec
is
not
None
else
[],
rec_types
=
[
rec_type
]
if
rec
is
not
None
else
[],
deg_corr
=
deg_corr
,
allow_empty
=
allow_empty
)
return
state
...
...
@@ -53,7 +56,7 @@ def gen_state(directed, deg_corr, layers, overlap, rec, allow_empty):
pranges
=
[(
"directed"
,
[
False
,
True
]),
(
"overlap"
,
[
False
,
True
]),
(
"layered"
,
[
False
,
"covariates"
,
True
]),
(
"rec"
,
[
None
,
"
positive"
,
"signed
"
]),
(
"rec"
,
[
None
,
"
real-exponential"
,
"real-normal
"
]),
(
"deg_corr"
,
[
False
,
True
]),
(
"dl"
,
[
False
,
True
]),
(
"degree_dl_kind"
,
[
"uniform"
,
"distributed"
,
"entropy"
]),
...
...
@@ -84,13 +87,13 @@ for pvals in iter_ranges(pranges):
print
(
params
,
file
=
out
)
rec_
=
None
if
rec
==
"
positive
"
:
if
rec
==
"
real-exponential
"
:
rec_
=
rec_p
elif
rec
==
"
signed
"
:
elif
rec
==
"
real-normal
"
:
rec_
=
rec_s
print
(
"
\t
mcmc (unweighted)"
,
file
=
out
)
state
=
gen_state
(
directed
,
deg_corr
,
layered
,
overlap
,
rec_
,
allow_empty
)
state
=
gen_state
(
directed
,
deg_corr
,
layered
,
overlap
,
rec_
,
rec
,
allow_empty
)
print
(
"
\t\t
"
,
state
.
mcmc_sweep
(
beta
=
0
,
...
...
@@ -107,7 +110,7 @@ for pvals in iter_ranges(pranges):
exact
=
exact
)),
state
.
get_nonempty_B
(),
file
=
out
)
state
=
gen_state
(
directed
,
deg_corr
,
layered
,
overlap
,
rec_
,
allow_empty
)
state
=
gen_state
(
directed
,
deg_corr
,
layered
,
overlap
,
rec_
,
rec
,
allow_empty
)
if
not
overlap
:
print
(
"
\t
mcmc"
,
file
=
out
)
...
...
@@ -136,7 +139,7 @@ for pvals in iter_ranges(pranges):
print
(
"
\t
merge"
,
file
=
out
)
state
=
gen_state
(
directed
,
deg_corr
,
layered
,
overlap
,
rec_
,
allow_empty
)
state
=
gen_state
(
directed
,
deg_corr
,
layered
,
overlap
,
rec_
,
rec
,
allow_empty
)
if
not
overlap
:
bstate
=
state
.
get_block_state
(
vweight
=
True
,
deg_corr
=
deg_corr
)
...
...
@@ -174,7 +177,7 @@ for pvals in iter_ranges(pranges):
print
(
"
\t
shrink"
,
file
=
out
)
state
=
gen_state
(
directed
,
deg_corr
,
layered
,
overlap
,
rec_
,
allow_empty
)
state
=
gen_state
(
directed
,
deg_corr
,
layered
,
overlap
,
rec_
,
rec
,
allow_empty
)
state
=
state
.
shrink
(
B
=
5
,
entropy_args
=
dict
(
dl
=
dl
,
degree_dl_kind
=
degree_dl_kind
,
multigraph
=
False
,
...
...
@@ -185,7 +188,7 @@ for pvals in iter_ranges(pranges):
pranges
=
[(
"directed"
,
[
False
,
True
]),
(
"overlap"
,
[
False
,
True
]),
(
"layered"
,
[
False
,
"covariates"
,
True
]),
(
"rec"
,
[
None
,
"
positive"
,
"signed
"
]),
(
"rec"
,
[
None
,
"
real-exponential"
,
"real-normal
"
]),
(
"deg_corr"
,
[
False
,
True
]),
(
"degree_dl_kind"
,
[
"uniform"
,
"distributed"
,
"entropy"
]),
(
"exact"
,
[
True
])]
...
...
@@ -205,16 +208,17 @@ for pvals in iter_ranges(pranges):
print
(
params
,
file
=
out
)
rec_
=
None
if
rec
==
"
positive
"
:
rec_
=
[]
if
rec
==
"
real-exponential
"
:
rec_
=
rec_p
elif
rec
==
"
signed
"
:
elif
rec
==
"
real-normal
"
:
rec_
=
rec_s
if
layered
!=
False
:
state_args
=
dict
(
ec
=
ec
,
layers
=
(
layered
==
True
),
rec
=
rec_
)
state_args
=
dict
(
ec
=
ec
,
layers
=
(
layered
==
True
),
recs
=
[
rec_
],
rec_types
=
[
rec
])
else
:
state_args
=
dict
(
rec
=
rec_
)
state_args
=
dict
(
rec
s
=
[
rec_
],
rec_types
=
[
rec
]
)
entropy_args
=
dict
(
exact
=
exact
)
...
...
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