class_docstr: An implementation of the affine coupling layer of RealNVP (Dinh et al., 2017)
  that uses the bijective transform,
  
      :math:`\mathbf{y}_{1:d} = \mathbf{x}_{1:d}`
      :math:`\mathbf{y}_{(d+1):D} = \mu + \sigma\odot\mathbf{x}_{(d+1):D}`
  
  where :math:`\mathbf{x}` are the inputs, :math:`\mathbf{y}` are the outputs,
  e.g. :math:`\mathbf{x}_{1:d}` represents the first :math:`d` elements of the
  inputs, and :math:`\mu,\sigma` are shift and translation parameters calculated
  as the output of a function inputting only :math:`\mathbf{x}_{1:d}`.
  
  That is, the first :math:`d` components remain unchanged, and the subsequent
  :math:`D-d` are shifted and translated by a function of the previous components.
  
  Together with :class:`~pyro.distributions.TransformedDistribution` this provides
  a way to create richer variational approximations.
  
  Example usage:
  
  >>> from pyro.nn import DenseNN
  >>> input_dim = 10
  >>> split_dim = 6
  >>> base_dist = dist.Normal(torch.zeros(input_dim), torch.ones(input_dim))
  >>> param_dims = [input_dim-split_dim, input_dim-split_dim]
  >>> hypernet = DenseNN(split_dim, [10*input_dim], param_dims)
  >>> transform = AffineCoupling(split_dim, hypernet)
  >>> pyro.module("my_transform", transform)  # doctest: +SKIP
  >>> flow_dist = dist.TransformedDistribution(base_dist, [transform])
  >>> flow_dist.sample()  # doctest: +SKIP
  
  The inverse of the Bijector is required when, e.g., scoring the log density of a
  sample with :class:`~pyro.distributions.TransformedDistribution`. This
  implementation caches the inverse of the Bijector when its forward operation is
  called, e.g., when sampling from
  :class:`~pyro.distributions.TransformedDistribution`. However, if the cached
  value isn't available, either because it was overwritten during sampling a new
  value or an arbitary value is being scored, it will calculate it manually.
  
  This is an operation that scales as O(1), i.e. constant in the input dimension.
  So in general, it is cheap to sample *and* score (an arbitrary value) from
  :class:`~pyro.distributions.transforms.AffineCoupling`.
  
  :param split_dim: Zero-indexed dimension :math:`d` upon which to perform input/
      output split for transformation.
  :type split_dim: int
  :param hypernet: a neural network whose forward call returns a real-valued mean
      and logit-scale as a tuple. The input should have final dimension split_dim
      and the output final dimension input_dim-split_dim for each member of the
      tuple.
  :type hypernet: callable
  :param dim: the tensor dimension on which to split. This value must be negative
      and defines the event dim as `abs(dim)`.
  :type dim: int
  :param log_scale_min_clip: The minimum value for clipping the log(scale) from
      the autoregressive NN
  :type log_scale_min_clip: float
  :param log_scale_max_clip: The maximum value for clipping the log(scale) from
      the autoregressive NN
  :type log_scale_max_clip: float
  
  References:
  
  [1] Laurent Dinh, Jascha Sohl-Dickstein, and Samy Bengio. Density estimation
  using Real NVP. ICLR 2017.
