probinet.evaluation.likelihood#
This module provides functions for computing the log-likelihood and pseudo log-likelihood of the models, as well as other related calculations.
Functions
|
Compute the pseudo log-likelihood of the data. |
|
Compute the optimal value for the pseudo log-likelihood with the inferred parameters. |
|
Compute the log-likelihood of the data given the parameters. |
|
Calculate the log-likelihood of the model considering only the structural data. |
|
Return the log-likelihood of the model. |
|
Compute the log-likelihood for the attributes. |
|
Compute the log-likelihood for the network structure. |
- probinet.evaluation.likelihood.PSloglikelihood(B: ndarray, u: ndarray, v: ndarray, w: ndarray, eta: float, mask: ndarray | None = None) float [source]#
Compute the pseudo log-likelihood of the data.
- Parameters:
B (np.ndarray) – Graph adjacency tensor.
u (np.ndarray) – Out-going membership matrix.
v (np.ndarray) – In-coming membership matrix.
w (np.ndarray) – Affinity tensor.
eta (float) – Reciprocity coefficient.
mask (Optional[np.ndarray]) – Mask for selecting the held out set in the adjacency tensor in case of cross-validation.
- Returns:
Pseudo log-likelihood value.
- Return type:
float
- probinet.evaluation.likelihood.calculate_opt_func(B: ndarray, algo_obj, mask: ndarray | None = None, assortative: bool = False) float [source]#
Compute the optimal value for the pseudo log-likelihood with the inferred parameters.
- Parameters:
B (np.ndarray) – Graph adjacency tensor.
algo_obj (object) – The CRep object.
mask (Optional[np.ndarray]) – Mask for selecting a subset of the adjacency tensor.
assortative (bool) – Flag to use an assortative mode.
- Returns:
Maximum pseudo log-likelihood value.
- Return type:
float
- probinet.evaluation.likelihood.likelihood_conditional(M: ndarray, beta: float, data: ndarray, data_tm1: ndarray, EPS: float | None = 1e-10) float [source]#
Compute the log-likelihood of the data given the parameters.
- Parameters:
M (np.ndarray) – Matrix of expected values.
beta (float) – Rate of edge removal.
data (np.ndarray) – Current adjacency tensor.
data_tm1 (np.ndarray) – Previous adjacency tensor.
EPS (float, optional) – Small constant to prevent division by zero and log of zero.
- Returns:
Log-likelihood value.
- Return type:
float
- probinet.evaluation.likelihood.log_likelihood_given_model(model: object, adjacency_tensor: ndarray) float [source]#
Calculate the log-likelihood of the model considering only the structural data.
- Parameters:
model (object) – The model object containing the lambda0_ija and lambda0_nz attributes.
adjacency_tensor (np.ndarray) – The adjacency matrix.
- Returns:
The log-likelihood value, rounded to three decimal places.
- Return type:
float
- probinet.evaluation.likelihood.loglikelihood(B: ndarray, X: DataFrame, u: ndarray, v: ndarray, w: ndarray, beta: ndarray, gamma: float, maskG: ndarray | None = None, maskX: ndarray | None = None) float [source]#
Return the log-likelihood of the model.
- Parameters:
B (np.ndarray) – Graph adjacency tensor.
X (pd.DataFrame) – Pandas DataFrame object representing the one-hot encoding version of the design matrix.
u (np.ndarray) – Membership matrix (out-degree).
v (np.ndarray) – Membership matrix (in-degree).
w (np.ndarray) – Affinity tensor.
beta (np.ndarray) – Beta parameter matrix.
gamma (float) – Scaling parameter gamma.
maskG (Optional[np.ndarray]) – Mask for selecting a subset in the adjacency tensor.
maskX (Optional[np.ndarray]) – Mask for selecting a subset in the design matrix.
- Returns:
Log-likelihood value.
- Return type:
float
- probinet.evaluation.likelihood.loglikelihood_attributes(X: DataFrame, u: ndarray, v: ndarray, beta: ndarray, mask: ndarray | None = None) float [source]#
Compute the log-likelihood for the attributes.
- Parameters:
X (pd.DataFrame) – Pandas DataFrame object representing the one-hot encoding version of the design matrix.
u (np.ndarray) – Membership matrix (out-degree).
v (np.ndarray) – Membership matrix (in-degree).
beta (np.ndarray) – Beta parameter matrix.
mask (Optional[np.ndarray]) – Mask for selecting a subset in the design matrix.
- Returns:
Log-likelihood value for the attributes.
- Return type:
float
- probinet.evaluation.likelihood.loglikelihood_network(B: ndarray, u: ndarray, v: ndarray, w: ndarray, mask: ndarray | None = None) float [source]#
Compute the log-likelihood for the network structure.
- Parameters:
B (np.ndarray) – Graph adjacency tensor.
u (np.ndarray) – Membership matrix (out-degree).
v (np.ndarray) – Membership matrix (in-degree).
w (np.ndarray) – Affinity tensor.
mask (Optional[np.ndarray]) – Mask for selecting a subset in the adjacency tensor.
- Returns:
Log-likelihood value for the network structure.
- Return type:
float