class_docstr: Stochastic Gates with binary concrete distribution.
  
  Stochastic Gates is a practical solution to add L0 norm regularization for neural
  networks. L0 regularization, which explicitly penalizes any present (non-zero)
  parameters, can help network pruning and feature selection, but directly optimizing
  L0 is a non-differentiable combinatorial problem. To surrogate L0, Stochastic Gate
  uses certain continuous probability distributions (e.g., Concrete, Gaussian) with
  hard-sigmoid rectification as a continuous smoothed Bernoulli distribution
  determining the weight of a parameter, i.e., gate. Then L0 is equal to the gates's
  non-zero probability represented by the parameters of the continuous probability
  distribution. The gate value can also be reparameterized to the distribution
  parameters with a noise. So the expected L0 can be optimized through learning
  the distribution parameters via stochastic gradients.
  
  BinaryConcreteStochasticGates adopts a "stretched" binary concrete distribution as
  the smoothed Bernoulli distribution of gate. The binary concrete distribution does
  not include its lower and upper boundaries, 0 and 1, which are required by a
  Bernoulli distribution, so it needs to be linearly stretched beyond both boundaries.
  Then use hard-sigmoid rectification to "fold" the parts smaller than 0 or larger
  than 1 back to 0 and 1.
  
  More details can be found in the original paper:
  https://arxiv.org/abs/1712.01312
  
  Examples::
  
      >>> n_params = 5  # number of parameters
      >>> stg = BinaryConcreteStochasticGates(n_params, reg_weight=0.01)
      >>> inputs = torch.randn(3, n_params)  # mock inputs with batch size of 3
      >>> gated_inputs, reg = stg(mock_inputs)  # gate the inputs
docstr: Sample gate values for each example in the batch from the binary concrete
  distributions
  
  Args:
      batch_size (int): input batch size
  
  Returns:
      gate_values (Tensor): gate value tensor of shape(batch_size, n_gates)
docstr_tok: ["Sample","gate","values","for","each","example","in","the","batch","from","the","binary","concrete","distributions","Args",":","batch_size","(","int",")",":","input","batch","size","Returns",":","gate_values","(","Tensor",")",":","gate","value","tensor","of","shape","(","batch_size",",","n_gates",")"]
code: def _sample_gate_values(self, batch_size: int) -> Tensor:
      """
      Sample gate values for each example in the batch from the binary concrete
      distributions
  
      Args:
          batch_size (int): input batch size
  
      Returns:
          gate_values (Tensor): gate value tensor of shape(batch_size, n_gates)
      """
      if self.training:
          u = _torch_empty(
              batch_size,
              self.n_gates,
              device=self.log_alpha_param.device,
          )
          u.uniform_(self.eps, 1 - self.eps)
          s = torch.sigmoid(
              (_logit(u) + self.log_alpha_param) / self.temperature
          )
  
      else:
          s = torch.sigmoid(self.log_alpha_param)
          s = s.expand(batch_size, self.n_gates)
  
      s_bar = (
          s * (self.upper_bound - self.lower_bound) + self.lower_bound
      )
  
      return s_bar
  
file_path: captum/captum/module/binary_concrete_stochastic_gates.py
imports: import math
  from typing import Optional
  import torch
  from captum.module.stochastic_gates_base import StochasticGatesBase
  from torch import nn, Tensor
label_desc: Use image node_id 2 for calling the BinaryConcreteStochasticGates obj's underlying member method code with example usage: obj._sample_gate_values(batch_size) and returns: s_bar