class_docstr: Interface for torch models.
class_docstr_tok: ["Interface","for","torch","models","."]
docstr: Sample a model by means of adding normally distributed noise.
  
  Parameters
  ----------
  mean: float
      The mean point to sample from.
  std: float
      The standard deviation to sample from.
  noise_type: string
      Noise type could be either 'additive' or 'multiplicative'.
  
  Returns
  -------
  model_copy: torch.nn
      A noisy copy of the orginal model.
docstr_tok: ["Sample","a","model","by","means","of","adding","normally","distributed","noise",".","Parameters","--","--","--","--","--","mean",":","float","The","mean","point","to","sample","from",".","std",":","float","The","standard","deviation","to","sample","from",".","noise_type",":","string","Noise","type","could","be","either","'additive","'","or","'multiplicative","'",".","Returns","--","--","--","-","model_copy",":","torch.nn","A","noisy","copy","of","the","orginal","model","."]
code: def sample(
      self,
      mean: float,
      std: float,
      noise_type: str = "multiplicative",
  ) -> torch.nn:
      """
      Sample a model by means of adding normally distributed noise.
  
      Parameters
      ----------
      mean: float
          The mean point to sample from.
      std: float
          The standard deviation to sample from.
      noise_type: string
          Noise type could be either 'additive' or 'multiplicative'.
  
      Returns
      -------
      model_copy: torch.nn
          A noisy copy of the orginal model.
      """
  
      distribution = torch.distributions.normal.Normal(
          loc=mean, scale=std
      )
      original_parameters = self.state_dict()
      model_copy = deepcopy(self.model)
      model_copy.load_state_dict(original_parameters)
  
      # If std is not zero, loop over each layer and add Gaussian noise.
      if not std == 0.0:
          with torch.no_grad():
              for layer in model_copy.parameters():
                  if noise_type == "additive":
                      layer.add_(
                          distribution.sample(layer.size()).to(
                              layer.device
                          )
                      )
                  elif noise_type == "multiplicative":
                      layer.mul_(
                          distribution.sample(layer.size()).to(
                              layer.device
                          )
                      )
                  else:
                      raise ValueError(
                          "Set noise_type to either 'multiplicative' "
                          "or 'additive' (string) when you sample the model."
                      )
      return model_copy
  
imports: import copy
  from contextlib import suppress
  from copy import deepcopy
  from typing import Any, Dict, Optional, Tuple, List, Union, Generator
  import warnings
  import logging
  import numpy
  import torch
  from torch import nn
  from functools import lru_cache
  from quantus.helpers import utils
  from quantus.helpers.model.model_interface import ModelInterface
label_desc: Use image node_id 10 for calling the PyTorchModel obj's underlying member method code with example usage: obj.sample(mean, std, noise_type) and returns: model_copy