class_docstr: Perform mixup on the model inputs. Requires use of :meth:`MixupInputs.loss`, otherwise lambdas can be found in
  state under :attr:`.MIXUP_LAMBDA`. Model targets will be a tuple containing the original target and permuted target.
  
  .. note::
  
      The accuracy metric for mixup is different on training to deal with the different targets,
      but for validation it is exactly the categorical accuracy, despite being called "val_mixup_acc"
  
  Example: ::
  
      >>> from torchbearer import Trial
      >>> from torchbearer.callbacks import Mixup
  
      # Example Trial which does Mixup regularisation
      >>> mixup = Mixup(0.9)
      >>> trial = Trial(None, criterion=Mixup.mixup_loss, callbacks=[mixup], metrics=['acc'])
  
  Args:
      lam (float): Mixup inputs by fraction lam. If RANDOM, choose lambda from Beta(alpha, alpha). Else, lambda=lam
      alpha (float): The alpha value to use in the beta distribution.
class_docstr_tok: ["Perform","mixup","on","the","model","inputs",".","Requires","use","of",":","meth",":","`","MixupInputs.loss","`",",","otherwise","lambdas","can","be","found","in","state","under",":","attr",":","`",".MIXUP_LAMBDA","`",".","Model","targets","will","be","a","tuple","containing","the","original","target","and","permuted","target",".","..","note",":",":","The","accuracy","metric","for","mixup","is","different","on","training","to","deal","with","the","different","targets",",","but","for","validation","it","is","exactly","the","categorical","accuracy",",","despite","being","called","``","val_mixup_acc","''","Example",":",":",":",">",">",">","from","torchbearer","import","Trial",">",">",">","from","torchbearer.callbacks","import","Mixup","#","Example","Trial","which","does","Mixup","regularisation",">",">",">","mixup","=","Mixup","(","0.9",")",">",">",">","trial","=","Trial","(","None",",","criterion=Mixup.mixup_loss",",","callbacks=","[","mixup","]",",","metrics=","[","'acc","'","]",")","Args",":","lam","(","float",")",":","Mixup","inputs","by","fraction","lam",".","If","RANDOM",",","choose","lambda","from","Beta","(","alpha",",","alpha",")",".","Else",",","lambda=lam","alpha","(","float",")",":","The","alpha","value","to","use","in","the","beta","distribution","."]
code: def on_sample(self, state):
      if self.lam is Mixup.RANDOM:
          if self.alpha > 0:
              lam = self.distrib.sample()
          else:
              lam = 1.0
      else:
          lam = self.lam
  
      state[torchbearer.MIXUP_LAMBDA] = lam
  
      state[torchbearer.MIXUP_PERMUTATION] = torch.randperm(
          state[torchbearer.X].size(0)
      )
      state[torchbearer.X] = state[torchbearer.X] * state[
          torchbearer.MIXUP_LAMBDA
      ] + state[torchbearer.X][
          state[torchbearer.MIXUP_PERMUTATION], :
      ] * (
          1 - state[torchbearer.MIXUP_LAMBDA]
      )
      state[torchbearer.Y_TRUE] = (
          state[torchbearer.Y_TRUE],
          state[torchbearer.Y_TRUE][
              state[torchbearer.MIXUP_PERMUTATION]
          ],
      )
  
file_path: torchbearer/torchbearer/callbacks/mixup.py
imports: import torch
  import torch.nn.functional
  from torch.distributions.beta import Beta
  import torchbearer
  from torchbearer import cite
  from torchbearer.callbacks import Callback
  from torchbearer.metrics import CategoricalAccuracy, AdvancedMetric, running_mean, mean, super
  from torchbearer.metrics import default
label_desc: Use image node_id 3 for calling the Mixup obj's underlying member method code with example usage: obj.on_sample(state) without return types