class_docstr: Samples from a distribution and transforms samples into specified size.
  
  The connector is the same as
  :class:`~texar.tf.modules.ReparameterizedStochasticConnector`, except that
  here reparameterization is disabled, and thus the gradients cannot be
  back-propagated through the stochastic samples.
  
  Args:
      output_size: Size of output **excluding** the batch dimension. For
          example, set `output_size` to `dim` to generate output of
          shape `[batch_size, dim]`.
          Can be an `int`, a tuple of `int`, a Tensorshape, or a tuple of
          TensorShapes.
          For example, to transform inputs to have decoder state size, set
          `output_size=decoder.state_size`.
      hparams (dict, optional): Hyperparameters. Missing
          hyperparamerter will be set to default values. See
          :meth:`default_hparams` for the hyperparameter sturcture and
          default values.
  
  .. document private functions
  .. automethod:: _build
class_docstr_tok: ["Samples","from","a","distribution","and","transforms","samples","into","specified","size",".","The","connector","is","the","same","as",":","class",":","`","~texar.tf.modules.ReparameterizedStochasticConnector","`",",","except","that","here","reparameterization","is","disabled",",","and","thus","the","gradients","can","not","be","back-propagated","through","the","stochastic","samples",".","Args",":","output_size",":","Size","of","output","*","*","excluding","*","*","the","batch","dimension",".","For","example",",","set","`","output_size","`","to","`","dim","`","to","generate","output","of","shape","`","[","batch_size",",","dim","]","`",".","Can","be","an","`","int","`",",","a","tuple","of","`","int","`",",","a","Tensorshape",",","or","a","tuple","of","TensorShapes",".","For","example",",","to","transform","inputs","to","have","decoder","state","size",",","set","`","output_size=decoder.state_size","`",".","hparams","(","dict",",","optional",")",":","Hyperparameters",".","Missing","hyperparamerter","will","be","set","to","default","values",".","See",":","meth",":","`","default_hparams","`","for","the","hyperparameter","sturcture","and","default","values",".","..","document","private","functions","..","automethod",":",":","_build"]
docstr: Samples from a distribution and optionally performs transformation
  with an MLP layer.
  
  The inputs and outputs are the same as
  :class:`~texar.tf.modules.ReparameterizedStochasticConnector` except that
  the distribution does not need to be reparameterizable, and gradient
  cannot be back-propagate through the samples.
  
  Args:
      distribution: A instance of subclass of
          :tf_main:`TF Distribution <distributions/Distribution>`,
          or :tf_hmpg:`tensorflow_probability Distribution <probability>`.
          Can be a class, its name or module path, or a class instance.
      distribution_kwargs (dict, optional): Keyword arguments for the
          distribution constructor. Ignored if `distribution` is a
          class instance.
      transform (bool): Whether to perform MLP transformation of the
          distribution samples. If `False`, the structure/shape of a
          sample must match :attr:`output_size`.
      num_samples (optional): An `int` or `int` Tensor. Number of samples
          to generate. If not given, generate a single sample. Note
          that if batch size has already been included in
          `distribution`'s dimensionality, `num_samples` should be
          left as `None`.
  
  Returns:
      A tuple (output, sample), where
  
      - output: A Tensor or a (nested) tuple of Tensors with the same             structure and size of :attr:`output_size`. The batch dimension             equals :attr:`num_samples` if specified, or is determined by the             distribution dimensionality. If :attr:`transform` is `False`,             :attr:`output` will be equal to :attr:`sample`.
      - sample: The sample from the distribution, prior to transformation.
  
  Raises:
      ValueError: The output does not match :attr:`output_size`.
