Commit 50fb2c31 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Refactor stochastic blockmodel inference

This greatly improves the performance of the previous algorithm, and
includes support for hierarchical models.
parent ae9857c0
.. automodule:: graph_tool.community
:members:
:undoc-members:
:member-order: "bysource"
\ No newline at end of file
:no-members:
:no-undoc-members:
.. autofunction:: minimize_blockmodel_dl
.. autoclass:: BlockState
.. autofunction:: mcmc_sweep
.. autoclass:: MinimizeState
.. autofunction:: multilevel_minimize
.. autofunction:: collect_edge_marginals
.. autofunction:: collect_vertex_marginals
.. autofunction:: mf_entropy
.. autofunction:: bethe_entropy
.. autofunction:: model_entropy
.. autofunction:: get_max_B
.. autofunction:: get_akc
.. autofunction:: condensation_graph
.. autofunction:: minimize_nested_blockmodel_dl
.. autoclass:: NestedBlockState
.. autoclass:: NestedMinimizeState
.. autofunction:: init_nested_state
.. autofunction:: nested_mcmc_sweep
.. autofunction:: nested_tree_sweep
.. autofunction:: get_hierarchy_tree
.. autofunction:: community_structure
.. autofunction:: modularity
This diff is collapsed.
This diff is collapsed.
......@@ -155,15 +155,31 @@ struct get_community_network_edges
if (ct == cs && !self_loops)
continue;
cedge_t ce;
if (comm_edges.find(make_pair(cs, ct)) != comm_edges.end())
ce = comm_edges[make_pair(cs, ct)];
else if (!is_directed::apply<Graph>::type::value &&
comm_edges.find(make_pair(ct, cs)) != comm_edges.end())
ce = comm_edges[make_pair(ct, cs)];
typeof(comm_edges.begin()) iter = comm_edges.find(make_pair(cs, ct));
if (iter != comm_edges.end())
{
ce = iter->second;
}
else
{
ce = add_edge(cs, ct, cg).first;
comm_edges[make_pair(cs, ct)] = ce;
if (!is_directed::apply<Graph>::type::value)
{
iter = comm_edges.find(make_pair(ct, cs));
if (iter != comm_edges.end())
{
ce = iter->second;
}
else
{
ce = add_edge(cs, ct, cg).first;
comm_edges[make_pair(cs, ct)] = ce;
}
}
else
{
ce = add_edge(cs, ct, cg).first;
comm_edges[make_pair(cs, ct)] = ce;
}
}
put(edge_count, ce, get(edge_count, ce) + get(eweight, *e));
}
......
......@@ -63,7 +63,8 @@ graph_tool_centralitydir = $(MOD_DIR)/centrality
graph_tool_community_PYTHON = \
community/__init__.py \
community/blockmodel.py
community/blockmodel.py \
community/nested_blockmodel.py
graph_tool_communitydir = $(MOD_DIR)/community
graph_tool_draw_PYTHON = \
......
......@@ -29,8 +29,11 @@ graphs.
Stochastic blockmodel inference
+++++++++++++++++++++++++++++++
Non-hierarchical models
=======================
Summary
=======
^^^^^^^
.. autosummary::
:nosignatures:
......@@ -38,6 +41,8 @@ Summary
minimize_blockmodel_dl
BlockState
mcmc_sweep
MinimizeState
multilevel_minimize
collect_vertex_marginals
collect_edge_marginals
mf_entropy
......@@ -45,9 +50,25 @@ Summary
model_entropy
get_max_B
get_akc
min_dist
condensation_graph
Hierarchical models
===================
Summary
^^^^^^^
.. autosummary::
:nosignatures:
minimize_nested_blockmodel_dl
NestedBlockState
NestedMinimizeState
init_nested_state
nested_mcmc_sweep
nested_tree_sweep
get_hierarchy_tree
Modularity-based community detection
++++++++++++++++++++++++++++++++++++
......@@ -72,21 +93,41 @@ if sys.version_info < (3,):
range = xrange
from .. dl_import import dl_import
dl_import("from . import libgraph_tool_community")
#dl_import("from . import libgraph_tool_community")
from .. import _degree, _prop, Graph, GraphView, libcore, _get_rng
import random
import sys
__all__ = ["minimize_blockmodel_dl", "BlockState", "mcmc_sweep",
"collect_edge_marginals", "collect_vertex_marginals",
"bethe_entropy", "mf_entropy", "model_entropy", "get_max_B",
"get_akc", "min_dist", "condensation_graph", "community_structure",
__all__ = ["minimize_blockmodel_dl",
"BlockState",
"mcmc_sweep",
"MinimizeState",
"multilevel_minimize",
"collect_edge_marginals",
"collect_vertex_marginals",
"mf_entropy",
"bethe_entropy",
"model_entropy",
"get_max_B",
"get_akc",
"condensation_graph",
"minimize_nested_blockmodel_dl",
"NestedBlockState",
"NestedMinimizeState",
"init_nested_state",
"nested_mcmc_sweep",
"nested_tree_sweep",
"get_hierarchy_tree",
"community_structure",
"modularity"]
from . blockmodel import minimize_blockmodel_dl, BlockState, mcmc_sweep, \
model_entropy, get_max_B, get_akc, min_dist, condensation_graph, \
collect_edge_marginals, collect_vertex_marginals, bethe_entropy, mf_entropy
multilevel_minimize, model_entropy, get_max_B, get_akc, condensation_graph, \
collect_edge_marginals, collect_vertex_marginals, bethe_entropy, mf_entropy, MinimizeState
from . nested_blockmodel import NestedBlockState, NestedMinimizeState, init_nested_state, \
nested_mcmc_sweep, nested_tree_sweep, minimize_nested_blockmodel_dl, get_hierarchy_tree
def community_structure(g, n_iter, n_spins, gamma=1.0, corr="erdos",
spins=None, weight=None, t_range=(100.0, 0.01),
......
This diff is collapsed.
This diff is collapsed.
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