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_enginestr (required, default: "engines/bipartiteSBM-KL/biSBM")
n_sweepsint (required, default: 4)

Note that this will generate <n_sweeps> output sub-folders in <f_kl_output>.

is_parallelbool (required, default: True)
n_coresint (required, default: 4)
algm_namestr (required, default: kl)
kl_edgelist_delimiterstr (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_stepsint (required, default: 5)

Number of random initializations (refer to the README_cplusplus.txt file)

kl_itertimesint (required, default: 1)

Number of KL runs (within each <outputFOLDER>) for returning an optimal result.

f_kl_outputstr (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_verbosebool (required, default: True)
kl_is_parallelbool (required, default: False)
engine(self, f_edgelist, na, nb, ka, kb, mb=None)[source]

Run the shell code.

Parameters
kaint (required)

Number of communities for type-a nodes to partition.

kbint (required)

Number of communities for type-b nodes to partition.

Returns
of_grouplist[int]
static gen_types(na, nb)[source]
prepare_engine(self, f_edgelist, na, nb, ka, kb, delimiter=None)[source]

Output shell commands for graph partitioning calculation.

Parameters
kaint (required)

Number of communities for type-a nodes to partition.

kbint (required)

Number of communities for type-b nodes to partition.

Returns
action_strstr

The command line string that enables execution of the code.

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_enginestr (required, default: “engines/bipartiteSBM-MCMC/bin/mcmc”)

Path to the graph partitioning binary.

n_sweepsint (required, default: 1)

Number of partitioning computations for each \((K_a, K_b)\) data point.

is_parallelbool (required, default: False)

Whether to compute the partitioning in parallel.

n_coresint (required, default: 1)

The number of cores used when is_parallel is True.

algm_namestr (required, default: mcmc)

The name of the algorithm.

mcmc_stepsint (required, default: 1e5)

Number of sweeps to perform. During each sweep, a move attempt is made for each node.

mcmc_await_stepsint (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_coolingstr (required, default: abrupt_cool)

Annealing scheme used, which can be either exponential, logarithm, linear, constant, or abrupt_cool.

mcmc_cooling_param_1int (required, default: 1e3)

Parameter 1 for the annealing.

mcmc_cooling_param_2float (required, default: 0.1)

Parameter 2 for the annealing.

mcmc_epsilonfloat (required, default: 1.)

The \(\epsilon\) parameter used in the proposal moves.

engine(self, f_edgelist, na, nb, ka, kb, mb=None, method=None)[source]

Run the shell code.

Parameters
f_edgeliststr
naint
nbint
kaint, required

Number of communities for type-a nodes to partition.

kbint, required

Number of communities for type-b nodes to partition.

mbnumpy.ndarray
method :
Returns
of_groupnumpy.ndarray
static gen_types(na, nb)[source]
prepare_engine(self, f_edgelist, na, nb, ka, kb, mb=None, method=None)[source]

Output shell commands for graph partitioning calculation.

Parameters
kaint (required)

Number of communities for type-a nodes to partition.

kbint (required)

Number of communities for type-b nodes to partition.

Returns
action_strstr

the command line string that enables execution of the code

set_await_steps(self, await_steps)[source]
set_cooling(self, cooling)[source]
set_cooling_param_1(self, cooling_param_1)[source]
set_cooling_param_2(self, cooling_param_2)[source]
set_epsilon(self, epsilon)[source]
set_steps(self, steps)[source]

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_enginestr (required, default: "engines/bipartiteSBM-KL/biSBM")
n_sweepsint (required, default: 4)

Note that this will generate <n_sweeps> output sub-folders in <f_kl_output>.

is_parallelbool (required, default: True)
n_coresint (required, default: 4)
algm_namestr (required, default: kl)
kl_edgelist_delimiterstr (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_stepsint (required, default: 5)

Number of random initializations (refer to the README_cplusplus.txt file)

kl_itertimesint (required, default: 1)

Number of KL runs (within each <outputFOLDER>) for returning an optimal result.

f_kl_outputstr (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_verbosebool (required, default: True)
kl_is_parallelbool (required, default: False)
engine(self, f_edgelist, na, nb, ka, kb, mb=None)[source]

Run the shell code.

Parameters
kaint (required)

Number of communities for type-a nodes to partition.

kbint (required)

Number of communities for type-b nodes to partition.

Returns
of_grouplist[int]
static gen_types(na, nb)[source]
prepare_engine(self, f_edgelist, na, nb, ka, kb, delimiter=None)[source]

Output shell commands for graph partitioning calculation.

Parameters
kaint (required)

Number of communities for type-a nodes to partition.

kbint (required)

Number of communities for type-b nodes to partition.

Returns
action_strstr

The command line string that enables execution of the code.

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_enginestr (required, default: “engines/bipartiteSBM-MCMC/bin/mcmc”)

Path to the graph partitioning binary.

n_sweepsint (required, default: 1)

Number of partitioning computations for each \((K_a, K_b)\) data point.

is_parallelbool (required, default: False)

Whether to compute the partitioning in parallel.

n_coresint (required, default: 1)

The number of cores used when is_parallel is True.

algm_namestr (required, default: mcmc)

The name of the algorithm.

mcmc_stepsint (required, default: 1e5)

Number of sweeps to perform. During each sweep, a move attempt is made for each node.

mcmc_await_stepsint (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_coolingstr (required, default: abrupt_cool)

Annealing scheme used, which can be either exponential, logarithm, linear, constant, or abrupt_cool.

mcmc_cooling_param_1int (required, default: 1e3)

Parameter 1 for the annealing.

mcmc_cooling_param_2float (required, default: 0.1)

Parameter 2 for the annealing.

mcmc_epsilonfloat (required, default: 1.)

The \(\epsilon\) parameter used in the proposal moves.

engine(self, f_edgelist, na, nb, ka, kb, mb=None, method=None)[source]

Run the shell code.

Parameters
f_edgeliststr
naint
nbint
kaint, required

Number of communities for type-a nodes to partition.

kbint, required

Number of communities for type-b nodes to partition.

mbnumpy.ndarray
method :
Returns
of_groupnumpy.ndarray
static gen_types(na, nb)[source]
prepare_engine(self, f_edgelist, na, nb, ka, kb, mb=None, method=None)[source]

Output shell commands for graph partitioning calculation.

Parameters
kaint (required)

Number of communities for type-a nodes to partition.

kbint (required)

Number of communities for type-b nodes to partition.

Returns
action_strstr

the command line string that enables execution of the code

set_await_steps(self, await_steps)[source]
set_cooling(self, cooling)[source]
set_cooling_param_1(self, cooling_param_1)[source]
set_cooling_param_2(self, cooling_param_2)[source]
set_epsilon(self, epsilon)[source]
set_steps(self, steps)[source]