class_docstr: Abstract base class for inference. All inference algorithms in
  Edward inherit from `Inference`, sharing common methods and
  properties via a class hierarchy.
  
  Specific algorithms typically inherit from other subclasses of
  `Inference` rather than `Inference` directly. For example, one
  might inherit from the abstract classes `MonteCarlo` or
  `VariationalInference`.
  
  To build an algorithm inheriting from `Inference`, one must at the
  minimum implement `initialize` and `update`: the former builds
  the computational graph for the algorithm; the latter runs the
  computational graph for the algorithm.
  
  To reset inference (e.g., internal variable counters incremented
  over training), fetch inference's reset ops from session with
  `sess.run(inference.reset)`.
  
  #### Examples
  
  ```python
  # Set up probability model.
  mu = Normal(loc=0.0, scale=1.0)
  x = Normal(loc=mu, scale=1.0, sample_shape=50)
  
  # Set up posterior approximation.
  qmu_loc = tf.Variable(tf.random_normal([]))
  qmu_scale = tf.nn.softplus(tf.Variable(tf.random_normal([])))
  qmu = Normal(loc=qmu_loc, scale=qmu_scale)
  
  inference = ed.Inference({mu: qmu}, data={x: tf.zeros(50)})
  ```
class_docstr_tok: ["Abstract","base","class","for","inference",".","All","inference","algorithms","in","Edward","inherit","from","`","Inference","`",",","sharing","common","methods","and","properties","via","a","class","hierarchy",".","Specific","algorithms","typically","inherit","from","other","subclasses","of","`","Inference","`","rather","than","`","Inference","`","directly",".","For","example",",","one","might","inherit","from","the","abstract","classes","`","MonteCarlo","`","or","`","VariationalInference","`",".","To","build","an","algorithm","inheriting","from","`","Inference","`",",","one","must","at","the","minimum","implement","`","initialize","`","and","`","update","`",":","the","former","builds","the","computational","graph","for","the","algorithm",";","the","latter","runs","the","computational","graph","for","the","algorithm",".","To","reset","inference","(","e.g.",",","internal","variable","counters","incremented","over","training",")",",","fetch","inference","'s","reset","ops","from","session","with","`","sess.run","(","inference.reset",")","`",".","#","#","#","#","Examples","``","`","python","#","Set","up","probability","model",".","mu","=","Normal","(","loc=0.0",",","scale=1.0",")","x","=","Normal","(","loc=mu",",","scale=1.0",",","sample_shape=50",")","#","Set","up","posterior","approximation",".","qmu_loc","=","tf.Variable","(","tf.random_normal","(","[","]",")",")","qmu_scale","=","tf.nn.softplus","(","tf.Variable","(","tf.random_normal","(","[","]",")",")",")","qmu","=","Normal","(","loc=qmu_loc",",","scale=qmu_scale",")","inference","=","ed.Inference","(","{","mu",":","qmu","}",",","data=","{","x",":","tf.zeros","(","50",")","}",")","``","`"]
docstr: Initialize inference algorithm. It initializes hyperparameters
  and builds ops for the algorithm's computation graph.
  
  Any derived class of `Inference` **must** implement this method.
  No methods which build ops should be called outside `initialize()`.
  
  Args:
    n_iter: int.
      Number of iterations for algorithm when calling `run()`.
      Alternatively if controlling inference manually, it is the
      expected number of calls to `update()`; this number determines
      tracking information during the print progress.
    n_print: int.
      Number of iterations for each print progress. To suppress print
      progress, then specify 0. Default is `int(n_iter / 100)`.
    scale: dict of RandomVariable to tf.Tensor.
      A tensor to scale computation for any random variable that it is
      binded to. Its shape must be broadcastable; it is multiplied
      element-wise to the random variable. For example, this is useful
      for mini-batch scaling when inferring global variables, or
      applying masks on a random variable.
    auto_transform: bool.
      Whether to automatically transform continuous latent variables
      of unequal support to be on the unconstrained space. It is
      only applied if the argument is `True`, the latent variable
      pair are `ed.RandomVariable`s with the `support` attribute,
      the supports are both continuous and unequal.
    logdir: str.
      Directory where event file will be written. For details,
      see `tf.summary.FileWriter`. Default is to log nothing.
    log_timestamp: bool.
      If True (and `logdir` is specified), create a subdirectory of
      `logdir` to save the specific run results. The subdirectory's
      name is the current UTC timestamp with format 'YYYYMMDD_HHMMSS'.
    log_vars: list.
      Specifies the list of variables to log after each `n_print`
      steps. If None, will log all variables. If `[]`, no variables
      will be logged. `logdir` must be specified for variables to be
      logged.
    debug: bool.
      If True, add checks for `NaN` and `Inf` to all computations
      in the graph. May result in substantially slower execution
      times.
