def __sup_con_loss(
        self,
        anchor_features: torch.Tensor,
        features: torch.Tensor,
        anchor_targets: torch.Tensor,
        targets: torch.Tensor,
    ) -> torch.Tensor:
        """
        Method able to compute the supervised contrastive loss of new minibatch.
        :param anchor_features: Anchor features related to new minibatch duplicated mapped in latent space.
        :param features: Features related to half positive and half negative examples mapped in latent space.
        :param anchor_targets: Labels related to anchor features.
        :param targets: Labels related to features.
        :return: Supervised contrastive loss.
        """
        pos_mask = (
            (anchor_targets.reshape(-1, 1) == targets.reshape(1, -1))
            .float()
            .to(self.device)
        )
        similarity = anchor_features @ features.T / self.temp
        similarity -= similarity.max(dim=1)[0].detach()
        log_prob = similarity - torch.log(torch.exp(similarity).sum(1))
        mean_log_prob_pos = (pos_mask * log_prob).sum(1) / pos_mask.sum(1)
        loss = -(self.temp / self.base_temp) * mean_log_prob_pos.mean()
        return loss

        Method able to compute the supervised contrastive loss of new minibatch.
        :param anchor_features: Anchor features related to new minibatch duplicated mapped in latent space.
        :param features: Features related to half positive and half negative examples mapped in latent space.
        :param anchor_targets: Labels related to anchor features.
        :param targets: Labels related to features.
        :return: Supervised contrastive loss.
        
avalanche/training/regularization.py