probinet.models.crep#

Class definition of CRep, the algorithm to perform inference in networks with reciprocity. The latent variables are related to community memberships and reciprocity value [SCDB21].

Classes

CRep([max_iter, num_realizations])

Class to perform inference in networks with reciprocity.

class probinet.models.crep.CRep(max_iter: int = 1000, num_realizations: int = 5, **kwargs: Any)[source]#

Class to perform inference in networks with reciprocity.

check_params_to_load_data(**kwargs)[source]#

Check that the parameters to load the data are correct.

compute_likelihood() float[source]#

Compute the pseudo log-likelihood of the data.

Returns:

loglik – Pseudo log-likelihood value.

Return type:

float

fit(gdata: GraphData, K: int = 3, mask: ndarray | None = None, initialization: int = 0, eta0: float | None = None, undirected: bool = False, assortative: bool = True, constrained: bool = True, out_inference: bool = True, fix_eta: bool = False, fix_w: bool = False, out_folder: Path = PosixPath('outputs'), end_file: str | None = None, files: PathLike | None = None, rng: Generator | None = None, **_kwargs: Any) tuple[ndarray[Any, dtype[float64]], ndarray[Any, dtype[float64]], ndarray[Any, dtype[float64]], float, float][source]#

Fit the CRep models to the given data using the EM algorithm.

Parameters:
  • data – Graph adjacency tensor.

  • data_T – Transposed graph adjacency tensor.

  • data_T_vals – Array with values of entries A[j, i] given non-zero entry (i, j).

  • nodes – List of node IDs.

  • K – Number of communities, by default 3.

  • mask – Mask for selecting the held-out set in the adjacency tensor in case of cross-validation, by default None.

  • initialization – Initialization method for the models parameters, by default 0.

  • eta0 – Initial value of the reciprocity coefficient, by default None.

  • undirected – Flag to specify if the graph is undirected, by default False.

  • assortative – Flag to specify if the graph is assortative, by default True.

  • constrained – Flag to specify if the models is constrained, by default True.

  • out_inference – Flag to specify if inference results should be evaluation, by default True.

  • out_folder – Output folder for inference results, by default “outputs/”.

  • end_file – Suffix for the evaluation file, by default “_CRep”.

  • fix_eta – Flag to specify if the eta parameter should be fixed, by default False.

  • files – Path to the file for initialization, by default “”.

Returns:

  • u_f – Out-going membership matrix.

  • v_f – In-coming membership matrix.

  • w_f – Affinity tensor.

  • eta_f – Reciprocity coefficient.

  • maxL – Maximum pseudo log-likelihood.

load_data(**kwargs: Any)[source]#

Load the data from the input files.

Parameters:
  • files – The directory containing the input files.

  • adj_name – The name of the adjacency file.

  • **kwargs – Additional keyword arguments to pass to the data loading function.

Returns:

The loaded graph data.

Return type:

GraphData