docstr_tok: ["Samples","from","a","distribution","and","optionally","performs","transformation","with","an","MLP","layer",".","The","inputs","and","outputs","are","the","same","as",":","class",":","`","~texar.tf.modules.ReparameterizedStochasticConnector","`","except","that","the","distribution","does","not","need","to","be","reparameterizable",",","and","gradient","can","not","be","back-propagate","through","the","samples",".","Args",":","distribution",":","A","instance","of","subclass","of",":","tf_main",":","`","TF","Distribution","<","distributions\/Distribution",">","`",",","or",":","tf_hmpg",":","`","tensorflow_probability","Distribution","<","probability",">","`",".","Can","be","a","class",",","its","name","or","module","path",",","or","a","class","instance",".","distribution_kwargs","(","dict",",","optional",")",":","Keyword","arguments","for","the","distribution","constructor",".","Ignored","if","`","distribution","`","is","a","class","instance",".","transform","(","bool",")",":","Whether","to","perform","MLP","transformation","of","the","distribution","samples",".","If","`","False","`",",","the","structure\/shape","of","a","sample","must","match",":","attr",":","`","output_size","`",".","num_samples","(","optional",")",":","An","`","int","`","or","`","int","`","Tensor",".","Number","of","samples","to","generate",".","If","not","given",",","generate","a","single","sample",".","Note","that","if","batch","size","has","already","been","included","in","`","distribution","`","'s","dimensionality",",","`","num_samples","`","should","be","left","as","`","None","`",".","Returns",":","A","tuple","(","output",",","sample",")",",","where","-","output",":","A","Tensor","or","a","(","nested",")","tuple","of","Tensors","with","the","same","structure","and","size","of",":","attr",":","`","output_size","`",".","The","batch","dimension","equals",":","attr",":","`","num_samples","`","if","specified",",","or","is","determined","by","the","distribution","dimensionality",".","If",":","attr",":","`","transform","`","is","`","False","`",",",":","attr",":","`","output","`","will","be","equal","to",":","attr",":","`","sample","`",".","-","sample",":","The","sample","from","the","distribution",",","prior","to","transformation",".","Raises",":","ValueError",":","The","output","does","not","match",":","attr",":","`","output_size","`","."]
code: def _build(
      self,
      distribution="MultivariateNormalDiag",
      distribution_kwargs=None,
      transform=True,
      num_samples=None,
  ):
      """Samples from a distribution and optionally performs transformation
          with an MLP layer.
  
          The inputs and outputs are the same as
          :class:`~texar.tf.modules.ReparameterizedStochasticConnector` except that
          the distribution does not need to be reparameterizable, and gradient
          cannot be back-propagate through the samples.
  
          Args:
              distribution: A instance of subclass of
                  :tf_main:`TF Distribution <distributions/Distribution>`,
                  or :tf_hmpg:`tensorflow_probability Distribution <probability>`.
                  Can be a class, its name or module path, or a class instance.
              distribution_kwargs (dict, optional): Keyword arguments for the
                  distribution constructor. Ignored if `distribution` is a
                  class instance.
              transform (bool): Whether to perform MLP transformation of the
                  distribution samples. If `False`, the structure/shape of a
                  sample must match :attr:`output_size`.
              num_samples (optional): An `int` or `int` Tensor. Number of samples
                  to generate. If not given, generate a single sample. Note
                  that if batch size has already been included in
                  `distribution`'s dimensionality, `num_samples` should be
                  left as `None`.
  
          Returns:
              A tuple (output, sample), where
  
              - output: A Tensor or a (nested) tuple of Tensors with the same \
              structure and size of :attr:`output_size`. The batch dimension \
              equals :attr:`num_samples` if specified, or is determined by the \
              distribution dimensionality. If :attr:`transform` is `False`, \
              :attr:`output` will be equal to :attr:`sample`.
              - sample: The sample from the distribution, prior to transformation.
  
          Raises:
              ValueError: The output does not match :attr:`output_size`.
          """
      dstr = check_or_get_instance(
          distribution,
          distribution_kwargs,
          [
              "tensorflow.distributions",
              "tensorflow_probability.distributions",
              "texar.tf.custom",
          ],
      )
  
      if num_samples:
          sample = dstr.sample(num_samples)
      else:
          sample = dstr.sample()
  
      if dstr.event_shape == []:
          sample = tf.reshape(
              sample, sample.shape.concatenate(tf.TensorShape(1))
          )
  
      # Disable gradients through samples
      sample = tf.stop_gradient(sample)
  
      sample = tf.cast(sample, tf.float32)
  
      if transform:
          fn_modules = [
              "tensorflow",
              "tensorflow.nn",
              "texar.tf.custom",
          ]
          activation_fn = get_function(
              self.hparams.activation_fn, fn_modules
          )
          output = _mlp_transform(
              sample, self._output_size, activation_fn
          )
      else:
          output = sample
  
      _assert_same_size(output, self._output_size)
      if not self._built:
          self._add_internal_trainable_variables()
          self._built = True
  
      return output, sample
  
imports: import numpy
  import tensorflow
  from tensorflow import distributions
  from tensorflow.python.util import nest
  from texar.tf.modules.connectors.connector_base import ConnectorBase
  from texar.tf.core import layers
  from texar.tf.utils.utils import get_function, check_or_get_instance
label_desc: Use image node_id 3 for calling the StochasticConnector obj's underlying member method code with example usage: obj._build(distribution, distribution_kwargs, transform, num_samples) and returns: output,  sample