torchcell.losses.dango.DangoLoss
- class DangoLoss(edge_types: list[str], lambda_values: dict[str, float], scheduler: DangoLossSched | None = None, reduction: str = 'mean')[source]
Bases:
ModuleCombined loss for the DANGO model with dynamic weighting between reconstruction loss and interaction loss.
- Parameters:
edge_types – List of edge types for reconstruction loss
lambda_values – Dictionary mapping edge types to their lambda values for weighted MSE
scheduler – DangoLossSched instance that determines loss weighting over epochs
reduction – Reduction method for the loss (‘none’, ‘mean’, ‘sum’)
- compute_weighted_mse_loss(predictions: Tensor, targets: Tensor, lambda_value: float) Tensor[source]
Compute the weighted MSE loss as defined in the paper
- Parameters:
predictions – Reconstructed adjacency matrix rows
targets – Ground truth adjacency matrix rows
lambda_value – Weight for zero entries
- Returns:
Weighted MSE loss
- compute_reconstruction_loss(reconstructions: dict[str, Tensor], adjacency_matrices: dict[str, Tensor]) Tensor[source]
Compute the total reconstruction loss across all networks
- Parameters:
reconstructions – Dictionary of reconstructed adjacency matrix rows for each edge type
adjacency_matrices – Dictionary of ground truth adjacency matrices for each edge type
- Returns:
Total reconstruction loss
- compute_interaction_loss(predictions: Tensor, targets: Tensor) Tensor[source]
Compute the log-cosh loss for interaction prediction
- Parameters:
predictions – Predicted interaction scores
targets – Ground truth interaction scores
- Returns:
Log-cosh loss
- forward(predictions: Tensor, targets: Tensor, reconstructions: dict[str, Tensor], adjacency_matrices: dict[str, Tensor], current_epoch: int = 0) tuple[Tensor, dict[str, Tensor]][source]
Compute the combined loss for DANGO model.
- Parameters:
predictions – Predicted interaction scores
targets – Ground truth interaction scores
reconstructions – Dictionary of reconstructed adjacency matrices
adjacency_matrices – Dictionary of ground truth adjacency matrices
current_epoch – Current training epoch (used for dynamic weighting)
- Returns:
Tuple containing the total loss and a dictionary with component losses