class_docstr_tok: ["An","implementation","of","the","affine","coupling","layer","of","RealNVP","(","Dinh","et","al.",",","2017",")","that","uses","the","bijective","transform",",",":","math",":","`","\\mathbf","{","y","}","_","{","1",":","d","}","=","\\mathbf","{","x","}","_","{","1",":","d","}","`",":","math",":","`","\\mathbf","{","y","}","_","{","(","d+1",")",":","D","}","=","\\mu","+","\\sigma\\odot\\mathbf","{","x","}","_","{","(","d+1",")",":","D","}","`","where",":","math",":","`","\\mathbf","{","x","}","`","are","the","inputs",",",":","math",":","`","\\mathbf","{","y","}","`","are","the","outputs",",","e.g",".",":","math",":","`","\\mathbf","{","x","}","_","{","1",":","d","}","`","represents","the","first",":","math",":","`","d","`","elements","of","the","inputs",",","and",":","math",":","`","\\mu",",","\\sigma","`","are","shift","and","translation","parameters","calculated","as","the","output","of","a","function","inputting","only",":","math",":","`","\\mathbf","{","x","}","_","{","1",":","d","}","`",".","That","is",",","the","first",":","math",":","`","d","`","components","remain","unchanged",",","and","the","subsequent",":","math",":","`","D-d","`","are","shifted","and","translated","by","a","function","of","the","previous","components",".","Together","with",":","class",":","`","~pyro.distributions.TransformedDistribution","`","this","provides","a","way","to","create","richer","variational","approximations",".","Example","usage",":",">",">",">","from","pyro.nn","import","DenseNN",">",">",">","input_dim","=","10",">",">",">","split_dim","=","6",">",">",">","base_dist","=","dist.Normal","(","torch.zeros","(","input_dim",")",",","torch.ones","(","input_dim",")",")",">",">",">","param_dims","=","[","input_dim-split_dim",",","input_dim-split_dim","]",">",">",">","hypernet","=","DenseNN","(","split_dim",",","[","10","*","input_dim","]",",","param_dims",")",">",">",">","transform","=","AffineCoupling","(","split_dim",",","hypernet",")",">",">",">","pyro.module","(","``","my_transform","''",",","transform",")","#","doctest",":","+SKIP",">",">",">","flow_dist","=","dist.TransformedDistribution","(","base_dist",",","[","transform","]",")",">",">",">","flow_dist.sample","(",")","#","doctest",":","+SKIP","The","inverse","of","the","Bijector","is","required","when",",","e.g.",",","scoring","the","log","density","of","a","sample","with",":","class",":","`","~pyro.distributions.TransformedDistribution","`",".","This","implementation","caches","the","inverse","of","the","Bijector","when","its","forward","operation","is","called",",","e.g.",",","when","sampling","from",":","class",":","`","~pyro.distributions.TransformedDistribution","`",".","However",",","if","the","cached","value","is","n't","available",",","either","because","it","was","overwritten","during","sampling","a","new","value","or","an","arbitary","value","is","being","scored",",","it","will","calculate","it","manually",".","This","is","an","operation","that","scales","as","O","(","1",")",",","i.e",".","constant","in","the","input","dimension",".","So","in","general",",","it","is","cheap","to","sample","*","and","*","score","(","an","arbitrary","value",")","from",":","class",":","`","~pyro.distributions.transforms.AffineCoupling","`",".",":","param","split_dim",":","Zero-indexed","dimension",":","math",":","`","d","`","upon","which","to","perform","input\/","output","split","for","transformation",".",":","type","split_dim",":","int",":","param","hypernet",":","a","neural","network","whose","forward","call","returns","a","real-valued","mean","and","logit-scale","as","a","tuple",".","The","input","should","have","final","dimension","split_dim","and","the","output","final","dimension","input_dim-split_dim","for","each","member","of","the","tuple",".",":","type","hypernet",":","callable",":","param","dim",":","the","tensor","dimension","on","which","to","split",".","This","value","must","be","negative","and","defines","the","event","dim","as","`","abs","(","dim",")","`",".",":","type","dim",":","int",":","param","log_scale_min_clip",":","The","minimum","value","for","clipping","the","log","(","scale",")","from","the","autoregressive","NN",":","type","log_scale_min_clip",":","float",":","param","log_scale_max_clip",":","The","maximum","value","for","clipping","the","log","(","scale",")","from","the","autoregressive","NN",":","type","log_scale_max_clip",":","float","References",":","[","1","]","Laurent","Dinh",",","Jascha","Sohl-Dickstein",",","and","Samy","Bengio",".","Density","estimation","using","Real","NVP",".","ICLR","2017","."]
docstr: Calculates the elementwise determinant of the log jacobian
docstr_tok: ["Calculates","the","elementwise","determinant","of","the","log","jacobian"]
code: def log_abs_det_jacobian(self, x, y):
      """
      Calculates the elementwise determinant of the log jacobian
      """
      x_old, y_old = self._cached_x_y
      if (
          self._cached_log_scale is not None
          and x is x_old
          and y is y_old
      ):
          log_scale = self._cached_log_scale
      else:
          x1, x2 = x.split(
              [self.split_dim, x.size(self.dim) - self.split_dim],
              dim=self.dim,
          )
          _, log_scale = self.nn(
              x1.reshape(x1.shape[: self.dim] + (-1,))
          )
          log_scale = log_scale.reshape(
              log_scale.shape[:-1] + x2.shape[self.dim :]
          )
          log_scale = clamp_preserve_gradients(
              log_scale,
              self.log_scale_min_clip,
              self.log_scale_max_clip,
          )
      return _sum_rightmost(log_scale, self.event_dim)
  
imports: import operator
  from functools import partial, reduce
  import torch
  from torch.distributions.utils import _sum_rightmost
  from pyro.nn import ConditionalDenseNN, DenseNN
  from ..None import constraints
  from ..conditional import ConditionalTransformModule
  from ..torch_transform import TransformModule
  from ..transforms.utils import clamp_preserve_gradients
  from ..util import copy_docs_from
label_desc: Use image node_id 6 for calling the AffineCoupling obj's underlying member method code with example usage: obj.log_abs_det_jacobian(x, y) and returns: _sum_rightmost