probinet.models.dyncrep#

Class definition of DynCRep, the algorithm to perform inference in temporal networks [SCDB22].

Classes

DynCRep([err, num_realizations, max_iter])

Class definition of DynCRep, the algorithm to perform inference in temporal networks with reciprocity.

class probinet.models.dyncrep.DynCRep(err: float = 0.01, num_realizations: int = 1, max_iter: int = 1000, **kwargs)[source]#

Class definition of DynCRep, the algorithm to perform inference in temporal 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 likelihood of the models.

Returns:

loglik – Log-likelihood of the models.

Return type:

float

enforce_constraintU(num: float, den: float) float[source]#

Enforce a constraint on the U matrix during the models fitting process. It uses the root finding algorithm to find the value of lambda that satisfies the constraint.

Parameters:
  • num (float) – The numerator part of the constraint equation.

  • den (float) – The denominator part of the constraint equation.

Returns:

lambda_i – The value of lambda that satisfies the constraint.

Return type:

float

fit(gdata: GraphData, T: int | None = None, mask: ndarray | None = None, K: int = 2, ag: float = 1.0, bg: float = 0.5, eta0: float = None, beta0: float = 0.25, flag_data_T: int = 0, temporal: bool = True, initialization: int = 0, assortative: bool = False, constrained: bool = False, constraintU: bool = False, fix_eta: bool = False, fix_beta: bool = False, fix_communities: bool = False, fix_w: bool = False, undirected: bool = False, out_inference: bool = True, out_folder: Path = PosixPath('outputs'), end_file: str | None = None, files: PathLike | None = None, rng: Generator | None = None, **_kwargs: Any) Tuple[ndarray, ndarray, ndarray, float, ndarray, float][source]#

Model directed networks by using a probabilistic generative models that assumes community parameters and reciprocity coefficient. The inference is performed via the EM algorithm.

Parameters:
  • gdata – Graph adjacency tensor.

  • T – Number of time steps.

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

  • K – Number of communities, by default 2.

  • ag – Shape of gamma prior, by default 1.0.

  • bg – Rate of gamma prior, by default 0.5.

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

  • beta0 – Initial value of the beta parameter, by default 0.25.

  • flag_data_T – Flag to determine which log-likelihood function to use, by default 0.

  • temporal – Flag to determine if the function should behave in a temporal manner, by default True.

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

  • assortative – Flag to indicate if the graph is assortative, by default False.

  • constrained – Flag to indicate if the models is constrained, by default False.

  • constraintU – Flag to indicate if there is a constraint on U, by default False.

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

  • fix_beta – Flag to indicate if the beta parameter should be fixed, by default False.

  • fix_communities – Flag to indicate if the communities should be fixed, by default False.

  • fix_w – Flag to indicate if the w parameter should be fixed, by default False.

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

  • out_inference – Flag to indicate 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 “_DynCRep”.

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

  • rng – Random number generator, by default None.

  • **kwargs – Additional parameters for the model.

Returns:

  • u_f – Out-going membership matrix.

  • v_f – In-coming membership matrix.

  • w_f – Affinity tensor.

  • eta_f – Reciprocity coefficient.

  • beta_f – Beta parameter.

  • maxL – Maximum pseudo log-likelihood.

func_beta_static(beta_t: float) float[source]#

Calculate the value of beta at time t for the static models.

Parameters:

beta_t (float) – The value of beta at time t.

Returns:

bt – The calculated value of beta at time t for the static models.

Return type:

float

get_params_to_load_data(args: Namespace) Dict[str, Any][source]#

Get the parameters from the arguments.

Parameters:

args (Namespace) – The arguments.

Returns:

params – The parameters.

Return type:

Dict[str, Any]