class_docstr: Base class for random variables.
  
  A random variable is an object parameterized by tensors. It is
  equipped with methods such as the log-density, mean, and sample.
  
  It also wraps a tensor, where the tensor corresponds to a sample
  from the random variable. This enables operations on the TensorFlow
  graph, allowing random variables to be used in conjunction with
  other TensorFlow ops.
  
  The random variable's shape is given by
  
  `sample_shape + batch_shape + event_shape`,
  
  where `sample_shape` is an optional argument representing the
  dimensions of samples drawn from the distribution (default is
  a scalar); `batch_shape` is the number of independent random variables
  (determined by the shape of its parameters); and `event_shape` is
  the shape of one draw from the distribution (e.g., `Normal` has a
  scalar `event_shape`; `Dirichlet` has a vector `event_shape`).
  
  #### Notes
  
  `RandomVariable` assumes use in a multiple inheritance setting. The
  child class must first inherit `RandomVariable`, then second inherit a
  class in `tf.contrib.distributions`. With Python's method resolution
  order, this implies the following during initialization (using
  `distributions.Bernoulli` as an example):
  
  1. Start the `__init__()` of the child class, which passes all
     `*args, **kwargs` to `RandomVariable`.
  2. This in turn passes all `*args, **kwargs` to
     `distributions.Bernoulli`, completing the `__init__()` of
     `distributions.Bernoulli`.
  3. Complete the `__init__()` of `RandomVariable`, which calls
     `self.sample()`, relying on the method from
     `distributions.Bernoulli`.
  4. Complete the `__init__()` of the child class.
  
  Methods from both `RandomVariable` and `distributions.Bernoulli`
  populate the namespace of the child class. Methods from
  `RandomVariable` will take higher priority if there are conflicts.
  
  #### Examples
  
  ```python
  p = tf.constant(0.5)
  x = Bernoulli(p)
  
  z1 = tf.constant([[1.0, -0.8], [0.3, -1.0]])
  z2 = tf.constant([[0.9, 0.2], [2.0, -0.1]])
  x = Bernoulli(logits=tf.matmul(z1, z2))
  
  mu = Normal(tf.constant(0.0), tf.constant(1.0))
  x = Normal(mu, tf.constant(1.0))
  ```
class_docstr_tok: ["Base","class","for","random","variables",".","A","random","variable","is","an","object","parameterized","by","tensors",".","It","is","equipped","with","methods","such","as","the","log-density",",","mean",",","and","sample",".","It","also","wraps","a","tensor",",","where","the","tensor","corresponds","to","a","sample","from","the","random","variable",".","This","enables","operations","on","the","TensorFlow","graph",",","allowing","random","variables","to","be","used","in","conjunction","with","other","TensorFlow","ops",".","The","random","variable","'s","shape","is","given","by","`","sample_shape","+","batch_shape","+","event_shape","`",",","where","`","sample_shape","`","is","an","optional","argument","representing","the","dimensions","of","samples","drawn","from","the","distribution","(","default","is","a","scalar",")",";","`","batch_shape","`","is","the","number","of","independent","random","variables","(","determined","by","the","shape","of","its","parameters",")",";","and","`","event_shape","`","is","the","shape","of","one","draw","from","the","distribution","(","e.g.",",","`","Normal","`","has","a","scalar","`","event_shape","`",";","`","Dirichlet","`","has","a","vector","`","event_shape","`",")",".","#","#","#","#","Notes","`","RandomVariable","`","assumes","use","in","a","multiple","inheritance","setting",".","The","child","class","must","first","inherit","`","RandomVariable","`",",","then","second","inherit","a","class","in","`","tf.contrib.distributions","`",".","With","Python","'s","method","resolution","order",",","this","implies","the","following","during","initialization","(","using","`","distributions.Bernoulli","`","as","an","example",")",":","1",".","Start","the","`","__init__","(",")","`","of","the","child","class",",","which","passes","all","`","*","args",",","*","*","kwargs","`","to","`","RandomVariable","`",".","2",".","This","in","turn","passes","all","`","*","args",",","*","*","kwargs","`","to","`","distributions.Bernoulli","`",",","completing","the","`","__init__","(",")","`","of","`","distributions.Bernoulli","`",".","3",".","Complete","the","`","__init__","(",")","`","of","`","RandomVariable","`",",","which","calls","`","self.sample","(",")","`",",","relying","on","the","method","from","`","distributions.Bernoulli","`",".","4",".","Complete","the","`","__init__","(",")","`","of","the","child","class",".","Methods","from","both","`","RandomVariable","`","and","`","distributions.Bernoulli","`","populate","the","namespace","of","the","child","class",".","Methods","from","`","RandomVariable","`","will","take","higher","priority","if","there","are","conflicts",".","#","#","#","#","Examples","``","`","python","p","=","tf.constant","(","0.5",")","x","=","Bernoulli","(","p",")","z1","=","tf.constant","(","[","[","1.0",",","-0.8","]",",","[","0.3",",","-1.0","]","]",")","z2","=","tf.constant","(","[","[","0.9",",","0.2","]",",","[","2.0",",","-0.1","]","]",")","x","=","Bernoulli","(","logits=tf.matmul","(","z1",",","z2",")",")","mu","=","Normal","(","tf.constant","(","0.0",")",",","tf.constant","(","1.0",")",")","x","=","Normal","(","mu",",","tf.constant","(","1.0",")",")","``","`"]
docstr: Create a new random variable.
  
  Args:
    sample_shape: tf.TensorShape.
      Shape of samples to draw from the random variable.
    value: tf.Tensor.
      Fixed tensor to associate with random variable. Must have shape
      `sample_shape + batch_shape + event_shape`.
    collections: list.
      Optional list of graph collections (lists). The random variable is
      added to these collections. Defaults to `[ed.random_variables()]`.
