class_docstr: Bijector which computes `Y = g(X) = exp([X 0]) / sum(exp([X 0]))`.
  
  To implement [softmax](https://en.wikipedia.org/wiki/Softmax_function) as a
  bijection, the forward transformation appends a value to the input and the
  inverse removes this coordinate. The appended coordinate represents a pivot,
  e.g., `softmax(x) = exp(x-c) / sum(exp(x-c))` where `c` is the implicit last
  coordinate.
  
  Example Use:
  
  ```python
  bijector.SoftmaxCentered().forward(tf.log([2, 3, 4]))
  # Result: [0.2, 0.3, 0.4, 0.1]
  # Extra result: 0.1
  
  bijector.SoftmaxCentered().inverse([0.2, 0.3, 0.4, 0.1])
  # Result: tf.log([2, 3, 4])
  # Extra coordinate removed.
  ```
  
  At first blush it may seem like the [Invariance of domain](
  https://en.wikipedia.org/wiki/Invariance_of_domain) theorem implies this
  implementation is not a bijection. However, the appended dimension
  makes the (forward) image non-open and the theorem does not directly apply.
class_docstr_tok: ["Bijector","which","computes","`","Y","=","g","(","X",")","=","exp","(","[","X","0","]",")","\/","sum","(","exp","(","[","X","0","]",")",")","`",".","To","implement","[","softmax","]","(","https",":","\/\/en.wikipedia.org\/wiki\/Softmax_function",")","as","a","bijection",",","the","forward","transformation","appends","a","value","to","the","input","and","the","inverse","removes","this","coordinate",".","The","appended","coordinate","represents","a","pivot",",","e.g.",",","`","softmax","(","x",")","=","exp","(","x-c",")","\/","sum","(","exp","(","x-c",")",")","`","where","`","c","`","is","the","implicit","last","coordinate",".","Example","Use",":","``","`","python","bijector.SoftmaxCentered","(",")",".forward","(","tf.log","(","[","2",",","3",",","4","]",")",")","#","Result",":","[","0.2",",","0.3",",","0.4",",","0.1","]","#","Extra","result",":","0.1","bijector.SoftmaxCentered","(",")",".inverse","(","[","0.2",",","0.3",",","0.4",",","0.1","]",")","#","Result",":","tf.log","(","[","2",",","3",",","4","]",")","#","Extra","coordinate","removed",".","``","`","At","first","blush","it","may","seem","like","the","[","Invariance","of","domain","]","(","https",":","\/\/en.wikipedia.org\/wiki\/Invariance_of_domain",")","theorem","implies","this","implementation","is","not","a","bijection",".","However",",","the","appended","dimension","makes","the","(","forward",")","image","non-open","and","the","theorem","does","not","directly","apply","."]
code: def _inverse_log_det_jacobian(self, y):
      # Let B be the forward map defined by the bijector. Consider the map
      # F : R^n -> R^n where the image of B in R^{n+1} is restricted to the first
      # n coordinates.
      #
      # Claim: det{ dF(X)/dX } = prod(Y) where Y = B(X).
      # Proof: WLOG, in vector notation:
      #     X = log(Y[:-1]) - log(Y[-1])
      #   where,
      #     Y[-1] = 1 - sum(Y[:-1]).
      #   We have:
      #     det{dF} = 1 / det{ dX/dF(X} }                                      (1)
      #             = 1 / det{ diag(1 / Y[:-1]) + 1 / Y[-1] }
      #             = 1 / det{ inv{ diag(Y[:-1]) - Y[:-1]' Y[:-1] } }
      #             = det{ diag(Y[:-1]) - Y[:-1]' Y[:-1] }
      #             = (1 + Y[:-1]' inv{diag(Y[:-1])} Y[:-1]) det{diag(Y[:-1])} (2)
      #             = Y[-1] prod(Y[:-1])
      #             = prod(Y)
      #
      # Let P be the image of R^n under F. Define the lift G, from P to R^{n+1},
      # which appends the last coordinate, Y[-1] := 1 - \sum_k Y_k. G is linear,
      # so its Jacobian is constant.
      #
      # The differential of G, DG, is eye(n) with a row of -1s appended to the
      # bottom. To compute the Jacobian sqrt{det{(DG)^T(DG)}}, one can see that
      # (DG)^T(DG) = A + eye(n), where A is the n x n matrix of 1s. This has
      # eigenvalues (n + 1, 1,...,1), so the determinant is (n + 1). Hence, the
      # Jacobian of G is sqrt{n + 1} everywhere.
      #
      # Putting it all together, the forward bijective map B can be written as
      # B(X) = G(F(X)) and has Jacobian sqrt{n + 1} * prod(F(X)).
      #
      # (1) - https://en.wikipedia.org/wiki/Sherman%E2%80%93Morrison_formula
      #       or by noting that det{ dX/dY } = 1 / det{ dY/dX } from Bijector
      #       docstring "Tip".
      # (2) - https://en.wikipedia.org/wiki/Matrix_determinant_lemma
      np1 = ps.cast(ps.shape(y)[-1], dtype=y.dtype)
      return -(
          0.5 * ps.log(np1) + tf.reduce_sum(tf.math.log(y), axis=-1)
      )
  
file_path: probability/tensorflow_probability/python/bijectors/softmax_centered.py
imports: import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import bijector
  from tensorflow_probability.python.bijectors import pad
  from tensorflow_probability.python.internal import assert_util
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import prefer_static
label_desc: Use image node_id 9 for calling the SoftmaxCentered obj's underlying member method code with example usage: obj._inverse_log_det_jacobian(y) and returns: unknown