parameters: (
      raw, off_diagonal_scale=0., overall_scale=0.)
return_statement: return math_ops.matmul(cholesky_factor, cholesky_factor, transpose_a=True)
docstring: Constructs a positive definite matrix from an unconstrained input matrix.
  
    We want to keep the whole matrix on a log scale, but also allow off-diagonal
    elements to be negative, so the sign of off-diagonal elements is modeled
    separately from their magnitude (using the lower and upper triangles
    respectively). Specifically:
  
    for i < j, we have:
      output_cholesky[i, j] = raw[j, i] / (abs(raw[j, i]) + 1) *
          exp((off_diagonal_scale + overall_scale + raw[i, j]) / 2)
  
    output_cholesky[i, i] = exp((raw[i, i] + overall_scale) / 2)
  
    output = output_cholesky^T * output_cholesky
  
    where raw, off_diagonal_scale, and overall_scale are
    un-constrained real-valued variables. The resulting values are stable
    around zero due to the exponential (and the softsign keeps the function
    smooth).
  
    Args:
      raw: A [..., M, M] Tensor.
      off_diagonal_scale: A scalar or [...] shaped Tensor controlling the relative
          scale of off-diagonal values in the output matrix.
      overall_scale: A scalar or [...] shaped Tensor controlling the overall scale
          of the output matrix.
    Returns:
      The `output` matrix described above, a [..., M, M] positive definite matrix.
docstring_summary: Constructs a positive definite matrix from an unconstrained input matrix.
docstring_tokens: Constructs a positive definite matrix from an unconstrained input matrix .
function: def sign_magnitude_positive_definite(
      raw, off_diagonal_scale=0., overall_scale=0.):
    """Constructs a positive definite matrix from an unconstrained input matrix.
  
    We want to keep the whole matrix on a log scale, but also allow off-diagonal
    elements to be negative, so the sign of off-diagonal elements is modeled
    separately from their magnitude (using the lower and upper triangles
    respectively). Specifically:
  
    for i < j, we have:
      output_cholesky[i, j] = raw[j, i] / (abs(raw[j, i]) + 1) *
          exp((off_diagonal_scale + overall_scale + raw[i, j]) / 2)
  
    output_cholesky[i, i] = exp((raw[i, i] + overall_scale) / 2)
  
    output = output_cholesky^T * output_cholesky
  
    where raw, off_diagonal_scale, and overall_scale are
    un-constrained real-valued variables. The resulting values are stable
    around zero due to the exponential (and the softsign keeps the function
    smooth).
  
    Args:
      raw: A [..., M, M] Tensor.
      off_diagonal_scale: A scalar or [...] shaped Tensor controlling the relative
          scale of off-diagonal values in the output matrix.
      overall_scale: A scalar or [...] shaped Tensor controlling the overall scale
          of the output matrix.
    Returns:
      The `output` matrix described above, a [..., M, M] positive definite matrix.
  
    """
    raw = ops.convert_to_tensor(raw)
    diagonal = array_ops.matrix_diag_part(raw)
    def _right_pad_with_ones(tensor, target_rank):
      # Allow broadcasting even if overall_scale and off_diagonal_scale have batch
      # dimensions
      tensor = ops.convert_to_tensor(tensor, dtype=raw.dtype.base_dtype)
      return array_ops.reshape(tensor,
                               array_ops.concat(
                                   [
                                       array_ops.shape(tensor), array_ops.ones(
                                           [target_rank - array_ops.rank(tensor)],
                                           dtype=target_rank.dtype)
                                   ],
                                   axis=0))
    # We divide the log values by 2 to compensate for the squaring that happens
    # when transforming Cholesky factors into positive definite matrices.
    sign_magnitude = (gen_math_ops.exp(
        (raw + _right_pad_with_ones(off_diagonal_scale, array_ops.rank(raw)) +
         _right_pad_with_ones(overall_scale, array_ops.rank(raw))) / 2.) *
                      nn.softsign(array_ops.matrix_transpose(raw)))
    sign_magnitude.set_shape(raw.get_shape())
    cholesky_factor = array_ops.matrix_set_diag(
        input=array_ops.matrix_band_part(sign_magnitude, 0, -1),
        diagonal=gen_math_ops.exp((diagonal + _right_pad_with_ones(
            overall_scale, array_ops.rank(diagonal))) / 2.))
    return math_ops.matmul(cholesky_factor, cholesky_factor, transpose_a=True)
function_tokens: def sign_magnitude_positive_definite ( raw , off_diagonal_scale = 0. , overall_scale = 0. ) : raw = ops . convert_to_tensor ( raw ) diagonal = array_ops . matrix_diag_part ( raw ) def _right_pad_with_ones ( tensor , target_rank ) : # Allow broadcasting even if overall_scale and off_diagonal_scale have batch # dimensions tensor = ops . convert_to_tensor ( tensor , dtype = raw . dtype . base_dtype ) return array_ops . reshape ( tensor , array_ops . concat ( [ array_ops . shape ( tensor ) , array_ops . ones ( [ target_rank - array_ops . rank ( tensor ) ] , dtype = target_rank . dtype ) ] , axis = 0 ) ) # We divide the log values by 2 to compensate for the squaring that happens # when transforming Cholesky factors into positive definite matrices. sign_magnitude = ( gen_math_ops . exp ( ( raw + _right_pad_with_ones ( off_diagonal_scale , array_ops . rank ( raw ) ) + _right_pad_with_ones ( overall_scale , array_ops . rank ( raw ) ) ) / 2. ) * nn . softsign ( array_ops . matrix_transpose ( raw ) ) ) sign_magnitude . set_shape ( raw . get_shape ( ) ) cholesky_factor = array_ops . matrix_set_diag ( input = array_ops . matrix_band_part ( sign_magnitude , 0 , - 1 ) , diagonal = gen_math_ops . exp ( ( diagonal + _right_pad_with_ones ( overall_scale , array_ops . rank ( diagonal ) ) ) / 2. ) ) return math_ops . matmul ( cholesky_factor , cholesky_factor , transpose_a = True )