docstr_tok: ["Create","a","new","random","variable",".","Args",":","sample_shape",":","tf.TensorShape",".","Shape","of","samples","to","draw","from","the","random","variable",".","value",":","tf.Tensor",".","Fixed","tensor","to","associate","with","random","variable",".","Must","have","shape","`","sample_shape","+","batch_shape","+","event_shape","`",".","collections",":","list",".","Optional","list","of","graph","collections","(","lists",")",".","The","random","variable","is","added","to","these","collections",".","Defaults","to","`","[","ed.random_variables","(",")","]","`","."]
code: def __init__(self, *args, **kwargs):
      """Create a new random variable.
  
      Args:
        sample_shape: tf.TensorShape.
          Shape of samples to draw from the random variable.
        value: tf.Tensor.
          Fixed tensor to associate with random variable. Must have shape
          `sample_shape + batch_shape + event_shape`.
        collections: list.
          Optional list of graph collections (lists). The random variable is
          added to these collections. Defaults to `[ed.random_variables()]`.
      """
      # Force the Distribution class to always use the same name scope
      # when scoping its parameter names and also when calling any
      # methods such as sample.
      name = kwargs.get("name", type(self).__name__)
      with tf.name_scope(name) as ns:
          kwargs["name"] = ns
  
      # pop and store RandomVariable-specific parameters in _kwargs
      sample_shape = kwargs.pop("sample_shape", ())
      value = kwargs.pop("value", None)
      collections = kwargs.pop("collections", ["random_variables"])
  
      # store args, kwargs for easy graph copying
      self._args = args
      self._kwargs = kwargs.copy()
  
      if sample_shape != ():
          self._kwargs["sample_shape"] = sample_shape
      if value is not None:
          self._kwargs["value"] = value
      if collections != ["random_variables"]:
          self._kwargs["collections"] = collections
  
      super(RandomVariable, self).__init__(*args, **kwargs)
  
      self._sample_shape = tf.TensorShape(sample_shape)
      if value is not None:
          t_value = tf.convert_to_tensor(value, self.dtype)
          value_shape = t_value.shape
          expected_shape = self._sample_shape.concatenate(
              self.batch_shape
          ).concatenate(self.event_shape)
          if not value_shape.is_compatible_with(expected_shape):
              raise ValueError(
                  "Incompatible shape for initialization argument 'value'. "
                  "Expected %s, got %s." % (expected_shape, value_shape)
              )
          else:
              self._value = t_value
      else:
          try:
              self._value = self.sample(self._sample_shape)
          except NotImplementedError:
              raise NotImplementedError(
                  "sample is not implemented for {0}. You must either pass in the "
                  "value argument or implement sample for {0}.".format(
                      self.__class__.__name__
                  )
              )
  
      for collection in collections:
          if collection == "random_variables":
              collection = _RANDOM_VARIABLE_COLLECTION
          collection[tf.get_default_graph()].append(self)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import tensorflow
  from collections import defaultdict
label_desc: Use image node_id 1 to create a new RandomVariable object from inherited base classes: object with example: obj = RandomVariable()