class_docstr: Abstract base class for Monte Carlo. Specific Monte Carlo methods
  inherit from `MonteCarlo`, sharing methods in this class.
  
  To build an algorithm inheriting from `MonteCarlo`, one must at the
  minimum implement `build_update`: it determines how to assign
  the samples in the `Empirical` approximations.
  
  #### Notes
  
  The number of Monte Carlo iterations is set according to the
  minimum of all `Empirical` sizes.
  
  Initialization is assumed from `params[0, :]`. This generalizes
  initializing randomly and initializing from user input. Updates
  are along this outer dimension, where iteration t updates
  `params[t, :]` in each `Empirical` random variable.
  
  No warm-up is implemented. Users must run MCMC for a long period
  of time, then manually burn in the Empirical random variable.
  
  #### Examples
  
  Most explicitly, `MonteCarlo` is specified via a dictionary:
  
  ```python
  qpi = Empirical(params=tf.Variable(tf.zeros([T, K-1])))
  qmu = Empirical(params=tf.Variable(tf.zeros([T, K*D])))
  qsigma = Empirical(params=tf.Variable(tf.zeros([T, K*D])))
  ed.MonteCarlo({pi: qpi, mu: qmu, sigma: qsigma}, data)
  ```
  
  The inferred posterior is comprised of `Empirical` random
  variables with `T` samples. We also automate the specification
  of `Empirical` random variables. One can pass in a list of
  latent variables instead:
  
  ```python
  ed.MonteCarlo([beta], data)
  ed.MonteCarlo([pi, mu, sigma], data)
  ```
  
  It defaults to `Empirical` random variables with 10,000 samples for
  each dimension.
class_docstr_tok: ["Abstract","base","class","for","Monte","Carlo",".","Specific","Monte","Carlo","methods","inherit","from","`","MonteCarlo","`",",","sharing","methods","in","this","class",".","To","build","an","algorithm","inheriting","from","`","MonteCarlo","`",",","one","must","at","the","minimum","implement","`","build_update","`",":","it","determines","how","to","assign","the","samples","in","the","`","Empirical","`","approximations",".","#","#","#","#","Notes","The","number","of","Monte","Carlo","iterations","is","set","according","to","the","minimum","of","all","`","Empirical","`","sizes",".","Initialization","is","assumed","from","`","params","[","0",",",":","]","`",".","This","generalizes","initializing","randomly","and","initializing","from","user","input",".","Updates","are","along","this","outer","dimension",",","where","iteration","t","updates","`","params","[","t",",",":","]","`","in","each","`","Empirical","`","random","variable",".","No","warm-up","is","implemented",".","Users","must","run","MCMC","for","a","long","period","of","time",",","then","manually","burn","in","the","Empirical","random","variable",".","#","#","#","#","Examples","Most","explicitly",",","`","MonteCarlo","`","is","specified","via","a","dictionary",":","``","`","python","qpi","=","Empirical","(","params=tf.Variable","(","tf.zeros","(","[","T",",","K-1","]",")",")",")","qmu","=","Empirical","(","params=tf.Variable","(","tf.zeros","(","[","T",",","K","*","D","]",")",")",")","qsigma","=","Empirical","(","params=tf.Variable","(","tf.zeros","(","[","T",",","K","*","D","]",")",")",")","ed.MonteCarlo","(","{","pi",":","qpi",",","mu",":","qmu",",","sigma",":","qsigma","}",",","data",")","``","`","The","inferred","posterior","is","comprised","of","`","Empirical","`","random","variables","with","`","T","`","samples",".","We","also","automate","the","specification","of","`","Empirical","`","random","variables",".","One","can","pass","in","a","list","of","latent","variables","instead",":","``","`","python","ed.MonteCarlo","(","[","beta","]",",","data",")","ed.MonteCarlo","(","[","pi",",","mu",",","sigma","]",",","data",")","``","`","It","defaults","to","`","Empirical","`","random","variables","with","10,000","samples","for","each","dimension","."]
code: def initialize(self, *args, **kwargs):
      kwargs["n_iter"] = np.amin(
          [
              qz.params.shape.as_list()[0]
              for qz in six.itervalues(self.latent_vars)
          ]
      )
      super(MonteCarlo, self).initialize(*args, **kwargs)
  
      self.n_accept = tf.Variable(0, trainable=False, name="n_accept")
      self.n_accept_over_t = self.n_accept / self.t
      self.train = self.build_update()
  
      self.reset.append(tf.variables_initializer([self.n_accept]))
  
      if self.logging:
          tf.summary.scalar(
              "n_accept", self.n_accept, collections=[self._summary_key]
          )
          self.summarize = tf.summary.merge_all(key=self._summary_key)
  
file_path: edward/edward/inferences/monte_carlo.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import abc
  import numpy
  import six
  import tensorflow
  from edward.inferences.inference import Inference
  from edward.models import Empirical, RandomVariable
  from edward.util import get_session
label_desc: Use image node_id 2 for calling the MonteCarlo obj's underlying member method code with example usage: obj.initialize() without return types