class_docstr: Implementation of https://arxiv.org/pdf/1612.02295.pdf
class_docstr_tok: ["Implementation","of","https",":","\/\/arxiv.org\/pdf\/1612.02295.pdf"]
code: def get_cos_with_margin(self, cosine):
      cosine = cosine.unsqueeze(1)
      for attr in [
          "n_range",
          "margin_choose_n",
          "cos_powers",
          "alternating",
      ]:
          setattr(
              self, attr, c_f.to_device(getattr(self, attr), cosine)
          )
      cos_powered = cosine**self.cos_powers
      sin_powered = (1 - cosine**2) ** self.n_range
      terms = (
          self.alternating
          * self.margin_choose_n
          * cos_powered
          * sin_powered
      )  # Equation 7 in the paper
      return torch.sum(terms, dim=1)
  
imports: import math
  import numpy
  import scipy.special
  import torch
  from ..distances import CosineSimilarity
  from ..utils import common_functions
  from ..utils import loss_and_miner_utils
  from .base_metric_loss_function import BaseMetricLossFunction
  from .mixins import WeightRegularizerMixin
label_desc: Use image node_id 3 for calling the LargeMarginSoftmaxLoss obj's underlying member method code with example usage: obj.get_cos_with_margin(cosine) and returns: torch