class_docstr: Asymmetric metric learning (AML) Criterion used in
  "New Insights on Reducing Abrupt Representation
  Change in Online Continual Learning"
  by Lucas Caccia et. al.
  https://openreview.net/forum?id=N8MaByOzUfb
docstr: 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.
docstr_tok: ["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","."]
code: 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
  
imports: import copy
  from collections import defaultdict
  from typing import List
  import torch
  import torch.nn.functional
  from avalanche.models import MultiTaskModule, avalanche_forward
label_desc: Use image node_id 3 for calling the AMLCriterion obj's underlying member method code with example usage: obj.__sup_con_loss(anchor_features, features, anchor_targets, targets) and returns: loss