engines package¶
Module contents¶
engines
- Inference engines of the bipartite stochastic block model¶
This module contains the wrappers for the binaries that identifies the large-scale network structure via the statistical inference of the bipartite stochastic block model.
Note
TODO.
-
class
engines.
KL
(f_engine='engines/bipartiteSBM-KL/biSBM', n_sweeps=1, is_parallel=False, n_cores=1, algm_name='kl', kl_edgelist_delimiter='t', kl_steps=5, kl_itertimes=1, f_kl_output='engines/bipartiteSBM-KL/f_kl_output', kl_verbose=True, kl_is_parallel=False)[source]¶ Bases:
object
Base class for the Kernighan-Lin algorithm.
- Parameters
- f_engine
str
(required, default:"engines/bipartiteSBM-KL/biSBM"
) - n_sweeps
int
(required, default:4
) Note that this will generate
<n_sweeps>
output sub-folders in<f_kl_output>
.- is_parallel
bool
(required, default:True
) - n_cores
int
(required, default:4
) - algm_name
str
(required, default:kl
) - kl_edgelist_delimiter
str
(required, default:"\t"
) Due to the KL code accepts 1-indexed nodes by default, we used the delimiter to transform our 0-indexed input.
- kl_steps
int
(required, default:5
) Number of random initializations (refer to the README_cplusplus.txt file)
- kl_itertimes
int
(required, default:1
) Number of KL runs (within each
<outputFOLDER>
) for returning an optimal result.- f_kl_output
str
(required, default:"engines/bipartiteSBM-KL/f_kl_output"
) Path to the KL output dir; recommended to be in the same folder as the binary.
- kl_verbose
bool
(required, default:True
) - kl_is_parallel
bool
(required, default:False
)
- f_engine
-
engine
(self, f_edgelist, na, nb, ka, kb, mb=None)[source]¶ Run the shell code.
- Parameters
- ka
int
(required) Number of communities for type-a nodes to partition.
- kb
int
(required) Number of communities for type-b nodes to partition.
- ka
- Returns
- of_group
list[int]
- of_group
-
prepare_engine
(self, f_edgelist, na, nb, ka, kb, delimiter=None)[source]¶ Output shell commands for graph partitioning calculation.
- Parameters
- ka
int
(required) Number of communities for type-a nodes to partition.
- kb
int
(required) Number of communities for type-b nodes to partition.
- ka
- Returns
- action_str
str
The command line string that enables execution of the code.
- action_str
-
class
engines.
MCMC
(f_engine='engines/bipartiteSBM-MCMC/bin/mcmc', n_sweeps=1, is_parallel=False, n_cores=1, algm_name='mcmc', mcmc_steps=100000.0, mcmc_await_steps=2000.0, mcmc_cooling='abrupt_cool', mcmc_cooling_param_1=1000.0, mcmc_cooling_param_2=0.1, mcmc_epsilon=1.0)[source]¶ Bases:
object
Base class for the Markov chain Monte Carlo algorithm.
- Parameters
- f_engine
str
(required, default: “engines/bipartiteSBM-MCMC/bin/mcmc”) Path to the graph partitioning binary.
- n_sweeps
int
(required, default: 1) Number of partitioning computations for each \((K_a, K_b)\) data point.
- is_parallel
bool
(required, default: False) Whether to compute the partitioning in parallel.
- n_cores
int
(required, default: 1) The number of cores used when is_parallel is True.
- algm_name
str
(required, default: mcmc) The name of the algorithm.
- mcmc_steps
int
(required, default: 1e5) Number of sweeps to perform. During each sweep, a move attempt is made for each node.
- mcmc_await_steps
int
(required, default: 2e3) Number of iterations to wait for a record-breaking event. The algorithm will stop if there is no record-breaking event within the interval or the overall MCMC sweeps exceed
mcmc_steps
, whichever happens earlier.- mcmc_cooling
str
(required, default: abrupt_cool) Annealing scheme used, which can be either
exponential
,logarithm
,linear
,constant
, orabrupt_cool
.- mcmc_cooling_param_1
int
(required, default: 1e3) Parameter 1 for the annealing.
- mcmc_cooling_param_2
float
(required, default: 0.1) Parameter 2 for the annealing.
- mcmc_epsilon
float
(required, default: 1.) The \(\epsilon\) parameter used in the proposal moves.
- f_engine
-
engine
(self, f_edgelist, na, nb, ka, kb, mb=None, method=None)[source]¶ Run the shell code.
- Parameters
- f_edgelist
str
- na
int
- nb
int
- ka
int
, required Number of communities for type-a nodes to partition.
- kb
int
, required Number of communities for type-b nodes to partition.
- mb
numpy.ndarray
- method :
- f_edgelist
- Returns
- of_group
numpy.ndarray
- of_group
-
prepare_engine
(self, f_edgelist, na, nb, ka, kb, mb=None, method=None)[source]¶ Output shell commands for graph partitioning calculation.
- Parameters
- ka
int
(required) Number of communities for type-a nodes to partition.
- kb
int
(required) Number of communities for type-b nodes to partition.
- ka
- Returns
- action_str
str
the command line string that enables execution of the code
- action_str
engines.kl module¶
-
class
engines.kl.
KL
(f_engine='engines/bipartiteSBM-KL/biSBM', n_sweeps=1, is_parallel=False, n_cores=1, algm_name='kl', kl_edgelist_delimiter='t', kl_steps=5, kl_itertimes=1, f_kl_output='engines/bipartiteSBM-KL/f_kl_output', kl_verbose=True, kl_is_parallel=False)[source]¶ Bases:
object
Base class for the Kernighan-Lin algorithm.
- Parameters
- f_engine
str
(required, default:"engines/bipartiteSBM-KL/biSBM"
) - n_sweeps
int
(required, default:4
) Note that this will generate
<n_sweeps>
output sub-folders in<f_kl_output>
.- is_parallel
bool
(required, default:True
) - n_cores
int
(required, default:4
) - algm_name
str
(required, default:kl
) - kl_edgelist_delimiter
str
(required, default:"\t"
) Due to the KL code accepts 1-indexed nodes by default, we used the delimiter to transform our 0-indexed input.
- kl_steps
int
(required, default:5
) Number of random initializations (refer to the README_cplusplus.txt file)
- kl_itertimes
int
(required, default:1
) Number of KL runs (within each
<outputFOLDER>
) for returning an optimal result.- f_kl_output
str
(required, default:"engines/bipartiteSBM-KL/f_kl_output"
) Path to the KL output dir; recommended to be in the same folder as the binary.
- kl_verbose
bool
(required, default:True
) - kl_is_parallel
bool
(required, default:False
)
- f_engine
-
engine
(self, f_edgelist, na, nb, ka, kb, mb=None)[source]¶ Run the shell code.
- Parameters
- ka
int
(required) Number of communities for type-a nodes to partition.
- kb
int
(required) Number of communities for type-b nodes to partition.
- ka
- Returns
- of_group
list[int]
- of_group
-
prepare_engine
(self, f_edgelist, na, nb, ka, kb, delimiter=None)[source]¶ Output shell commands for graph partitioning calculation.
- Parameters
- ka
int
(required) Number of communities for type-a nodes to partition.
- kb
int
(required) Number of communities for type-b nodes to partition.
- ka
- Returns
- action_str
str
The command line string that enables execution of the code.
- action_str
engines.mcmc module¶
-
class
engines.mcmc.
MCMC
(f_engine='engines/bipartiteSBM-MCMC/bin/mcmc', n_sweeps=1, is_parallel=False, n_cores=1, algm_name='mcmc', mcmc_steps=100000.0, mcmc_await_steps=2000.0, mcmc_cooling='abrupt_cool', mcmc_cooling_param_1=1000.0, mcmc_cooling_param_2=0.1, mcmc_epsilon=1.0)[source]¶ Bases:
object
Base class for the Markov chain Monte Carlo algorithm.
- Parameters
- f_engine
str
(required, default: “engines/bipartiteSBM-MCMC/bin/mcmc”) Path to the graph partitioning binary.
- n_sweeps
int
(required, default: 1) Number of partitioning computations for each \((K_a, K_b)\) data point.
- is_parallel
bool
(required, default: False) Whether to compute the partitioning in parallel.
- n_cores
int
(required, default: 1) The number of cores used when is_parallel is True.
- algm_name
str
(required, default: mcmc) The name of the algorithm.
- mcmc_steps
int
(required, default: 1e5) Number of sweeps to perform. During each sweep, a move attempt is made for each node.
- mcmc_await_steps
int
(required, default: 2e3) Number of iterations to wait for a record-breaking event. The algorithm will stop if there is no record-breaking event within the interval or the overall MCMC sweeps exceed
mcmc_steps
, whichever happens earlier.- mcmc_cooling
str
(required, default: abrupt_cool) Annealing scheme used, which can be either
exponential
,logarithm
,linear
,constant
, orabrupt_cool
.- mcmc_cooling_param_1
int
(required, default: 1e3) Parameter 1 for the annealing.
- mcmc_cooling_param_2
float
(required, default: 0.1) Parameter 2 for the annealing.
- mcmc_epsilon
float
(required, default: 1.) The \(\epsilon\) parameter used in the proposal moves.
- f_engine
-
engine
(self, f_edgelist, na, nb, ka, kb, mb=None, method=None)[source]¶ Run the shell code.
- Parameters
- f_edgelist
str
- na
int
- nb
int
- ka
int
, required Number of communities for type-a nodes to partition.
- kb
int
, required Number of communities for type-b nodes to partition.
- mb
numpy.ndarray
- method :
- f_edgelist
- Returns
- of_group
numpy.ndarray
- of_group
-
prepare_engine
(self, f_edgelist, na, nb, ka, kb, mb=None, method=None)[source]¶ Output shell commands for graph partitioning calculation.
- Parameters
- ka
int
(required) Number of communities for type-a nodes to partition.
- kb
int
(required) Number of communities for type-b nodes to partition.
- ka
- Returns
- action_str
str
the command line string that enables execution of the code
- action_str