docstr_tok: ["Initialize","inference","algorithm",".","It","initializes","hyperparameters","and","builds","ops","for","the","algorithm","'s","computation","graph",".","Any","derived","class","of","`","Inference","`","*","*","must","*","*","implement","this","method",".","No","methods","which","build","ops","should","be","called","outside","`","initialize","(",")","`",".","Args",":","n_iter",":","int",".","Number","of","iterations","for","algorithm","when","calling","`","run","(",")","`",".","Alternatively","if","controlling","inference","manually",",","it","is","the","expected","number","of","calls","to","`","update","(",")","`",";","this","number","determines","tracking","information","during","the","print","progress",".","n_print",":","int",".","Number","of","iterations","for","each","print","progress",".","To","suppress","print","progress",",","then","specify","0",".","Default","is","`","int","(","n_iter","\/","100",")","`",".","scale",":","dict","of","RandomVariable","to","tf.Tensor",".","A","tensor","to","scale","computation","for","any","random","variable","that","it","is","binded","to",".","Its","shape","must","be","broadcastable",";","it","is","multiplied","element-wise","to","the","random","variable",".","For","example",",","this","is","useful","for","mini-batch","scaling","when","inferring","global","variables",",","or","applying","masks","on","a","random","variable",".","auto_transform",":","bool",".","Whether","to","automatically","transform","continuous","latent","variables","of","unequal","support","to","be","on","the","unconstrained","space",".","It","is","only","applied","if","the","argument","is","`","True","`",",","the","latent","variable","pair","are","`","ed.RandomVariable","`","s","with","the","`","support","`","attribute",",","the","supports","are","both","continuous","and","unequal",".","logdir",":","str",".","Directory","where","event","file","will","be","written",".","For","details",",","see","`","tf.summary.FileWriter","`",".","Default","is","to","log","nothing",".","log_timestamp",":","bool",".","If","True","(","and","`","logdir","`","is","specified",")",",","create","a","subdirectory","of","`","logdir","`","to","save","the","specific","run","results",".","The","subdirectory's","name","is","the","current","UTC","timestamp","with","format","'YYYYMMDD_HHMMSS","'",".","log_vars",":","list",".","Specifies","the","list","of","variables","to","log","after","each","`","n_print","`","steps",".","If","None",",","will","log","all","variables",".","If","`","[","]","`",",","no","variables","will","be","logged",".","`","logdir","`","must","be","specified","for","variables","to","be","logged",".","debug",":","bool",".","If","True",",","add","checks","for","`","NaN","`","and","`","Inf","`","to","all","computations","in","the","graph",".","May","result","in","substantially","slower","execution","times","."]
code: def initialize(
      self,
      n_iter=1000,
      n_print=None,
      scale=None,
      auto_transform=True,
      logdir=None,
      log_timestamp=True,
      log_vars=None,
      debug=False,
  ):
      """Initialize inference algorithm. It initializes hyperparameters
      and builds ops for the algorithm's computation graph.
  
      Any derived class of `Inference` **must** implement this method.
      No methods which build ops should be called outside `initialize()`.
  
      Args:
        n_iter: int.
          Number of iterations for algorithm when calling `run()`.
          Alternatively if controlling inference manually, it is the
          expected number of calls to `update()`; this number determines
          tracking information during the print progress.
        n_print: int.
          Number of iterations for each print progress. To suppress print
          progress, then specify 0. Default is `int(n_iter / 100)`.
        scale: dict of RandomVariable to tf.Tensor.
          A tensor to scale computation for any random variable that it is
          binded to. Its shape must be broadcastable; it is multiplied
          element-wise to the random variable. For example, this is useful
          for mini-batch scaling when inferring global variables, or
          applying masks on a random variable.
        auto_transform: bool.
          Whether to automatically transform continuous latent variables
          of unequal support to be on the unconstrained space. It is
          only applied if the argument is `True`, the latent variable
          pair are `ed.RandomVariable`s with the `support` attribute,
          the supports are both continuous and unequal.
        logdir: str.
          Directory where event file will be written. For details,
          see `tf.summary.FileWriter`. Default is to log nothing.
        log_timestamp: bool.
          If True (and `logdir` is specified), create a subdirectory of
          `logdir` to save the specific run results. The subdirectory's
          name is the current UTC timestamp with format 'YYYYMMDD_HHMMSS'.
        log_vars: list.
          Specifies the list of variables to log after each `n_print`
          steps. If None, will log all variables. If `[]`, no variables
          will be logged. `logdir` must be specified for variables to be
          logged.
        debug: bool.
          If True, add checks for `NaN` and `Inf` to all computations
          in the graph. May result in substantially slower execution
          times.
      """
      self.n_iter = n_iter
      if n_print is None:
          self.n_print = int(n_iter / 100)
      else:
          self.n_print = n_print
  
      self.progbar = Progbar(self.n_iter)
      self.t = tf.Variable(0, trainable=False, name="iteration")
  
      self.increment_t = self.t.assign_add(1)
  
      if scale is None:
          scale = {}
      elif not isinstance(scale, dict):
          raise TypeError("scale must be a dict object.")
  
      self.scale = scale
  
      # map from original latent vars to unconstrained versions
      self.transformations = {}
      if auto_transform:
          latent_vars = self.latent_vars.copy()
          # latent_vars maps original latent vars to constrained Q's.
          # latent_vars_unconstrained maps unconstrained vars to unconstrained Q's.
          self.latent_vars = {}
          self.latent_vars_unconstrained = {}
          for z, qz in six.iteritems(latent_vars):
              if (
                  hasattr(z, "support")
                  and hasattr(qz, "support")
                  and z.support != qz.support
                  and qz.support != "point"
              ):
                  # transform z to an unconstrained space
                  z_unconstrained = transform(z)
                  self.transformations[z] = z_unconstrained
  
                  # make sure we also have a qz that covers the unconstrained space
                  if qz.support == "points":
                      qz_unconstrained = qz
                  else:
                      qz_unconstrained = transform(qz)
                  self.latent_vars_unconstrained[
                      z_unconstrained
                  ] = qz_unconstrained
  
                  # additionally construct the transformation of qz
                  # back into the original constrained space
                  if z_unconstrained != z:
                      qz_constrained = transform(
                          qz_unconstrained,
                          bijectors.Invert(z_unconstrained.bijector),
                      )
  
                      try:  # attempt to pushforward the params of Empirical distributions
                          qz_constrained.params = (
                              z_unconstrained.bijector.inverse(
                                  qz_unconstrained.params
                              )
                          )
                      except:  # qz_unconstrained is not an Empirical distribution
                          pass
  
                  else:
                      qz_constrained = qz_unconstrained
  
                  self.latent_vars[z] = qz_constrained
              else:
                  self.latent_vars[z] = qz
                  self.latent_vars_unconstrained[z] = qz
          del latent_vars
  
      if logdir is not None:
          self.logging = True
          if log_timestamp:
              logdir = os.path.expanduser(logdir)
              logdir = os.path.join(
                  logdir,
                  datetime.strftime(datetime.utcnow(), "%Y%m%d_%H%M%S"),
              )
  
          self._summary_key = tf.get_default_graph().unique_name(
              "summaries"
          )
          self._set_log_variables(log_vars)
          self.train_writer = tf.summary.FileWriter(
              logdir, tf.get_default_graph()
          )
      else:
          self.logging = False
  
      self.debug = debug
      if self.debug:
          self.op_check = tf.add_check_numerics_ops()
  
      # Store reset ops which user can call. Subclasses should append
      # any ops needed to reset internal variables in inference.
      self.reset = [tf.variables_initializer([self.t])]
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import abc
  import numpy
  import six
  import tensorflow
  import os
  from datetime import datetime
  from edward.models import RandomVariable
  from edward.util import check_data, check_latent_vars, get_session, get_variables, Progbar, transform
  from tensorflow.contrib.distributions import bijectors
label_desc: Use image node_id 3 for calling the Inference obj's underlying member method code with example usage: obj.initialize(n_iter, n_print, scale, auto_transform, logdir, log_timestamp, log_vars, debug) without return types