Commit 0ca5f78f authored by Tiago Peixoto's avatar Tiago Peixoto

inference: implement assortative SBMs

parent 32951567
Pipeline #623 passed with stage
in 497 minutes and 4 seconds
......@@ -38,6 +38,9 @@ libgraph_tool_inference_la_SOURCES = \
partition_modes/graph_partition_mode_clustering.cc \
partition_modes/graph_partition_mode_clustering_mcmc.cc \
partition_modes/graph_partition_mode_clustering_multiflip_mcmc.cc \
planted_partition/graph_planted_partition.cc \
planted_partition/graph_planted_partition_mcmc.cc \
planted_partition/graph_planted_partition_multiflip_mcmc.cc \
overlap/graph_blockmodel_overlap.cc \
overlap/graph_blockmodel_overlap_exhaustive.cc \
overlap/graph_blockmodel_overlap_gibbs.cc \
......@@ -110,6 +113,7 @@ nobase_libgraph_tool_inference_la_include_HEADERS = \
partition_centroid/graph_partition_centroid_rmi.hh \
partition_modes/graph_partition_mode.hh \
partition_modes/graph_partition_mode_clustering.hh \
planted_partition/graph_planted_partition.hh \
overlap/graph_blockmodel_overlap.hh \
overlap/graph_blockmodel_overlap_mcmc_bundled.hh \
overlap/graph_blockmodel_overlap_util.hh \
......
......@@ -134,6 +134,9 @@ extern void export_partition_mode();
extern void export_mode_cluster_state();
extern void export_mode_cluster_mcmc();
extern void export_mode_cluster_multiflip_mcmc();
extern void export_pp_state();
extern void export_pp_mcmc();
extern void export_pp_multiflip_mcmc();
BOOST_PYTHON_MODULE(libgraph_tool_inference)
{
......@@ -204,6 +207,9 @@ BOOST_PYTHON_MODULE(libgraph_tool_inference)
export_mode_cluster_state();
export_mode_cluster_mcmc();
export_mode_cluster_multiflip_mcmc();
export_pp_state();
export_pp_mcmc();
export_pp_multiflip_mcmc();
def("vector_map", vector_map<int32_t>);
def("vector_map64", vector_map<int64_t>);
......
// graph-tool -- a general graph modification and manipulation thingy
//
// Copyright (C) 2006-2020 Tiago de Paula Peixoto <tiago@skewed.de>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "graph_tool.hh"
#include "random.hh"
#include <boost/python.hpp>
#include "graph_planted_partition.hh"
#include "../support/graph_state.hh"
using namespace boost;
using namespace graph_tool;
GEN_DISPATCH(block_state, PPState, BLOCK_STATE_params)
python::object make_pp_state(boost::python::object ostate)
{
python::object state;
block_state::make_dispatch(ostate,
[&](auto& s){state = python::object(s);});
return state;
}
void export_pp_state()
{
using namespace boost::python;
def("make_pp_state", &make_pp_state);
block_state::dispatch
([&](auto* s)
{
typedef typename std::remove_reference<decltype(*s)>::type state_t;
void (state_t::*move_vertex)(size_t, size_t) =
&state_t::move_vertex;
double (state_t::*virtual_move)(size_t, size_t, size_t,
const pp_entropy_args_t& ea) =
&state_t::virtual_move;
class_<state_t>
c(name_demangle(typeid(state_t).name()).c_str(),
no_init);
c.def("move_vertex", move_vertex)
.def("virtual_move", virtual_move)
.def("entropy", &state_t::entropy);
});
class_<pp_entropy_args_t>("pp_entropy_args")
.def_readwrite("uniform", &pp_entropy_args_t::uniform)
.def_readwrite("degree_dl_kind", &pp_entropy_args_t::degree_dl_kind);
}
// graph-tool -- a general graph modification and manipulation thingy
//
// Copyright (C) 2006-2020 Tiago de Paula Peixoto <tiago@skewed.de>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "graph_tool.hh"
#include "random.hh"
#include <boost/python.hpp>
#include "graph_planted_partition.hh"
#include "../blockmodel/graph_blockmodel_mcmc.hh"
#include "../loops/mcmc_loop.hh"
using namespace boost;
using namespace graph_tool;
GEN_DISPATCH(block_state, PPState, BLOCK_STATE_params)
template <class State>
GEN_DISPATCH(mcmc_block_state, MCMC<State>::template MCMCBlockState,
MCMC_BLOCK_STATE_params(State))
python::object pp_mcmc_sweep(python::object omcmc_state,
python::object oblock_state,
rng_t& rng)
{
python::object ret;
auto dispatch = [&](auto& block_state)
{
typedef typename std::remove_reference<decltype(block_state)>::type
state_t;
mcmc_block_state<state_t>::make_dispatch
(omcmc_state,
[&](auto& s)
{
auto ret_ = mcmc_sweep(s, rng);
ret = tuple_apply([&](auto&... args){ return python::make_tuple(args...); }, ret_);
});
};
block_state::dispatch(oblock_state, dispatch);
return ret;
}
void export_pp_mcmc()
{
using namespace boost::python;
def("pp_mcmc_sweep", &pp_mcmc_sweep);
}
// graph-tool -- a general graph modification and manipulation thingy
//
// Copyright (C) 2006-2020 Tiago de Paula Peixoto <tiago@skewed.de>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "graph_tool.hh"
#include "random.hh"
#include <boost/python.hpp>
#include "graph_planted_partition.hh"
#include "../blockmodel/graph_blockmodel_multiflip_mcmc.hh"
#include "../loops/mcmc_loop.hh"
using namespace boost;
using namespace graph_tool;
GEN_DISPATCH(block_state, PPState, BLOCK_STATE_params)
template <class State>
GEN_DISPATCH(mcmc_block_state, MCMC<State>::template MCMCBlockState,
MCMC_BLOCK_STATE_params(State))
python::object pp_multiflip_mcmc_sweep(python::object omcmc_state,
python::object oblock_state,
rng_t& rng)
{
python::object ret;
auto dispatch = [&](auto& block_state)
{
typedef typename std::remove_reference<decltype(block_state)>::type
state_t;
mcmc_block_state<state_t>::make_dispatch
(omcmc_state,
[&](auto& s)
{
auto ret_ = mcmc_sweep(s, rng);
ret = tuple_apply([&](auto&... args){ return python::make_tuple(args...); }, ret_);
});
};
block_state::dispatch(oblock_state, dispatch);
return ret;
}
void export_pp_multiflip_mcmc()
{
using namespace boost::python;
def("pp_multiflip_mcmc_sweep", &pp_multiflip_mcmc_sweep);
}
......@@ -77,6 +77,7 @@ graph_tool_inference_PYTHON = \
inference/modularity.py \
inference/partition_centroid.py \
inference/partition_modes.py \
inference/planted_partition.py \
inference/latent_multigraph.py \
inference/util.py
graph_tool_inferencedir = $(MOD_DIR)/inference
......
......@@ -183,6 +183,7 @@ __all__ = ["minimize_blockmodel_dl",
"OverlapBlockState",
"LayeredBlockState",
"NestedBlockState",
"PPBlockState",
"PartitionCentroidState",
"PartitionModeState",
"ModeClusterState",
......@@ -252,3 +253,4 @@ from . modularity import *
from . latent_multigraph import *
from . partition_centroid import *
from . partition_modes import *
from . planted_partition import *
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