Commit 627f6ea0 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Update docstests

parent 950fca54
......@@ -163,7 +163,7 @@ follows:
os.chdir("demos/inference")
except FileNotFoundError:
pass
gt.seed_rng(42)
gt.seed_rng(44)
.. testcode:: food-web
......@@ -273,9 +273,9 @@ Therefore, we can compute the posterior odds ratio between both models as:
.. testoutput:: food-web
:options: +NORMALIZE_WHITESPACE
ln Λ: -36.983569...
ln Λ: -52.959287...
A value of :math:`\Lambda \approx \mathrm{e}^{37} \approx 10^{16}` in
A value of :math:`\Lambda \approx \mathrm{e}^{53} \approx 10^{23}` in
favor the exponential model indicates that the log-normal model does not
provide a better fit for this particular data.
......
......@@ -21,7 +21,8 @@ network of American football teams, which we load from the
os.chdir("demos/inference")
except FileNotFoundError:
pass
gt.seed_rng(12)
np.random.seed(42)
gt.seed_rng(42)
.. testcode:: football
......@@ -94,7 +95,7 @@ which yields:
.. testoutput:: football
103
82
.. note::
......@@ -148,7 +149,7 @@ illustrate its use with the neural network of the `C. elegans
.. testsetup:: celegans
gt.seed_rng(42)
gt.seed_rng(44)
.. testcode:: celegans
......@@ -206,10 +207,10 @@ which shows the number of nodes and groups in all levels:
.. testoutput:: celegans
l: 0, N: 297, B: 20
l: 1, N: 20, B: 8
l: 2, N: 8, B: 3
l: 3, N: 3, B: 1
l: 0, N: 297, B: 15
l: 1, N: 15, B: 6
l: 2, N: 6, B: 2
l: 3, N: 2, B: 1
l: 4, N: 1, B: 1
The hierarchical levels themselves are represented by individual
......@@ -226,11 +227,11 @@ The hierarchical levels themselves are represented by individual
.. testoutput:: celegans
<BlockState object with 297 blocks (20 nonempty), degree-corrected, for graph <Graph object, directed, with 297 vertices and 2359 edges, 2 internal vertex properties, 1 internal edge property, 2 internal graph properties, at 0x...>, at 0x...>
<BlockState object with 27 blocks (8 nonempty), for graph <Graph object, directed, with 297 vertices and 203 edges, 2 internal vertex properties, 1 internal edge property, at 0x...>, at 0x...>
<BlockState object with 12 blocks (3 nonempty), for graph <Graph object, directed, with 27 vertices and 51 edges, 2 internal vertex properties, 1 internal edge property, at 0x...>, at 0x...>
<BlockState object with 3 blocks (1 nonempty), for graph <Graph object, directed, with 12 vertices and 8 edges, 2 internal vertex properties, 1 internal edge property, at 0x...>, at 0x...>
<BlockState object with 1 blocks (1 nonempty), for graph <Graph object, directed, with 3 vertices and 1 edge, 2 internal vertex properties, 1 internal edge property, at 0x...>, at 0x...>
<BlockState object with 297 blocks (15 nonempty), degree-corrected, for graph <Graph object, directed, with 297 vertices and 2359 edges, 2 internal vertex properties, 1 internal edge property, 2 internal graph properties, at 0x...>, at 0x...>
<BlockState object with 15 blocks (6 nonempty), for graph <Graph object, directed, with 297 vertices and 125 edges, 2 internal vertex properties, 1 internal edge property, at 0x...>, at 0x...>
<BlockState object with 8 blocks (2 nonempty), for graph <Graph object, directed, with 15 vertices and 32 edges, 2 internal vertex properties, 1 internal edge property, at 0x...>, at 0x...>
<BlockState object with 2 blocks (1 nonempty), for graph <Graph object, directed, with 8 vertices and 4 edges, 2 internal vertex properties, 1 internal edge property, at 0x...>, at 0x...>
<BlockState object with 1 blocks (1 nonempty), for graph <Graph object, directed, with 2 vertices and 1 edge, 2 internal vertex properties, 1 internal edge property, at 0x...>, at 0x...>
This means that we can inspect the hierarchical partition just as before:
......@@ -245,9 +246,9 @@ This means that we can inspect the hierarchical partition just as before:
.. testoutput:: celegans
175
10
2
278
4
4
Refinements using merge-split MCMC
++++++++++++++++++++++++++++++++++
......@@ -282,7 +283,7 @@ to the above minimization for the `C. elegans` network is the following:
.. testoutput:: celegans-mcmc
Improvement: -83.804934...
Improvement: -36.887009...
Whenever possible, this procedure should be repeated several times, and
the result with the smallest description length (obtained via the
......
......@@ -110,8 +110,8 @@ show in the example below.
.. testoutput:: model-evidence
Model log-evidence for deg_corr = True: -678.461337...
Model log-evidence for deg_corr = False: -672.572076...
Model log-evidence for deg_corr = True: -678.633834...
Model log-evidence for deg_corr = False: -670.190510...
The outcome shows a preference for the non-degree-corrected model.
......@@ -168,8 +168,8 @@ approach for the same network, using the nested model.
.. testoutput:: nested-model-evidence
Model log-evidence for deg_corr = True: -663.861749...
Model log-evidence for deg_corr = False: -655.062153...
Model log-evidence for deg_corr = True: -666.147684...
Model log-evidence for deg_corr = False: -657.426243...
The results are similar: The non-degree-corrected model possesses the
largest evidence. Note also that we observe a better evidence for the
......
......@@ -25,8 +25,8 @@ we have
.. testoutput:: model-selection
:options: +NORMALIZE_WHITESPACE
Non-degree-corrected DL: 8506.262715...
Degree-corrected DL: 8246.035395...
Non-degree-corrected DL: 8550.039909...
Degree-corrected DL: 8204.289347...
Since it yields the smallest description length, the degree-corrected
fit should be preferred. The statistical significance of the choice can
......@@ -52,13 +52,13 @@ fits. In our particular case, we have
.. testoutput:: model-selection
:options: +NORMALIZE_WHITESPACE
ln Λ: -260.227319...
ln Λ: -345.750561...
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:`\mathrm{e}^{260}
\approx 10^{112}` times more likely than the non-degree corrected one,
particular degree-corrected fit is around :math:`\mathrm{e}^{345}
\approx 10^{149}` times more likely than the non-degree corrected one,
and hence it can be safely concluded that it provides a substantially
better fit.
......@@ -81,8 +81,8 @@ example, for the American football network above, we have:
:options: +NORMALIZE_WHITESPACE
Non-degree-corrected DL: 1733.525685...
Degree-corrected DL: 1780.576716...
ln Λ: -47.051031...
Degree-corrected DL: 1780.964656...
ln Λ: -47.438970...
Hence, with a posterior odds ratio of :math:`\Lambda \approx
\mathrm{e}^{-47} \approx 10^{-21}` in favor of the non-degree-corrected
......
......@@ -136,8 +136,8 @@ above).
.. testoutput:: missing-edges
likelihood-ratio for (101, 102): 0.0199167
likelihood-ratio for (17, 56): 0.980083
likelihood-ratio for (101, 102): 0.0202066
likelihood-ratio for (17, 56): 0.979793
From which we can conclude that edge :math:`(17, 56)` is more likely
than :math:`(101, 102)` to be a missing edge.
......
......@@ -189,9 +189,9 @@ Which yields the following output:
.. testoutput:: measured
Posterior probability of edge (11, 36): 0.345334...
Posterior probability of edge (11, 36): 0.377937...
Posterior probability of non-edge (15, 73): 0.0
Estimated average local clustering: 0.570758 ± 0.00247256
Estimated average local clustering: 0.571134 ± 0.002860...
We have a successful reconstruction, where both ambiguous adjacency
......@@ -313,9 +313,9 @@ Which yields:
.. testoutput:: measured
Posterior probability of edge (11, 36): 0.218221...
Posterior probability of edge (11, 36): 0.414341...
Posterior probability of non-edge (15, 73): 0.0
Estimated average local clustering: 0.565382 ± 0.00778943
Estimated average local clustering: 0.57138 ± 0.003014...
The results are very similar to the ones obtained with the uniform model
in this case, but can be quite different in situations where a large
......@@ -439,9 +439,9 @@ The above yields the output:
.. testoutput:: uncertain
Posterior probability of edge (11, 36): 0.891589...
Posterior probability of non-edge (15, 73): 0.003300...
Estimated average local clustering: 0.51592 ± 0.0284656
Posterior probability of edge (11, 36): 0.699969...
Posterior probability of non-edge (15, 73): 0.0
Estimated average local clustering: 0.540214 ± 0.028586...
The reconstruction is accurate, despite the two ambiguous entries having
the same measurement probability. The reconstructed network is visualized below.
......@@ -718,8 +718,8 @@ Which yields the following output:
.. testoutput:: measured-closure
Posterior probability of edge (11, 36): 1.0
Posterior probability of edge (11, 36): 0.915691...
Posterior probability of non-edge (15, 73): 0.0
Estimated average local clustering: 0.573263 ± 0.00149512
Estimated average local clustering: 0.573308 ± 0.002496...
.. include:: _reconstruction_dynamics.rst
......@@ -146,8 +146,8 @@ The reconstruction can accurately recover the hidden network and the infection p
.. testoutput:: dynamics
Posterior similarity: 0.984238...
Inferred infection probability: 0.690102 ± 0.0484924
Posterior similarity: 0.984240...
Inferred infection probability: 0.690546 ± 0.0476793
The figure below shows the reconstructed network and the inferred community structure.
......
......@@ -60,8 +60,8 @@ from a random partition into 20 groups
.. testoutput:: model-averaging
Change in description length: -63.691086...
Number of accepted vertex moves: 137242
Change in description length: -77.095673...
Number of accepted vertex moves: 128045
Although the above is sufficient to implement sampling from the
posterior, there is a convenience function called
......@@ -195,8 +195,8 @@ network as above.
.. testoutput:: nested-model-averaging
Change in description length: -46.639668...
Number of accepted vertex moves: 451971
Change in description length: -73.911066...
Number of accepted vertex moves: 435339
.. warning::
......@@ -383,10 +383,10 @@ corresponding to their collective posterior probability.
.. testoutput:: partition-modes
Mode 0 with size 0.684684...
Mode 1 with size 0.240240...
Mode 2 with size 0.074074...
Mode 3 with size 0.001001...
Mode 0 with size 0.493493...
Mode 1 with size 0.352352...
Mode 2 with size 0.121121...
Mode 3 with size 0.033033...
Below are the marginal node distributions representing the partitions that belong to each inferred mode:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment