Commit 83db893e authored by Tiago Peixoto's avatar Tiago Peixoto

Update documentation

parent 9bbcb771
Pipeline #564 failed with stage
in 298 minutes and 7 seconds
......@@ -117,8 +117,14 @@ the weights, as follows:
state = gt.minimize_nested_blockmodel_dl(g, state_args=dict(recs=[g.ep.weight],
rec_types=["discrete-binomial"]))
# improve solution with merge-split
state = state.copy(bs=state.get_bs() + [np.zeros(1)] * 4, sampling=True)
for i in range(100):
ret = state.multiflip_mcmc_sweep(niter=10, beta=np.inf)
state.draw(edge_color=g.ep.weight, ecmap=(matplotlib.cm.inferno, .6),
eorder=g.ep.weight, edge_pen_width=gt.prop_to_size(g.ep.weight, 1, 4, power=1),
eorder=g.ep.weight, edge_pen_width=gt.prop_to_size(g.ep.weight, 2, 8, power=1),
edge_gradient=[], output="moreno-train-wsbm.pdf")
.. testcleanup:: weighted-model
......@@ -171,6 +177,13 @@ follows:
state = gt.minimize_nested_blockmodel_dl(g, state_args=dict(recs=[g.ep.weight],
rec_types=["real-exponential"]))
# improve solution with merge-split
state = state.copy(bs=state.get_bs() + [np.zeros(1)] * 4, sampling=True)
for i in range(100):
ret = state.multiflip_mcmc_sweep(niter=10, beta=np.inf)
state.draw(edge_color=gt.prop_to_size(g.ep.weight, power=1, log=True), ecmap=(matplotlib.cm.inferno, .6),
eorder=g.ep.weight, edge_pen_width=gt.prop_to_size(g.ep.weight, 1, 4, power=1, log=True),
edge_gradient=[], output="foodweb-wsbm.pdf")
......@@ -210,6 +223,12 @@ can fit this alternative model simply by using the transformed weights:
state_ln = gt.minimize_nested_blockmodel_dl(g, state_args=dict(recs=[y],
rec_types=["real-normal"]))
# improve solution with merge-split
state_ln = state.copy(bs=state.get_bs() + [np.zeros(1)] * 4, sampling=True)
for i in range(100):
ret = state_ln.multiflip_mcmc_sweep(niter=10, beta=np.inf)
state_ln.draw(edge_color=gt.prop_to_size(g.ep.weight, power=1, log=True), ecmap=(matplotlib.cm.inferno, .6),
eorder=g.ep.weight, edge_pen_width=gt.prop_to_size(g.ep.weight, 1, 4, power=1, log=True),
edge_gradient=[], output="foodweb-wsbm-lognormal.pdf")
......@@ -257,12 +276,12 @@ Therefore, we can compute the posterior odds ratio between both models as:
.. testoutput:: food-web
:options: +NORMALIZE_WHITESPACE
ln Λ: -16.814693...
ln Λ: 16490.463643...
A value of :math:`\Lambda \approx \mathrm{e}^{-17} \approx 10^{-7}` in
favor the exponential model indicates that the log-normal model does not
provide a better fit for this particular data. Based on this, we
conclude that the exponential model should be preferred in this case.
A value of :math:`\Lambda \approx \mathrm{e}^{16490} \approx 10^{7161}`
in favor the log-normal model indicates that the exponential model does
not provide a better fit for this particular data. Based on this, we
conclude that the log-normal model should be preferred in this case.
Posterior sampling
......@@ -270,16 +289,12 @@ Posterior sampling
The procedure to sample from the posterior distribution is identical to
what is described in Sec. :ref:`sampling`, but with the appropriate
initialization, i.e.
initialization, e.g..
.. testcode:: weighted-model
state = gt.BlockState(g, B=20, recs=[g.ep.weight], rec_types=["discrete-poisson"])
or for the nested model
g = gt.collection.konect_data["foodweb-baywet"]
.. testcode:: weighted-model
state = gt.NestedBlockState(g, state_args=dict(recs=[g.ep.weight], rec_types=["real-exponential"]))
state = gt.NestedBlockState(g, bs=[np.random.randint(0, 20, g.num_vertices())] + [zeros(1)] * 10,
state_args=dict(recs=[g.ep.weight],
rec_types=["discrete-poisson"]))
gt.mcmc_equilibrate(state, force_niter=100, mcmc_args=dict(niter=10))
......@@ -277,4 +277,38 @@ implements `simulated annealing
Any of the above methods should give similar results to the previous
algorithms, while requiring less memory. In terms of quality of the
results, it will vary depending on the data, thus experimentation is
recommended.
\ No newline at end of file
recommended.
.. note::
Note that both approaches above can be combined, where the
agglomerative algorithm of
:func:`~graph_tool.inference.minimize.minimize_blockmodel_dl` or
:func:`~graph_tool.inference.minimize.minimize_nested_blockmodel_dl`
is used to find an initial solution, which is then improved via a
greedy merge-split MCMC, e.g.
.. testcode:: celegans-mcmc-combine
g = gt.collection.data["celegansneural"]
state = gt.minimize_nested_blockmodel_dl(g)
S1 = state.entropy()
# we will pad the hierarchy with another four empty levels, to
# give it room to potentially increase
state = state.copy(bs=state.get_bs() + [np.zeros(1)] * 4,
sampling = True)
for i in range(100):
ret = state.multiflip_mcmc_sweep(niter=10, beta=np.inf)
S2 = state.entropy()
print("Improvement:", S2 - S1)
.. testoutput:: celegans-mcmc-combine
Improvement: -82.616161...
\ No newline at end of file
......@@ -154,8 +154,8 @@ evidence efficiently, as we show below, using
.. testoutput:: model-evidence
Model evidence for deg_corr = True: -383.7870425700103 (mean field), -1053.691486781025 (Bethe)
Model evidence for deg_corr = False: -364.121582158287 (mean field), -945.9676904776013 (Bethe)
Model evidence for deg_corr = True: -383.787042... (mean field), -1053.691486... (Bethe)
Model evidence for deg_corr = False: -363.454006... (mean field), -948.144381... (Bethe)
If we consider the more accurate approximation, the outcome shows a
preference for the non-degree-corrected model.
......@@ -219,8 +219,8 @@ approach for the same network, using the nested model.
.. testoutput:: model-evidence
Model evidence for deg_corr = True: -189.190149... (mean field), -844.518064... (Bethe)
Model evidence for deg_corr = False: -177.192565... (mean field), -727.585051... (Bethe)
Model evidence for deg_corr = True: -183.999497... (mean field), -840.108164... (Bethe)
Model evidence for deg_corr = False: -187.344952... (mean field), -738.797625... (Bethe)
The results are similar: If we consider the most accurate approximation,
the non-degree-corrected model possesses the largest evidence. Note also
......
......@@ -25,9 +25,9 @@ we have
.. testoutput:: model-selection
:options: +NORMALIZE_WHITESPACE
Non-degree-corrected DL: 8553.474528...
Degree-corrected DL: 8266.554118...
Non-degree-corrected DL: 8520.825480...
Degree-corrected DL: 8227.987410...
Since it yields the smallest description length, the degree-corrected
fit should be preferred. The statistical significance of the choice can
be accessed by inspecting the posterior odds ratio
......@@ -52,7 +52,7 @@ fits. In our particular case, we have
.. testoutput:: model-selection
:options: +NORMALIZE_WHITESPACE
ln Λ: -286.92041...
ln Λ: -292.838070...
The precise threshold that should be used to decide when to `reject a
hypothesis <https://en.wikipedia.org/wiki/Hypothesis_testing>`_ is
......@@ -80,11 +80,11 @@ example, for the American football network above, we have:
.. testoutput:: model-selection
:options: +NORMALIZE_WHITESPACE
Non-degree-corrected DL: 1738.138494...
Degree-corrected DL: 1780.576716...
ln Λ: -42.4382219...
Non-degree-corrected DL: 1757.843826...
Degree-corrected DL: 1809.861996...
ln Λ: -52.018170...
Hence, with a posterior odds ratio of :math:`\Lambda \approx \mathrm{e}^{-42} \approx
10^{-18}` in favor of the non-degree-corrected model, we conclude that the
Hence, with a posterior odds ratio of :math:`\Lambda \approx \mathrm{e}^{-52} \approx
10^{-22}` in favor of the non-degree-corrected model, we conclude that the
degree-corrected variant is an unnecessarily complex description for
this network.
......@@ -67,7 +67,8 @@ References
(2015). :doi:`10.1093/comnet/cnu026`, :arxiv:`1404.0431`
.. [peixoto-weighted-2017] Tiago P. Peixoto, "Nonparametric weighted
stochastic block models", :arxiv:`1708.01432`
stochastic block models", Phys. Rev. E 97, 012306 (2018),
:doi:`10.1103/PhysRevE.97.012306`, :arxiv:`1708.01432`
.. [peixoto-efficient-2014] Tiago P. Peixoto, "Efficient Monte Carlo and
greedy heuristic for the inference of stochastic block models", Phys.
......
......@@ -1088,7 +1088,8 @@ class BlockState(object):
Phys. Rev. X 4, 011047 (2014), :doi:`10.1103/PhysRevX.4.011047`,
:arxiv:`1310.4377`.
.. [peixoto-weighted-2017] Tiago P. Peixoto, "Nonparametric weighted
stochastic block models", :arxiv:`1708.01432`
stochastic block models", Phys. Rev. E 97, 012306 (2018),
:doi:`10.1103/PhysRevE.97.012306`, :arxiv:`1708.01432`
"""
......
......@@ -1093,8 +1093,8 @@ class EpidemicsBlockState(DynamicsBlockStateBase):
References
----------
.. [peixoto-network-2019] Tiago P. Peixoto, "Network reconstruction and
community detection from dynamics", :arxiv:`1903.10833`
community detection from dynamics", Phys. Rev. Lett. 123 128301
(2019), :doi:`10.1103/PhysRevLett.123.128301`, :arxiv:`1903.10833`
"""
if beta is None:
......@@ -1295,7 +1295,8 @@ class IsingBaseBlockState(DynamicsBlockStateBase):
References
----------
.. [peixoto-network-2019] Tiago P. Peixoto, "Network reconstruction and
community detection from dynamics", :arxiv:`1903.10833`
community detection from dynamics", Phys. Rev. Lett. 123 128301
(2019), :doi:`10.1103/PhysRevLett.123.128301`, :arxiv:`1903.10833`
"""
......
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